window.onload=changes();
window.onload=agecalma();
window.onload=agecalfe();
window.onload=empchange1;
function textCounter(field,cntfield,maxlimit) {
if (field.value.length < maxlimit) 
field.value = field.value.substring(0, maxlimit);

else
cntfield.value = maxlimit + field.value.length;
}

function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
return !numcheck.test(keychar);
}

function noText(e)
{
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
return numcheck.test(keychar);
}
// FOR EMAIL VALIDATION----------------------------------------------------------------------->

function empchange()
{
var unemploy=document.getElementById('unemploy');
var income=document.getElementById('income');
var annualincome=document.getElementById('annualincome');
income.style.display='none';
annualincome.value=0;
}

function empchange1()
{
var employ=document.getElementById('employ');
var income=document.getElementById('income');
income.style.display='block';
}


function IsEmail(email,Label)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  var x = email;
  	if(x!="")	
	{			
		var testresults;
		var varEmail=email;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;														
		if (filter.test(varEmail))
		{		
			testresults=true;
					
		}
		else
		{
			alert("Please enter a valid e-mail ID");
			return false;
		}
		
		
			var testresults;
			var varEmail = ""
			varEmail=email;
			var tmp = varEmail;
			var i,j,t1,vale;
			//alert (varEmail.length);
			i = varEmail.indexOf('@');
			j = tmp.indexOf('.',i);
			tn = j - i;
			
	}
	else
	{
		alert("Please enter your "+Label+" ID");
		return false;
	}
  	return true;
}

function trim(Val)
{
	while(''+Val.charAt(0)==' ')
	Val=Val.substring(1,Val.length);
	return Val
}

// FOR GENERAL VALIDATION---------------------------------------------------------------------->
function IsValid(Val,Label)
{
	if(trim(Val)=="")
	{
		alert("Please enter your "+Label)
		return false
	}
	return true
}

// FOR PHONE NUMBER VALIDATION------------------------------------------------------------------>
function IsPhone(sText,Label)
{
   var ValidChars = "0123456789-_/+()orOR ";
   var IsNumber=true;
   var Char;
   if(sText=="") {alert("Please enter your "+Label);return false}
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if(ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   if(!IsNumber)
   	alert(Label+ "must be of numeric value")
   return IsNumber;
}

function isValidFrm()
{
		

		if(!IsValid(document.entryFrm.name.value,"name "))
		{
			document.entryFrm.name.focus();
			return false;
		}
		
		if(!IsEmail(document.entryFrm.emailID.value,"E-Mail "))
		{
			document.entryFrm.emailID.focus();
			return false;
		}

	   if(!IsPhone(document.entryFrm.phoneNo.value,"Phone number "))
		{
			document.entryFrm.phoneNo.focus();
			return false;
		}
		
	

		if(!IsValid(document.entryFrm.desIn.value,"the reason why you're elite "))
		{
			document.entryFrm.desIn.focus();
			return false;
		}		
	document.entryFrm.submit();	 

}

function changes(id)
{
var unmari=document.getElementById('child');
var child=document.getElementById('td3');
if(unmari.value=='None')
{
 child.style.display='none';
 }
else
{
 child.style.display='block';
}
}

function checkLen(x,y)
{
if (y.length==x.maxLength)
  {
  var next=x.tabIndex;
  if (next<document.getElementById("myForm").length)
    {
    document.getElementById("myForm").elements[next].focus();
    }
  }
}

function formValidator1(){	
	
	
	var educationlevel = document.getElementById('educationlevel');
	var eduin = document.getElementById('eduin');
	var height = document.getElementById('height');
	var bodytype = document.getElementById('bodytype');
	var weight = document.getElementById('weight');
	var religion = document.getElementById('religion');
	var mothertongue = document.getElementById('mothertongue');
	var foccupation = document.getElementById('foccupation');
	var moccupation = document.getElementById('moccupation');
	var familystatus = document.getElementById('familystatus');
	var familytype = document.getElementById('familytype');
	var familyvalues = document.getElementById('familyvalues');
	var sibblings = document.getElementById('sibblings');
	var mbrothers = document.getElementById('mbrothers');
	var brothers = document.getElementById('brothers');
	var msisters = document.getElementById('msisters');
	var sisters = document.getElementById('sisters');
	var aboutme = document.getElementById('aboutme');
	var address = document.getElementById('address');
	var pincode = document.getElementById('pincode');
	var landmark = document.getElementById('landmark');
	var confirm_policy = document.getElementById('confirm_policy');
	

	// Check each input in the order that it appears in the form!
	
	if(notEmpty(educationlevel, "Please select your education"))
	{
	if(notEmpty(eduin, "Please select your education department"))
	{
	 if(notEmpty(height, "Please select your height"))
	 {
	  if(notEmpty(bodytype, "Please select your body type"))
	  {
	   if(notEmpty(weight, "Please enter your weight"))
	   {
		if(notEmpty(religion, "Please select your religion "))
		{
		if(notEmpty(mothertongue, "Please select your mother tongue "))
		 {
		 if(notEmpty(foccupation, "Please select your father's occupation "))
		  {
		  if(notEmpty(moccupation, "Please select your mother's occupation "))
		  {
		  if(notEmpty(familystatus, "Please select your family status "))
		  {
		  if(notEmpty(familytype, "Please select your family type "))
		  {
		  if(notEmpty(familyvalues, "Please select your family values "))
		  {
		  if(notEmpty(sibblings, "Please select your number of sibblings "))
		  {
		  if(notEmpty(mbrothers, "Please select your number of married brothers "))
		  {
		  if(notEmpty(brothers, "Please select your number of unmarried brothers "))
		  {
		  if(notEmpty(msisters, "Please select your number of married sisters "))
		  {
		  if(notEmpty(sisters, "Please select your number of unmarried sisters "))
		   {
		  if(lengthRestriction(aboutme,30,1000))
		  {
		  if(notEmpty(address, "Please enter your communication address "))
		  {
		  if(notEmpty(pincode, "Please enter your pincode "))
		  {
		  if(notEmpty(landmark, "Please enter nearest landmark of your address "))
		  {
	if(checkBoxVal(confirm_policy, "you must agree with our terms and conditions"))
	{
		return true;

	}
					}}}}}}}}}
					}
					}
					}
				  }
				}
				}
			   } 
			   }
			   }
			   }
			
		}
	}
	
	
	return false;
	
}
function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('name');
	var email = document.getElementById('email');
	var mobile = document.getElementById('mobile');
	var password1 = document.getElementById('password1');
	var password2 = document.getElementById('password2');
	var day = document.getElementById('day');
	var month = document.getElementById('month');
	var year = document.getElementById('year');
	var countryofresidence = document.getElementById('country');
	var state1 = document.getElementById('state');
	var city = document.getElementById('city');
	var educationlevel = document.getElementById('educationlevel');
	var eduin = document.getElementById('eduin');
	var height = document.getElementById('height');
	var bodytype = document.getElementById('bodytype');
	var weight = document.getElementById('weight');
	var religion = document.getElementById('religion');
	var mothertongue = document.getElementById('mothertongue');
	var foccupation = document.getElementById('foccupation');
	var moccupation = document.getElementById('moccupation');
	var familystatus = document.getElementById('familystatus');
	var familytype = document.getElementById('familytype');
	var familyvalues = document.getElementById('familyvalues');
	var sibblings = document.getElementById('sibblings');
	var mbrothers = document.getElementById('mbrothers');
	var brothers = document.getElementById('brothers');
	var msisters = document.getElementById('msisters');
	var sisters = document.getElementById('sisters');
	var aboutme = document.getElementById('aboutme');	
	var address = document.getElementById('address');
	var pincode = document.getElementById('pincode');
	var landmark = document.getElementById('landmark');
	var confirm_policy = document.getElementById('confirm_policy');
	

	// Check each input in the order that it appears in the form!
	if(	notEmpty(firstname, "Please enter your full name"))
	{
	 if(isNumeric(day, "Please select your birth date"))
	  {
	   if(isNumeric(month, "Please select your birth month"))
	    {
		 if(isNumeric(year, "Please select your birth year"))
		  {
		   if(emailValidator(email, "Please enter a valid email address"))
		    {		
			 if(isNumeric1(mobile, "Please enter your mobile number"))
			  {	
			if(checkmobileno1())
			  {
    		  if(passwordcheck(password1,password2,"Password Mismatch"))
			   {
			   if(notEmpty(countryofresidence, "Please select your country of residence"))
				{
				 if(notEmpty(state1, "Please select your state of residence"))
				 {	
				 if(notEmpty(city, "Please enter your city "))
				  {
			       if(notEmpty(educationlevel, "Please select your education"))
				   {
				    if(notEmpty(eduin, "Please select your education department"))
				    {
					 if(notEmpty(height, "Please select your height"))
				     {
					  if(notEmpty(bodytype, "Please select your body type"))
				      {
					   if(notEmpty(weight, "Please enter your weight"))
				       {
				      if(notEmpty(religion, "Please select your religion "))
				  {
					  if(notEmpty(mothertongue, "Please select your mother tongue "))
				  {
					  if(notEmpty(foccupation, "Please select your father's occupation "))
				  {
					  if(notEmpty(moccupation, "Please select your mother's occupation "))
				  {
					  if(notEmpty(familystatus, "Please select your family status "))
				  {
					  if(notEmpty(familytype, "Please select your family type "))
				  {
					  if(notEmpty(familyvalues, "Please select your family values "))
				  {
					  if(notEmpty(sibblings, "Please select your number of sibblings "))
				  {
					  if(notEmpty(mbrothers, "Please select your number of married brothers "))
				  {
					  if(notEmpty(brothers, "Please select your number of unmarried brothers "))
				  {
					  if(notEmpty(msisters, "Please select your number of married sisters "))
				  {
					  if(notEmpty(sisters, "Please select your number of unmarried sisters "))
				  {
					  if(lengthRestriction(aboutme,30,1000))
				  {
					  if(notEmpty(address, "Please enter your communication address "))
				  {
					  if(notEmpty(pincode, "Please enter your pincode "))
				  {
					  if(notEmpty(landmark, "Please enter nearest landmark of your address "))
				  {
	if(checkBoxVal(confirm_policy, "you must agree with our terms and conditions"))
	{
		return true;
	}
					}}}}}}}}}}}}}}}}}}}}
					}
					}
					}
				  }
				}
				}
			   } 
			   }
			   }
			   }
			
		}
	}
	
	
	return false;
	
}
function passwordcheck(password1,password2,mess)
{
	if((password1.value!=password2.value)|| password1.value=='')
	{
		alert(mess);
		password1.focus();
		password1.select();
		return false;
	}	
	return true;
}
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}
function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isNumeric1(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
function checkBoxVal(elem,helperMsg)
{
alert("");
if(!elem.checked)
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	else{
		return true;
	}
}
}
function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("About yourself between " +min+ " and " +max+ " characters ");
		elem.focus();
		return false;
	}
	
	}
/*function checkmobileno()
	{
		var mobile=document.getElementById('mobile');
		valuem=mobile.value;
		var val=valuem.charAt(0);
		var val1=valuem.charAt(1);
		if(val!=0 && val1!=9)
		{
			mobile.focus();
				alert('Invalid Email Id');
						
		}
		else if(val1!=9)
		{	mobile.focus();
			alert('Invalid Email Id');
		}
	}*/
	
	function checkmobileno1()
	{
		var mobile=document.getElementById('mobile');
		valuem=mobile.value;
		var val=valuem.charAt(0);
		var val1=valuem.charAt(1);
		if(val==0)
		{
			if(val1!=9)
			{
			mobile.focus();
			mobile.select();
				alert('Invalid Mobile Number');
				return false;
			}
						
		}
		else if(val!=9)
		{	mobile.focus();
			mobile.select();
			alert('Invalid Mobile Number');
			return false;
		}
		return true;
	}
	
	
function mobileNO(value)
{
var mob=document.getElementById('mobile');
if(isNaN(value))
{
mob.select();
}
}
function mobileNO1(value)
{
var mob=document.getElementById('mobile');
if(isNaN(value))
{
alert("Invalid Mobile no");
mob.select();
}

}



/**** Age calculation***/
function agecalma()
{
var male=document.getElementById('male');
var age=21;
/**year calculation**/
var date=new Date();
yearcal(male,(date.getFullYear()-age));
//alert((date.getFullYear()-age));
}

function agecalfe()
{
var female=document.getElementById('female');
var age=18;
/**year calculation**/
var date=new Date();
yearcal(female,(date.getFullYear()-age));
//alert((date.getFullYear()-age));
}

function yearcal(id,yearcal)
{
var optyear=document.getElementById('year');
for(i=50;i>=1;i--)
{
optyear.options[i]=new Option(text=(yearcal-i+1),value=(yearcal-i+1));
}
}