/*RETYPE PASSWORD*/
	//commented by jp 
	function retypepassword1(tofocus)
	{
		var data = tofocus.value;
		if(data != ""  || data == "")
		{
	   		var repass    = data;
			var repasspat  = /^([a-z1-9\W]+){4,15}$/i; 
		
			if(repasspat.test(repass) == false)
			{
				alert("Please Enter valid retypePassword");
				document.getElementById('password').focus();
				return false;
			}
			else if(data != document.getElementById('password').value )
			{
				alert("Password and retype password must be the same");
				document.getElementById('password').value=""
				document.getElementById('retypepassword').value=""
				document.getElementById('password').focus();
				
				return false;	   	    
			}
		}		
	}


/*PASSWORD*/
	function password1(tofocus)
	{
		var data = tofocus.value;
		if(data != ""  || data == "")
		{
			var pass    = data;
			var passpat  = /^([a-z1-9\W]+){6,15}$/i; 
		
			if(passpat.test(pass) == false)
			{
				alert("Please enter the valid password (6-20 characters) \n Blank space is not allowed");
				document.getElementById('password').value=""
				focusMethod(tofocus)
				return false;
			}
			else if(data == document.getElementById('username').value || data == document.getElementById('firstname').value)
			{
				alert("Please DONT Enter User Name and First Name as Password");
				document.getElementById('password').value=""
				focusMethod(tofocus)
				return false;   
			}			    	
		}		
	}

/*User Name*/
	function username1(tofocus)
	{
		//check_user_exist(); // this functioncall user name availability
		//alert("from validations.js");
		var data = tofocus.value;
		
		if(data == "")
		{
			document.getElementById('result0').innerHTML = "";
			document.getElementById('result1').innerHTML = "";
			document.getElementById('password').value = "";
			document.getElementById('retypepassword').value = "";						
			window.alert("User Name should not be empty");
			focusMethod(tofocus)
			return false;			
		}
		else
		{
			var dataarr = data.split("");
		
			if(dataarr[0]=='F'   ) //&& isInteger(dataarr[5]) == 'true'
			{
				var digiits = dataarr[4]+dataarr[5]+dataarr[6]+dataarr[7]+dataarr[8];
				
				var digitpat = /^[0-9]+$/i;
				
				var elegibe = 99;
				if(digitpat.test(digiits) == true)
				{
					elegibe = 1;
					alert("User ID Not Avilable");
			document.getElementById('password').value = "";
			document.getElementById('retypepassword').value = "";								
					focusMethod(tofocus)
					return false;
				}
			}
		}
		
		


		if(data != "" && elegibe != 1)
		{
		    var mani = data;
		    //alert (mani);
            
		    var objRegExp  = /^[a-z]+[\.\-\_]?[a-z0-9]*$/i;
		                
		    if(objRegExp.test(mani) == true)
		    {               
		        var lenngth = mani.length;

		        if( lenngth <6 || lenngth >20 )             
		        {
			document.getElementById('result2').innerHTML = "";
			document.getElementById('result0').innerHTML = "";
			document.getElementById('result1').innerHTML = "";
			document.getElementById('password').value = "";
			document.getElementById('retypepassword').value = "";						
		            window.alert("Please enter the valid user ID (6-20 characters)");
			    focusMethod(tofocus)
			    return false;
			    
		        }
			else
			{
				//alert(mani)	;
			    doWork(mani)
			}
		    }
		    
		    if(objRegExp.test(mani) == false)
		    {
		        window.alert("Please enter the valid user ID (6-20 characters) ");
			document.getElementById('password').value = "";
			document.getElementById('retypepassword').value = "";						
		        focusMethod(tofocus)
		        return false;
                    }           
                }		
	}




/*FAX*/
	function fax1(tofocus)
	{
	    var data = tofocus.value;

	    if(data != ""  && data != "91")
	    {
   	        var fax    = data;
		var faxpat  = /^[0-9]{12}$/i;
	    
		if(faxpat.test(fax) == false)
		{
		    alert("Please enter the valid fax number with STD code \n Only 12 digits are allowed \n Special character or space is not allowed ");
		    focusMethod(tofocus)
		    return false;
		}
            }		
	}
/*NOT mandatory EMAIL*/
	function notemail1(tofocus)
	{
	    
    	    var phoneee    = document.getElementById('phone').value;
	    var mobilee    = document.getElementById('mobile').value;
	    
	    //alert (phoneee+"**"+mobilee)

	    if(phoneee.length == 12 || mobilee.length == 12)
	    {
		
		var data = tofocus.value;
		if(data != "" )
		{
		    var email    = data;
		    //var emailpat  =  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
		    var emailpat  = /^\w+([\.-]?\w+)*@[a-z0-9]+[\.\-a-z0-9]*\.[a-z]+(\.[a-z]+)*$/i;
		    if(emailpat.test(email) == false)
		    {
		        alert("Please Enter Valid Email Id");
		        focusMethod(tofocus)
		        return false;
		    }
		}
	    }
	  /*else
	    {
		alert ("Please Enter Either Mobile Number or Phone Number");
		document.getElementById('phone').focus();
		return false;
	    }	   */ 
	    
	}

/*Email*/
	function email1(tofocus)
	{
    	
          var phoneee    = document.getElementById('phone').value;
	    var mobilee    = document.getElementById('mobile').value;		
	    //alert (phoneee+"**"+mobilee)

	    
	    if(phoneee.length == 12 || mobilee.length == 12)
	    {
		var data = tofocus.value;
		if(data != "" )
		{
		    var email    = data;
		    //var emailpat  =  /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
		    var emailpat  =  /^[a-z0-9]+([\.\-\_]?[a-z0-9]*)*@[a-z0-9]+[\_\-a-z0-9]*\.[a-z]+(\.[a-z]+)?$/i;
		    if(emailpat.test(email) == false)
		    {
		        alert("Please enter the valid email ID \n   (Eg. username@website.com)");
		        focusMethod(tofocus)
		        return false;
		    }
		}
		if(data == "")
		{
		    alert("Email ID should not be empty ");
		    focusMethod(tofocus)
		    return false;   		
		}
	    }
	    /*else
	    {
		alert("Please Enter Either Mobile Number or Phone Number");
		document.getElementById('phone').focus();
		return false;
	    }*/
	    
	}

/*function atleastOnePhone(element){

    	var phoneee    = document.getElementById('phone').value;
	    var mobilee    = document.getElementById('mobile').value;

if(phoneee == "91" && mobilee == "91" ){

alert ("Please Enter Either Mobile Number or Phone Number");
document.getElementById('phone').focus();
return false;
}

	    if(phoneee.length != 12 && mobilee.length != 12)
	    {
		alert ("Please enter the valid email ID (Eg. username@website.com)");
		document.getElementById('phone').focus();
		return false;
	    }
	    
}
*/

/*mobile*/
	function mobile1(tofocus)
	{
	    var data = tofocus.value;
	    if(data!= ""  && data != "91")
	    {
	        var mobile    = data;
	        var mobilepat = /^91\d*$/i;
		if(mobile.length != 12)
	        {
			alert("Exactly 12 digits only allowed for mobile");
			focusMethod(tofocus)
			return false;					
		}	    
	        if(mobilepat.test(mobile) == false)
	        {
	            alert("Please enter the valid mobile number ");
		    focusMethod(tofocus)		    
		    return false;
	        }
	    }
        }

/*phone*/
	function phone1(tofocus)
	{
	
	    var data = tofocus.value;
	    
	    if(data != "91"  && data != "")
	    {
	        var phone    = data;
	        var phonepat  = /^91\d*$/i;
		
		if(phone.length != 12)
	        {
			alert("Exactly 12 digits only allowed for phone");
			//focusMethod(tofocus)
		document.getElementById('phone').focus();
			return false;					
		}
	    
	        if(phonepat.test(phone) == false)
	        {
		    alert("Please enter the valid phone number with STD code ");
		    document.getElementById('phone').focus();
        return false;
		      }
            }		
	}


/*Pincode*/
	function pincode1(tofocus)
	{
	    var data = tofocus.value;
	    if(data != "")
            {
		var pin    = data;
		var pinpat  = /^[1-9][0-9]+$/i;    
		if(pinpat.test(pin) == false)
		{
		    alert("Please enter the valid pincode (Eg. 614601)");
		    focusMethod(tofocus)
	       	    return false;
		}
            }
	    if(data.length != 6)
	    {
		alert("Exactly 6 digits only allowed for pincode");
		focusMethod(tofocus)
		return false;					
	    }	    
	    if(data == "")
	    {
                alert("Pincode should not be empty");
                focusMethod(tofocus)
		return false;   		
	    }
	}

	
	
/*STATE*/
	function state1(tofocus)
	{
	   var data = tofocus.value;
	   //alert(data);
           if(data=="")
	   {
		alert("Please Select your State");
		focusMethod(tofocus)
		return false;
	   }		
	}
	
/*OTHESR CITY*/
	function otherscity1(tofocus)
	{
		//alert("hi1");
		var data = tofocus.value;
		if(data == "")
		{
			//alert("hi2");
			alert("Please Enter your City Name");
			focusMethod(tofocus)
			return false;
		}
		if(data != "")
		{
			var not_specialpat = /[\!\@\#\$\%\&\*\(\)\_\-]+/g;
			if(data.match(not_specialpat))
			{
			   alert("Special character other than dot(.) is not allowed");
			   focusMethod(tofocus)
			   return false;
			}
			
			var specialpat = /\.{2,}|\s{2,}/g;
			if(data.match(specialpat))
			{
			   alert("Repetative special characters / blank spaces are not allowed");
			   focusMethod(tofocus)
			   return false;
			}			
			othercitypat = /^[a-z]+[\s\.a-z]*$/i;
			if(othercitypat.test(data) == false)
			{
				alert("Please enter valid city name (3-40 Characters Only)");
				focusMethod(tofocus)
				return false;				
			}
			
			if(data.length<3 || data.length > 40)
			{
				alert("Please Enter Valid City Name (3-40 Characters Only)");
				focusMethod(tofocus)
				return false;					
			}
		}		
	}
	
/*Location*/
	function location1(tofocus)
	{
	    var data = tofocus.value;
	    if(data != "" )
	    {
		var location    = data;
		var specialpat = /\.{2,}|\s{2,}|\-{2,}|\_{2,}|\,{2,}/g;
		if(location.match(specialpat))
		{
		   alert("Repetative special characters / blank spaces are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }
		
		//var locationpat  = /^[a-z]+(\s?\.?\-?\_?\,?\s?[a-z0-9]+)*(\s)?\.?(\s)*$/i;
		var locationpat  = /^[a-z0-9]+[\s\.\-\_\,\sa-z0-9]*$/i;
	    
		if(locationpat.test(location) == false)
		{
		    alert("Please enter the valid location (3-40 characters) ");
		    focusMethod(tofocus)
                    return false;
		}
                if(location.length<3 || location.length >40)
                {
		    alert("Please enter the valid location (3-40 characters) ");
                    focusMethod(tofocus)
		    return false;				
	        }		
    	    }
            if(data == "")
            {
                alert("Location should not be empty");
                focusMethod(tofocus)
		return false;                
            }	    
	}

/*Residental Address*/
	function raddress1(tofocus)
	{
	    var data = tofocus.value;
            if(data!= "" )
            {
                var raddreee = data;
		var specialpat = /\_{2,}|\-{2,}|\.{2,}|\#{2,}|\,{2,}|\/{2,}|\\{2,}|\&{2,}|\!{2,}|\@{2,}|\${2,}|%{2,}|\({2,}|\){2,}?/g;
		if(raddreee.match(specialpat))
		{
		   alert("Repetative special characters are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }
		
                var raddpat =/^([\#a-z0-9\s]+[\_\-\.\#\,\/\\\s\&\!\@\%\(\)]*)+$/i;
	
                if(raddpat.test(raddreee)==false)
                {
                    alert("Please enter valid residence address (6-150 characters)");
                    focusMethod(tofocus)
                    return false;
                }
                if(raddreee.length<6 || raddreee.length >150)
                {
                    alert("Please enter valid residence address (6-150 characters)");
		    //focusMethod(tofocus)
                    focusMethod(tofocus)
		    return false;				
	        }
            }
            
	    if(data == "")
            {
                alert("Residence address should not be empty");
                focusMethod(tofocus)
		return false;                
            }
	}







/*Office address*/

        function oaddress1(tofocus)
	{
            var data = tofocus.value;
            if(data != "" )
            {
        	var addreee = data;
		var specialpat = /\_{2,}|\-{2,}|\.{2,}|\#{2,}|\,{2,}|\/{2,}|\\{2,}|\&{2,}|\!{2,}|\@{2,}|\${2,}|%{2,}|\({2,}|\){2,}?/g;
		if(addreee.match(specialpat))
		{
		   alert("Repetative special characters are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }
		
		//var oaddpat = /^([a-z0-9\s]+\_?\-?\.?\#?\,?\/?\\?\s?\&?\!?\@?\$?%?\(?\)?)+$/i;
		var oaddpat = /^([\#a-z0-9\s]+[\_\-\.\#\,\/\\\s\&\!\@\%\(\)]*)+$/i;
	
        	if(oaddpat.test(addreee)==false)
        	{
           	    alert("Please enter the valid office address (6-150 characters) ");
                    focusMethod(tofocus)
                    return false;
                }
                if(addreee.length<6 || addreee.length >150)
                {
            	    alert("Please enter the valid office address (6-150 characters)");
		    focusMethod(tofocus)
		    return false;				
	        }
	    }
            
	    if(data == "" )
            {
                alert("Office address should not be empty");
                focusMethod(tofocus)
		return false;
            }
	}


/*Permanent address*/

        function peraddress1(tofocus)
	{
            var data = tofocus.value;
            if(data != "" )
            {
        	var addreee = data;
		var specialpat = /\_{2,}|\-{2,}|\.{2,}|\#{2,}|\,{2,}|\/{2,}|\\{2,}|\&{2,}|\!{2,}|\@{2,}|\${2,}|%{2,}|\({2,}|\){2,}?/g;
		if(addreee.match(specialpat))
		{
		   alert("Repetative special characters are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }
		
        	var oaddpat = /^([\#a-z0-9\s]+[\_\-\.\#\,\/\\\s\&\!\@\%\(\)]*)+$/i;
	
        	if(oaddpat.test(addreee)==false)
        	{
           	    alert("Please enter valid permanent address (6-150 characters)");
                    focusMethod(tofocus)
                    return false;
                }
                if(addreee.length<6 || addreee.length >150)
                {
            	    alert("Please enter valid permanent address (6-150 characters)");
		    focusMethod(tofocus)
		    return false;				
	        }
	    }
            if(data == "" )
            {
                alert("Permanent address should not be empty");
                focusMethod(tofocus)
		return false;
            }
	}

/*Communication Address*/
        function comaddress1(tofocus)
	{
            var data = tofocus.value;
            if(data != "" )
            {
        	var addreee = data;
		var specialpat = /\_{2,}|\-{2,}|\.{2,}|\#{2,}|\,{2,}|\/{2,}|\\{2,}|\&{2,}|\!{2,}|\@{2,}|\${2,}|%{2,}|\({2,}|\){2,}?/g;
		if(addreee.match(specialpat))
		{
		   alert("Repetative special characters are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }
		
        	//var oaddpat = /^[a-z0-9\_\-\.\#\,\/]+[a-z0-9\_\-\.\s\#\,\/]+$/i;
		var oaddpat =/^([\#a-z0-9\s]+[\_\-\.\#\,\/\\\s\&\!\@\%\(\)]*)+$/i;
	
        	if(oaddpat.test(addreee)==false)
        	{
           	    alert("Please enter valid communication address (6-150 characters) ");
                    focusMethod(tofocus)
                    return false;
                }
                if(addreee.length<6 || addreee.length >150)
                {
            	    alert("Please enter valid communication address (6-150 characters) ");
		    focusMethod(tofocus)
		    return false;				
	        }
	    }
            if(data == "" )
            {
                alert("Communication address should not be empty");
                focusMethod(tofocus)
		return false;
            }
	}

/*Lastname*/
	function lastname1(tofocus)
	{
            var data = tofocus.value;
            if(data != "" )
            {
                var lstname    = data;
                
		var specialpat = /\.{2,}|\s{2,}/g;
		if(lstname.match(specialpat))
		{
		   alert("Repetative special characters / blank spaces are not allowed");
		   focusMethod(tofocus)
		   return false;
	        }		
		//var lstnamepat  = /^[a-z]+(\s?[a-z\.])*$/i;
		var lstnamepat  = /^[a-z]+[\sa-z\.]*$/i;
			   
                if(lstnamepat.test(lstname) == false)
		{
		    	alert("Please enter the valid last name (1-20 alphabetical characters)");
			//document.form.lastname.focus();
                        focusMethod(tofocus)
                        return false;
    		}
		
                if(lstname.length<1 || lstname.length >20)
	        {
                    alert("Please enter the valid last name (1-20 alphabetical characters)");
                    //document.form.lastname.focus();
                    focusMethod(tofocus)
                    return false;				
                }	
            
            }
            if(data == "")
            {
                alert("Last name should not be empty");
                focusMethod(tofocus)
		return false;
            }
	}

/*FIRSTNAME*/
	function firstname1(tofocus)
	{
                var data = tofocus.value; 
		if(data != "" )
		{
		    var fstname    = data;
		    
		    var specialpat = /\.{2,}|\s{2,}/g;
		    if(data.match(specialpat))
		    {
			alert("Repetative special characters / blank spaces are not allowed");
			focusMethod(tofocus)
			return false;
		    }
		    
		    //var fstnamepat  = /^[a-z]+([\s\.]?[a-z]+)*$/i;
		    var fstnamepat  = /^[a-z]+([\s\.]*[a-z]+)*$/i;				   
		    if(fstnamepat.test(fstname) == false)
			{
				alert("Please Enter the Valid First Name (3-20 Alphabetical Characters) "); 
				focusMethod(tofocus)
				return false;				
			}
			
		    if(fstname.length<3 || fstname.length >20)
		    {
			alert("Please Enter the Valid First Name (3-20 Alphabetical Characters)");
			focusMethod(tofocus)
			return false;				
		    }
	    
		}
                if(data == "")
                {
                    alert("First Name Should not be Empty");
                    focusMethod(tofocus)
		    return false;
                }
		
	}

/*	
	function firstname2(tofocus)
	{
		var data = tofocus.value; 
		if(data == "")
                {
                    alert("First name should not be empty");
                    focusMethod(tofocus)
				    return false;
                }
	} */




/*focusMethod*/
   		function focusMethod(element)
   		{			
   			aField = element;
   			setTimeout("aField.focus()", 50);					
 		}


    function setCaretPosition(elemId, caretPos)
    {
	var elem = document.getElementById(elemId);

	if(elem != null)
	{
	    if(elem.createTextRange)
	    {
		var range = elem.createTextRange();
	    }
	}
    }
    
    //For the cursor selection position
    function insertAtCursor(myField, myValue)
    {
    // IE support
	if (document.selection)
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
    // Mozilla/Netscape support
	else if (myField.selectionStart || myField.selectionStart == '0')
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue + myField.value.substring(endPos, myField.value.length);
        }
	else
	{
		myField.value += myValue;
        }
}		



function otherscitynew(tofocus)
	{
		//alert("hi1");
		var data = tofocus.value;
		if(data == "")
		{
			//alert("hi2");
			alert("Please Enter your City Name");
			focusMethod(tofocus)
			return false;
		}
		if(data != "")
		{
			var not_specialpat = /[\!\@\#\$\%\.\&\*\(\)\_\-]+/g;
			if(data.match(not_specialpat))
			{
			   alert("Special character are not allowed");
			   focusMethod(tofocus)
			   return false;
			}
			
			var specialpat = /\.{2,}|\s{2,}/g;
			if(data.match(specialpat))
			{
			   alert("Repetative special characters / blank spaces are not allowed");
			   focusMethod(tofocus)
			   return false;
			}			
			othercitypat = /^[a-z]+[\s\.a-z]*$/i;
			if(othercitypat.test(data) == false)
			{
				alert("Please enter valid city name (3-40 Characters Only)");
				focusMethod(tofocus)
				return false;				
			}
			
			if(data.length<3 || data.length > 40)
			{
				alert("Please Enter Valid City Name (3-40 Characters Only)");
				focusMethod(tofocus)
				return false;					
			}
		}		
	}
	
	