// CONTAINS COMMONLY USED FUNCTIONS // Function to check the maximum and 0 number of characters for any field... // (Kapil - 20/11) f
var currentObjectName='';
var vcurrentObjectName='';
function fnCheckLength(strMsg,strVal,inMin,inMax,errlabel) 
{ 
if (currentObjectName!='' && currentObjectName!=strVal.name) 
{
    return;
}

currentObjectName=strVal.name;

stItemValue = strVal.value; 
inItemLength = stItemValue.length; 
// Validate the control's minimum value. 
if (inMin !== 0) { if (inItemLength < inMin) 
{ //alert("Invalid length for " + strMsg + "! Please retry.");
 document.getElementById(errlabel).innerText='Please enter ' + strMsg ;
strVal.focus(); 
//strVal.select();
//document.all[strVal].focus();
return(false); 
} 
document.getElementById(errlabel).innerText='';
currentObjectName='';
return(true);
} 

if (inItemLength > inMax) // Validate the control's maximum value. 
{
 alert(strMsg + " cannot be more than " + inMax + " characters!. Please retry."); strVal.focus(); 
//strVal.focus(); 
return(false); 
} 

return(true); 
} 


// Function to check that number is not negative // (Kapil - 31/01/2001) 
function fnCheckNeg(strMsg,strVal) 
{ 
stItemValue = strVal.value; 
if (parseInt(stItemValuem,10) < 0) 
{ 
alert(strMsg + " cannot be negative!. Please retry."); 
strVal.focus(); 
strVal.select(); 
return(false); 
} 
return(true); 
} 

// Function to check that only numbers are entered // (Kapil - 20/11) 
function fnCheckNumeric(strMsg,strVal,inCheckNeg)
 { 
//alert(strVal); 
stItemValue = strVal.value; 
//alert(stItemValue); 
//stItemValue="432df" 
if (isNaN(stItemValue) === true) 
{ 
	alert(strMsg + " can only have numeric data!. Please retry."); 
	strVal.focus(); 
	strVal.select(); 
	return(false); 
} 
if (inCheckNeg == 1) 
{ 
	if (!(fnCheckNeg(strMsg,strVal))) 
		{
		return (false); 
		} 
	return(true);
 } 
}
function fnValidateEmail(str,errlabel) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_email.name) 
            {
                return;
            }
        currentObjectName=document.aspnetForm.ctl00_ContentPlaceHolder1_email.name;
		if (str.indexOf(at)==-1 || str.indexOf(at)===0 || str.indexOf(at)==lstr){
		   document.getElementById(errlabel).innerText='Invalid E-mail ID';
		   document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)===0 || str.indexOf(dot)==lstr){
		   document.getElementById(errlabel).innerText='Invalid E-mail ID';
		   document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    document.getElementById(errlabel).innerText='Invalid E-mail ID';
		    document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.getElementById(errlabel).innerText='Invalid E-mail ID';
		    document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    document.getElementById(errlabel).innerText='Invalid E-mail ID';
		    document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    document.getElementById(errlabel).innerText='Invalid E-mail ID';
		    document.aspnetForm.ctl00_ContentPlaceHolder1_email.focus();
		    return false;
}
currentObjectName='';
return true;
}
function validateUsername(fld,errlabel) {
    if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_Username.name) 
            {
                return;
            }
            currentObjectName=document.aspnetForm.ctl00_ContentPlaceHolder1_Username.name;
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if ((fld.value.length < 4) || (fld.value.length > 20)) {
        fld.style.background = 'Yellow'; 
        ctl00_ContentPlaceHolder1_Username.focus();
        document.getElementById(errlabel).innerText='The username is the wrong length.';
        
        return false;
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        
        document.getElementById(errlabel).innerText='The username contains illegal characters';
        
        return false;
    } else {
        fld.style.background = 'White';
        currentObjectName="";
        return true;
    } 
    
}

function validatePassword(fld,errlabel) {
    if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_Password.name) 
            {
                return;
            }
        currentObjectName=document.aspnetForm.ctl00_ContentPlaceHolder1_Password.name;
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if ((fld.value.length < 4) || (fld.value.length > 20)) {
        document.getElementById(errlabel).innerText='The password is the wrong length';
        ctl00_ContentPlaceHolder1_Password.focus();
        fld.style.background = 'Yellow';
        
        return false;
    } else if (illegalChars.test(fld.value)) {
        document.getElementById(errlabel).innerText='The password contains illegal characters';
        ctl00_ContentPlaceHolder1_Password.focus();
        fld.style.background = 'Yellow';
        
        return false;
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        document.getElementById(errlabel).innerText='The password must contain at least one numeral';
        ctl00_ContentPlaceHolder1_Password.focus();
        fld.style.background = 'Yellow';
        
        return false;
    } else {
        fld.style.background = 'White';
        currentObjectName="";
        return true;
    }
   
} 

function validatecPassword(fld,errlabel) {
    if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword.name) 
            {
                return;
            }
        currentObjectName=document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword.name;
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if ((fld.value.length < 4) || (fld.value.length > 20)) {
        document.getElementById(errlabel).innerText='The cofirm password is the wrong length';
        ctl00_ContentPlaceHolder1_conPassword.focus();
        fld.style.background = 'Yellow';
       
        return false;
    } else if (illegalChars.test(fld.value)) {
        document.getElementById(errlabel).innerText='The cofirm password contains illegal characters';
        ctl00_ContentPlaceHolder1_conPassword.focus();
        fld.style.background = 'Yellow';
        
        return false;
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        document.getElementById(errlabel).innerText='The cofirm password must contain at least one numeral';
        ctl00_ContentPlaceHolder1_conPassword.focus();
        fld.style.background = 'Yellow';
        
        return false;
    } else {
        fld.style.background = 'White';
        currentObjectName="";
        return true;
    }
   
} 
function validatePass(pass,cpass,errlabel) {
     if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword.name) 
            {
                return;
            }
        currentObjectName=document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword.name;
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (pass.value != cpass.value) {
        document.getElementById(errlabel).innerText='The password and confirm password are not same.';
        
        pass.style.background = 'Yellow';
        cpass.style.background = 'Yellow';
        ctl00_ContentPlaceHolder1_conPassword.focus();
        return false;
    } 
    else {
        pass.style.background = 'White';
        cpass.style.background = 'White';
        currentObjectName="";
        return true;
    }
   
}

function checkphone()
{
if(document.getElementById("ctl00_ContentPlaceHolder1_phoneoffice").value=="" && document.getElementById("ctl00_ContentPlaceHolder1_phoneres").value=="" && document.getElementById("ctl00_ContentPlaceHolder1_mobile").value=="") 
    { 
    document.getElementById("errphone").innerText="Please enter atleast one Phone Number! Please retry";
    //alert("Please enter atleast one Phone Number! Please retry"); 
    //document.getElementById("ctl00_ContentPlaceHolder1_phoneoffice").focus(); 
    altvalue=false; 
    //ctl00_ContentPlaceHolder1_phoneoffice.focus();
    document.getElementById("errphone").focus();
    return false;
    }
    document.getElementById("errphone").innerText='';
    return true;
}
    
    function checkcity()
    {
    if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_city.name) 
            {
                return ;
            }
    currentObjectName=ctl00_ContentPlaceHolder1_city.name;
    if(ctl00_ContentPlaceHolder1_city.selectedIndex==-1) 
    
   
    {
    document.getElementById("errcity").innerText="Please select city";
    
    //var input = ctl00_ContentPlaceHolder1_city.get_inputDomElement();
   ctl00_ContentPlaceHolder1_city.focus();
     currentObjectName="";
     altvalue=false;
     return false;
    }
    document.getElementById("errcity").innerText="";
    currentObjectName="";
    return true;
    }
    
    function checkstate()
    {
    if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_state.name) 
            {
               
                return;
            }
    currentObjectName=ctl00_ContentPlaceHolder1_state.name;
    if(ctl00_ContentPlaceHolder1_state.selectedIndex==-1) 
    
   
    {
   
     document.getElementById("errstate").innerText="Please select state";
     ctl00_ContentPlaceHolder1_state.focus();
     currentObjectName="";
     altvalue=false;
     return false;
    }
    document.getElementById("errstate").innerText='';
    currentObjectName="";
    return true;
}

function checkprof()
{
 if (currentObjectName!='' && currentObjectName!=document.aspnetForm.ctl00_ContentPlaceHolder1_Profession.name) 
            {
                return;
            }
    currentObjectName=ctl00_ContentPlaceHolder1_Profession.name;

if(ctl00_ContentPlaceHolder1_Profession.selectedIndex==-1) 
    
   
    {
    doucment.getElementById("errprof").innerText="Please select Profession";
    ctl00_ContentPlaceHolder1_Profession.focus();
    currentObjectName="";
     altvalue=false;
     return false;
    }
    document.getElementById("errprof").innerText="";
    currentObjectName="";
    return true;
  }    
    
  



function fnRegValidate()
 { 
	
    


	document.getElementById("errfn").innerText='';
    document.getElementById("errln").innerText='';
    document.getElementById("erremail").innerText='';

	
    document.getElementById("erradd").innerText='';
    document.getElementById("erradd").innerText='';
    document.getElementById("errcountry").innerText='';
    document.getElementById("errphone").innerText='';
    document.getElementById("errcity").innerText='';
    document.getElementById("errstate").innerText='';
    document.getElementById("errcity").innerText='';
    document.getElementById("errprof").innerText='';
    document.getElementById("errpract").innerText='';
   // document.getElementById("errdob").innerText='';
    document.getElementById("erruser").innerText='';

    //document.getElementById("errpass").innerText='';
    //document.getElementById("errcpass").innerText='';
    document.getElementById("errcode").innerText='';

	
   


    altvalue=true;
    
    
    
 
   
    
    
    
    
    
    
    
 

     // FOR USER NAME 
     if (!(fnCheckLength("Name",document.aspnetForm.ctl00_ContentPlaceHolder1_firstname,1,40,'errfn'))) 
     {
     altvalue=false;
     return false;
     }
     // FOR LAST NAME 
     if (!(fnCheckLength("Last Name",document.aspnetForm.ctl00_ContentPlaceHolder1_lastname,1,40,'errln'))) 
     {
     altvalue=false;
     return false;
    }
     // VALID EMAIL FORMAT 
    if (!(fnCheckLength("Email",document.aspnetForm.ctl00_ContentPlaceHolder1_email,1,40,'erremail'))) 
    {
    altvalue=false;
    return false;
    }
    if (!(fnValidateEmail(document.aspnetForm.ctl00_ContentPlaceHolder1_email.value,'erremail'))) 
    {
    altvalue=false;
    return false;
    }
     if (!(fnCheckLength("address",document.aspnetForm.ctl00_ContentPlaceHolder1_regaddress,1,100,'erradd'))) 
    {
    altvalue=false;
    return false;
    }
     if(document.getElementById("ctl00_ContentPlaceHolder1_phoneoffice").value=="" && document.getElementById("ctl00_ContentPlaceHolder1_phoneres").value=="" && document.getElementById("ctl00_ContentPlaceHolder1_mobile").value=="") 
    { 
    ctl00_ContentPlaceHolder1_phoneoffice.focus();
    document.getElementById("errphone").innerText="Please enter atleast one Phone Number! Please retry";
    //alert("Please enter atleast one Phone Number! Please retry"); 
    //document.getElementById("ctl00_ContentPlaceHolder1_phoneoffice").focus(); 
    altvalue=false; 
    return false;
    }
    if (!(fnCheckLength("Country",document.aspnetForm.ctl00_ContentPlaceHolder1_country,1,40,'errcountry'))) 
     {
     altvalue=false;
     return false;
    }
    //alert(ctl00_ContentPlaceHolder1_city.selectedIndex);
    
    if(ctl00_ContentPlaceHolder1_city.selectedIndex==-1) 
    {
     document.getElementById("errcity").innerText="Please select city";
     altvalue=false;
     ctl00_ContentPlaceHolder1_city.focus();
     return false;
    }
    if(ctl00_ContentPlaceHolder1_state.selectedIndex==-1) 
    {
    document.getElementById("errstate").innerText="Please select state";
     altvalue=false;
     ctl00_ContentPlaceHolder1_state.focus();
     return false;
    }
     if(ctl00_ContentPlaceHolder1_Profession.selectedIndex==-1) 
    
   
    {
    document.getElementById("errprof").innerText="Please select Profession";
    ctl00_ContentPlaceHolder1_Profession.focus();
     altvalue=false;
     return false;
    }
      
    
   
    if (!(validateUsername(document.aspnetForm.ctl00_ContentPlaceHolder1_Username,'erruser')))
    {
     altvalue=false;
     return false;
    }
      if (!(validatePassword(document.aspnetForm.ctl00_ContentPlaceHolder1_Password,'errpass')))
    {
     altvalue=false;
     return false;
    }
    if (!(validatecPassword(document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword,'errcpass')))
    {
     altvalue=false;
     return false;
    }
    if (!(validatePass(document.aspnetForm.ctl00_ContentPlaceHolder1_Password,document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword,'errcpass')))
    {
     altvalue=false;
     return false;
    }
    
    if (!(fnCheckLength("Username",document.aspnetForm.ctl00_ContentPlaceHolder1_Username,1,10,'erruser'))) 
     {
     altvalue=false;
     return false;
    }
    
    if (!(fnCheckLength("Password",document.aspnetForm.ctl00_ContentPlaceHolder1_Password,1,10,'errpass'))) 
     {
     altvalue=false;
     return false;
    }
    
      if (!(fnCheckLength("Confirm Password",document.aspnetForm.ctl00_ContentPlaceHolder1_conPassword,1,10,'errcpass'))) 
     {
     altvalue=false;
     return false;
    }
   
   
   
    
     if (!jcap())
     {
     altvalue=false;
     return false;
     }
     
    return altvalue;
}

function dosubmit()
{
	
    altvalue=fnRegValidate();
	
    if(altvalue !== false)

        {
		
        document.aspnetForm.action="register2.aspx";
        document.aspnetForm.submit();
        }
   
}


