window.onload=changes();
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 day = document.getElementById('day');
	var month = document.getElementById('month');
	var pwd = document.getElementById('pwd');
	var year = document.getElementById('year');
	var state = document.getElementById('state');
	var countryofresidence = document.getElementById('country');
	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(passwordcheck())
			  {
			   if(notEmpty(countryofresidence, "Please select your country of residence"))
				{
				if(notEmpty(state, "Please enter your state "))
				  {
				 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 notEmpty(elem, helperMsg){
	if(elem.value == ""){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}
function passwordcheck()
{
	var elem1=document.getElementById("cpwd").value;
	var elem=document.getElementById("pwd").value;
	if(elem == "")
	{
		alert("Please Enter Password");
		return false;
	}
	else
	{
		if(elem1 == "")
		{
			alert("Please Enter Confirm Password");
			return false;
		}
		else
		{
			if(elem != "" && elem1 != "")
			{
				if(elem==elem1)return true;
				else 
				{
					alert("Password doesn't Match"); return false;
				}
			}
			return false;
		}
		return true;
	}
	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("shiva")
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;
	}
	
	}
