		
  function maskDate(obj){
		date=obj.value
		if (/[^\d/]|(\/\/)/g.test(date))  {obj.value=obj.value.replace(/[^\d/]/g,'');obj.value=obj.value.replace(/\/{2}/g,'/'); return }
		if (/^\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
		if (/^\d{2}\/\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
		if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(date)) return

		test1=(/^\d{1,2}\/?\d{1,2}\/\d{4}$/.test(date))
		date=date.split('/')
		d=new Date(date[2],date[1]-1,date[0])
		test2=(1*date[0]==d.getDate() && 1*date[1]==(d.getMonth()+1) && 1*date[2]==d.getFullYear())
		if (test1 && test2) return true
		//alert("Invalid date")
		//obj.select();
		//obj.focus()
		return false
}

//validating date 
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateForm(){
	var dt=document.Form1.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }		
// end of date validation	

var __ErrorMsg;
function ValidateRegBeforeSubmit(){
var retval=true;
__ErrorMsg ="Application Encounters an Error(s)!\nPlease read carefully the following error message(s) before submitting this form. \n";
__ErrorMsg += "-------------------------------------------------------------------------------------------------------------------\n";
//check for all required field left empty
if (IsTuringNotValid(window.document.getElementById("TuringNumber"),"yes")) retval = false;
if (IsInputReqFldEmpty()) retval=false;   
if (IsSelectReqFldEmpty()) retval=false;

if (IsTextAreaReqFldEmpty()) retval=false;

if (window.document.getElementById("ChkPrivacy").checked == false) {
	__ErrorMsg = __ErrorMsg + "Privacy Policy checkbox must be checked.\n"
	retval=false;
}

if (window.document.getElementById("ChkTerm").checked == false) {
	__ErrorMsg = __ErrorMsg + "Terms and Condition checkbox must be checked.\n"
	retval=false;
}	

//end empty check

//check format--warning! this function has a hard coded field input name = 'email'
if (IsEmailFormatInvalid()) retval=false;

//other checking
if (IsPWDMismatch()) retval=false;

if (retval==false){
	window.alert(__ErrorMsg);
}
return retval;
}

//editinfo added by Romel S. Barrera
function ValidateEditInfoBeforeSubmit(){
var retval=true;
__ErrorMsg ="Application Encounters an Error(s)!\nPlease read carefully the following error message(s) before submitting this form. \n";
__ErrorMsg += "-------------------------------------------------------------------------------------------------------------------\n";
//check for all required field left empty

if (IsInputReqFldEmpty()) retval=false;   
if (IsSelectReqFldEmpty()) retval=false;

if (IsTextAreaReqFldEmpty()) retval=false;

/*if (window.document.getElementById("ChkPrivacy").checked == false) {
	__ErrorMsg = __ErrorMsg + "Privacy Policy checkbox must be checked.\n"
	retval=false;
}

if (window.document.getElementById("ChkTerm").checked == false) {
	__ErrorMsg = __ErrorMsg + "Terms and Condition checkbox must be checked.\n"
	retval=false;
}*/	

//end empty check

//check format--warning! this function has a hard coded field input name = 'email'
if (IsEmailFormatInvalid()) retval=false;

//other checking
if (IsPWDMismatch()) retval=false;

if (retval==false){
	window.alert(__ErrorMsg);
}
return retval;
}


//

//contact us
//added by Romel S. Barrera
function ValidateContactUsBeforeSubmit(){
var retval=true;
__ErrorMsg ="Application Encounters an Error(s)!\nPlease read carefully the following error message(s) before submitting this form. \n";
__ErrorMsg += "-------------------------------------------------------------------------------------------------------------------\n";
//check for all required field left empty

if (IsInputReqFldEmpty()) retval=false;   
/*if (IsSelectReqFldEmpty()) retval=false;

if (IsTextAreaReqFldEmpty()) retval=false;

if (window.document.getElementById("ChkPrivacy").checked == false) {
	__ErrorMsg = __ErrorMsg + "Privacy Policy checkbox must be checked.\n"
	retval=false;
}

if (window.document.getElementById("ChkTerm").checked == false) {
	__ErrorMsg = __ErrorMsg + "Terms and Condition checkbox must be checked.\n"
	retval=false;
}*/	

//end empty check

//check format--warning! this function has a hard coded field input name = 'email'
if (IsEmailFormatInvalid()) retval=false;

//other checking
//if (IsPWDMismatch()) retval=false;

if (retval==false){
	window.alert(__ErrorMsg);
}
return retval;
}
//


//
//business registraion
function ValidateBRegBeforeSubmit(){
var retval=true;
__ErrorMsg ="Application Encounters an Error(s)!\nPlease read carefully the following error message(s) before submitting this form. \n";
__ErrorMsg += "-------------------------------------------------------------------------------------------------------------------\n";
//check for all required field left empty

if (IsInputReqFldEmpty()) retval=false;   
if (IsSelectReqFldEmpty()) retval=false;
if (IsTextAreaReqFldEmpty()) retval=false;
//end empty check

//check format--warning! this function has a hard coded field input name = 'email'
if (IsEmailFormatInvalid()) retval=false;

if (retval==false){
	window.alert(__ErrorMsg);
}
return retval;
}

//Login 
function ValidateLoginBeforeSubmit(){
var retval=true;
__ErrorMsg ="Application Encounters an Error(s)!\nPlease read carefully the following error message(s) before submitting this form. \n";
__ErrorMsg += "-------------------------------------------------------------------------------------------------------------------\n";
//check for all required field left empty
if (IsInputReqFldEmpty()) retval=false;   
if (retval==false){
	window.alert(__ErrorMsg);
}
return retval;
}



//Check all textboxes having an attribue of IsRequired=yes
function IsInputReqFldEmpty()
{
	var retval = false ;
	var inputs=document.getElementsByTagName("INPUT");
	
	for(i=0, x=inputs.length; i<x; i++){
		//Textbox
	if (((inputs[i].getAttribute("TYPE") == "text") || (inputs[i].getAttribute("TYPE") == "password") )&&(inputs[i].getAttribute("isrequired") == "yes")){
			if (inputs[i].value.length  == 0){
		
				__ErrorMsg = __ErrorMsg + inputs[i].getAttribute("caption") + " cannot be blank! \n"
				
				retval=true;
			}	
		}
	}
	return retval;
}

//Check all Option Tag having an attribue of IsRequired=yes
function IsSelectReqFldEmpty()
{
	var retval = false ;
	var inputs=document.getElementsByTagName("SELECT");
	for(i=0, x=inputs.length; i<x; i++){
	if (inputs[i].getAttribute("isrequired") == "yes"){
	  
			if ((inputs[i].value  == "Select Country") || (inputs[i].value  == "0" )){
				__ErrorMsg = __ErrorMsg + inputs[i].getAttribute("caption") + " cannot be blank!\n";
				retval=true;
			}	
		}	
	}
	return retval;
}


//Check all Option Tag having an attribue of IsRequired=yes
function IsTextAreaReqFldEmpty()
{
	var retval = false ;
	var inputs=document.getElementsByTagName("TEXTAREA");
	for(i=0, x=inputs.length; i<x; i++){
	if (inputs[i].getAttribute("isrequired") == "yes"){
	  
			if (inputs[i].value.length  == 0){
				__ErrorMsg = __ErrorMsg + inputs[i].getAttribute("caption") + " cannot be blank!\n";
				retval=true;
			}	
		}	
	}
	return retval;
}


//end of validation


//ValidatePassword with retype password
function IsPWDMismatch()
{
	var retval= false;
	if (window.document.getElementById("Password").value != window.document.getElementById("RetypePassword").value)	{
	__ErrorMsg += "Password entered does not match the retype password! \n";
	retval= true;
	}
	else{
	retval= false;
	}
return retval;	
}

//check email format
function IsEmailFormatInvalid()
{

	var Emailfld = window.document.getElementById("Email");
	var retval = false;
	
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(Emailfld.value)){ //	//correct format
				retval= false; 
			}	
			else{
			  __ErrorMsg += "Incorrect Email Format! \n";
			  retval= true //alert('NO! Incorrect email address');
			}  
return retval;			  
}




//mask phone number
function maskContactNo(f){
/*tel='';
var val =f.value.split('');
for(var i=0;i<val.length;i++){
if(i==0){val[i]='('+val[i]}
if(i==3){val[i]=val[i]+')'}
if(i==5){val[i]=val[i]+'-'}
tel=tel+val[i]
}
f.value=tel;*/

tel='';
window.alert(f.value)

var val =f.value.split('');
window.alert(val.length);
window.alert(val);
for(var i=0;i<val.length;i++){
if (val.length == 1)
{
   val[i]='(09'+val[i];
}
if (val.length == 5)
{
  f.value = f.value + ')';
  return true;
}

if (val.length == 11)
{
  f.value = f.value + '-';
  return true;
}
tel=tel+val[i];



/*if(i==0)
{
  val[i]='(09'+val[i];
}
if(i==3)
{
 val[i]=val[i]+')';
}
if(i==5)
{
  val[i]=val[i]+'-';
 }
tel=tel+val[i];*/
}
f.value=tel;

} 




function IsTuringNotValid(_ctrl,forceValidate)
{
var xmlHttp=null;
var retval = false;

if (_ctrl.value.length==0) return false;

//no changes found
if ((_ctrl.getAttribute("LastValue") == _ctrl.value) && (forceValidate == undefined) ) {
     return true;
}
_ctrl.setAttribute("LastValue",_ctrl.value);
	

try{// Firefox, Opera 8.0+, Safari, IE7
  xmlHttp=new XMLHttpRequest();
  }
catch(e) {// Old IE
  try{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  catch(e){
    alert ("Your browser does not support XMLHTTP!");
    return;  
    }
  }
  if (xmlHttp!=null) {
  var url="Validator.aspx?ID=" + _ctrl.value;
  window.document.getElementById("cmdSubmit").disabled=true;
  //xmlHttp.onreadystatechange=state_Change; 
  xmlHttp.open("POST",url,false);
   var xmlstr;
  xmlstr = "<request Id='validateturingnumber'><tnumber>" + _ctrl.value + "</tnumber></request>";
  xmlHttp.send(xmlstr);
  
  
  if (xmlHttp.readyState==4){
			// 4 = "loaded"
			if (xmlHttp.status==200)
			{// 200 = "OK"
		    	if (xmlHttp.responseText =="-1"){
		    		
		    	   
		    	     window.document.getElementById("cmdSubmit").disabled=false;
		    	    
		    	    if (forceValidate == undefined){
		    			_ctrl.focus();
		    			_ctrl.value = "";
		    			 window.alert("Invalid turing number!");	
		    	     }
		    	    else{
		    	    __ErrorMsg += "Turing number does not match the image content! \n";
		    	    //window.alert("Invalid turing numberx!");	
		    	    } 
		    		return true;
				   }
				else {
				}   
			}
		else{
			alert("Problem retrieving XML data:" + xmlHttp.statusText);
			}
		
		 window.document.getElementById("cmdSubmit").disabled=false;
		}
  
  
  
 

  }
else{
  alert("Your browser does not support XMLHTTP.");
  }

		/*function state_Change(){
		if (xmlHttp.readyState==4){
			// 4 = "loaded"
			if (xmlHttp.status==200)
			{// 200 = "OK"
		    	if (xmlHttp.responseText =="-1"){
		    		
		    	    _ctrl.focus();
		    	    _ctrl.value = "";
		    	     window.document.getElementById("cmdSubmit").disabled=false;
		    	     window.alert("Invalid turing number!");
		    	   /* if (forceValidate != undefined){
		    		
		    	     }
		    	    else{
		    	    __ErrorMsg += "Turing number does not match the image content! \n";
		    	    } 
		    		return true;
				   }
				else {
				}   
			}
		else{
			alert("Problem retrieving XML data:" + xmlHttp.statusText);
			}
		
		 window.document.getElementById("cmdSubmit").disabled=false;
		}
		}
		*/


}



	
