
// JScript File
/*******************
^ - start of the string
$ - start of the string
w - [a-zA-z0-9 ]--space included
W - opposite of w
d - [0-9]
**********repetation******
? - 0 to 1
* -  0 or multiple
+ - 1 or multiple
********************/


function Ltrim_string(objID)
{			
var j = 0,k=0;
if(objID.length>0)
{
	for(var i=0;i<objID.length && k<objID.length;i++)
	{
		if(objID.charAt(i)==" ")
		{
		j++;
		}
		else
		{
		k = objID.length;
		}
	}
	objID =objID.substring(j,objID.length);
}
	return objID;
}


//Blank Check
function CheckBlank(objID,strControlName)
{
   if (Ltrim_string(objID.value)=="")
   {
		alert(strControlName+": Cannot be left blank");
		objID.focus();
		return false;
	}
	return true;
}

//Blank Check without setFocus
function CheckBlank1(objID,strControlName)
{
   if (Ltrim_string(objID.value)=="")
   {
		alert(strControlName+": Cannot be left blank");
		return false;
	}
	return true;
}

//function to check alphabets without space
function CheckAlphabets(objID,strControlName)
{
	var alpha=/[a-zA-Z]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	    }
	return true;
}

//function to check alphabets with space
function CheckAlphabetsWithSpace(objID,strControlName)
{
	var alpha=/[a-zA-Z ]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	}
	return true;
}

//function to check alphabets without space, allowing '
function CheckSurname(objID,strControlName)
{
	var alpha=/[a-zA-Z']+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	    }
	return true;
}

//Validation For Single EMail-Id
function CheckMail(objID,strControlName)
{
if (objID.value!="")
		{
		
	var email =/[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9]+\.[-a-zA-Z0-9\.]+/;
	var eflag = objID.value.match(email);
	if(eflag!=objID.value)
	{
		alert(strControlName+ ": should be in proper format")
		objID.focus();
		objID.select();
		return false;
		}
		else if(objID.value.indexOf(".")==0)
		{
		alert(strControlName +": should be valid Email")
		objID.focus();
		objID.select();
		return false;
		}
	}
	return true;
} 

//Allow only Numbers in TextBox
function CheckNumeric(objID,strControlName)
	{	
		if (objID.value!="")
		{
			var num=/[0-9.]+/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value){
			alert(strControlName+ ": should be Numeric only.")
			objID.focus();
 			objID.select();
			return false;
		}
	}
	return true;
}


//Allow Numbers with () & - in TextBox of phone number
function CheckPhone(objID,strControlName)
{	
		if (objID.value!="")
		{
			//var num=/[0-9()-]+/
			var num=/\(?[0-9]{0,4}\)?[-]?[0-9]{8,9}/
			//{0,4}means digits can come for 0 times to 4 times (std code), ? means it can come 0 or 1 times
			//var num=/\(?\d{3}\)?[- ]?\d{3}/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value)
			{
			    alert(strControlName+ ": should be Numeric and in proper format with minimum length 8")
			    objID.focus();
 			    objID.select();
			    return false;
		    }
		   
	    }
	    return true;
}

/*
//Allow Numbers with () & - in TextBox of phone number
function CheckPhone(objID,strControlName)
{	
    alert("in validation");
		if (objID.value!="")
		{
			var num=/[0-9()-]+/
			//var num=/\(?\d{3}\)?[- ]?\d{3}/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value)
			{
			    alert(strControlName+ ": should be Numeric and in proper format with minimum length 8")
			    objID.focus();
 			    objID.select();
			    return false;
            }
            /*else
            {var arr[5];
                alert("in else");
                if(objID.value.contains("-"))
                {
                    arr=objID.value.split("-")
                    alert(arr[0].value);
                }//if contains -
            }
	    }*/
/*	    return true;
}
*/

//function to check alpha numeric with space
function checkAlphaNumSpace(fieldName,str)
{

if (fieldName.value!="")
    {
	var alphanum=/[a-zA-Z0-9 ]+/;
	alphaflag=fieldName.value.match(alphanum);	
        if(alphaflag != fieldName.value)
        {
                alert(str+ " should contain alphabets and/or numbers only.")
                fieldName.focus();
                fieldName.select();
                return false;
        }
	}
	return true;
}

//function to check alpha numeric with space & special charcters ' & -
function checkAlphaNumSpaceSpl(fieldName,str)
{

if (fieldName.value!="")
    {
	var alphanum=/[a-zA-Z0-9\s.'&,-]+/;
	alphaflag=fieldName.value.match(alphanum);	
        if(alphaflag != fieldName.value)
        {
                alert(str+ " should contain alphabets and/or numbers only.")
                fieldName.focus();
                fieldName.select();
                return false;
        }
	}
	return true;
}


//function to check alphanumeric without space
function CheckAlphaNumeric(objID,strControlName)
{
	var alpha=/[a-zA-Z0-9]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphanumeric only.")
			objID.focus();
 			objID.select();
			return false;
	}
	return true;
}

//Allow Numbers with dot for currency in TextBox
function checkDotNumber(fieldName,str)
{

    if (fieldName.value!="")
    {
        var dnum=/(^\d+$)|(^\d+\.\d+$)/
        if (dnum.test(fieldName.value))
            return true;
        else
        {
             alert(str+ ": should be Numeric & in proper format.");
             fieldName.focus();
             fieldName.select();
             return false;
        }
       
    }
    
    
    return true;
}

//function to check if textfield contains only zero
function CheckZero(objID,strControlName)
{
  if (objID.value!="")
    {
	  if(objID.value==0)
		  {
			  alert(strControlName+ ": cannot be zero")
			  objID.focus();
 			  objID.select();
 			  
			  return false;
	      }
	   }
	   
	return true;
}

////function to check specified length-length can be pass by passing values to the parameter

function LengthCheck(objControl,strControlName,strlength)
{
    /*alert(objControl.value);
    alert(strControlName);
    alert(strlength);*/
    if (objControl.value!="")
    {
        if(objControl.value.length<strlength)
        {
            alert(strControlName+": should have minimum length "+strlength+"");
            objControl.focus();
            objControl.select();
            return false;
        } 
    }
    return true;
} 


//Validation For Drop-Down List
function CheckDropDown(objID,strControlName)
{
	   if(objID.options[0].selected=="true" || objID.selectedIndex == 0)
	   {
		alert(strControlName+ ": Select a proper option.");
		objID.focus();
		return false;
	}
	return true;
} 


//Validation for check box if neither check box is selected.
function CheckCheckBox(frm,objID)
{
alert(objID.value);
if(document.frm.objID.checked=="true")
{
	alert("Select at List one knowledge,Information & Educational Products!");
	//document.getElementById("objID").focus();
	return false;
}
return true;
}

function readData(rendControl,reg,interval)
    {

       
 var div1= document.getElementById(rendControl); 
  if(div1==null)
  {   
    setTimeout('readData(\'' + rendControl  + '\',\''+ reg + '\',' + interval + ')',interval);
    return;
  }
    var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
 
   xmlhttp.open("GET", reg,true);
   xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
  
    
//  var div1= document.getElementById(rendControl); 
//  if(div1==null)
//  {    return;
//  }
      div1.innerHTML = xmlhttp.responseText;
     


  setTimeout('readData(\'' + rendControl  + '\',\''+ reg + '\',' + interval + ')',interval);
  }
 }
 xmlhttp.send(null) 

 }
//-------------------------------

//Validation for password and confirm password field
function ComparePassword(objID1,objID2,strControlName)
{
    if(objID1.value!=objID2.value)
    {
	    alert(strControlName+": doesn't match!");
	    objID2.focus();
	    return false;
    }
return true;
}

//Validation for listbox control
function CheckListBox(objID,strControlName)
{
    if(objID.value=="select one")
    {
        alert(strControlName+": select atleast one!");
        objID.focus();
        return false;
    }
return true;
}

//-----------------------------------------------------

function getChatUser(rendControl, reg, interval) {

    var div1 = document.getElementById(rendControl);

    if (div1 == null) {
       
        setTimeout('getChatUser(\'' + rendControl + '\',\'' + reg + '\',' + interval + ')', interval);
        return;
    }
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }

    xmlhttp.open("GET", reg, true);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
           // div1.innerHTML = xmlhttp.responseText;
           // alert(div1.innerHTML);
            eval(xmlhttp.responseText);
            setTimeout('getChatUser(\'' + rendControl + '\',\'' + reg + '\',' + interval + ')', interval);
        }
    }
    xmlhttp.send(null)

}
//-------------------------------
//Blank Check First Name
function CheckBlankFirstN(objID, strControlName) {
    if (Ltrim_string(objID.value) == "First Name") {
        alert(strControlName + ": Cannot be left blank");
        objID.focus();
        return false;
    }
    return true;
}
//Blank Check Middle Name
function CheckBlankMiddleN(objID, strControlName) {
    if (Ltrim_string(objID.value) == "Middle Name") {
        alert(strControlName + ": Cannot be left blank");
        objID.focus();
        return false;
    }
    return true;
}
//Blank Check Last Name
function CheckBlankLastN(objID, strControlName) {
    if (Ltrim_string(objID.value) == "Last Name") {
        alert(strControlName + ": Cannot be left blank");
        objID.focus();
        return false;
    }
    return true;
}



function CheckDate_ddmmyyyy(input, msg) {
    if (input.value == "")
    { return true; }

    var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Basic check for format validity
    var returnval = false;
    if (!validformat.test(input.value)) {
        alert(msg + "Invalid Date Format. Please correct(dd/mm/yyyy) and submit again.");
        input.focus();
        input.select();
        return false;
    }
    else { //Detailed check for valid date ranges
        var yearfield = input.value.split("/")[2];
        var monthfield = input.value.split("/")[1];
        var dayfield = input.value.split("/")[0];
        var dayobj = new Date(yearfield, monthfield - 1, dayfield);
        if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {
            alert(msg + "Invalid Day, Month, or Year range detected. Please correct(dd/mm/yyyy) and submit again.");
            input.focus();
            input.select();
            return false;
        }
        else {
            // alert ('Correct date');
            return true;
        }
    }
}

function CmpDate_shdlesstoday(input, msg) {
    var yearfield = input.value.split("/")[2];
    var monthfield = input.value.split("/")[1];
    var dayfield = input.value.split("/")[0];
    var dayobj1 = new Date(yearfield, monthfield - 1, dayfield);

    var date1 = new Date();
    if (dayobj1 >= date1) {
        alert(msg + " cannot be greater than Today's date");
        return false;
    }
    return true;
}

