// update by sachin chaudhari date 14 Nov2006 // changes in validation messag and currection validation in city,state,pin code,tel no,,off phone, fax
	function chkdate(md, dd, yd)
	{
		
	}

	function IsNumeric(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
			
		for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
			  Char = sText.charAt(i); 
			  if (ValidChars.indexOf(Char) != -1) 
				{
			        IsNumber = "false";
					alert ("please enter characters only.");						
				}
		  }
	   return IsNumber;   
	}//character validation

	
	
	
	
function validate()
 {
 	var dd = parseInt(document.frm.date.options[document.frm.date.selectedIndex].value);
	var md = parseInt(document.frm.month.options[document.frm.month.selectedIndex].value);
	var yd = parseInt(document.frm.year.options[document.frm.year.selectedIndex].value);	
	/// alert(document.frm.salutation.value)
	if(document.frm.salutation.value=="Select")
	{
	alert("Please select your Salutation!");
	document.frm.salutation.focus();
	return false;
	}
	if(document.frm.fname.value=="")
	{
	alert("Please fill First Name field!")
	document.frm.fname.focus()
	return false
	} 	
	str10 = document.frm.fname.value;
    for (var i = 0; i < str10.length; i++) {
		var ch = str10.substring(i, i + 1);
		if (ch == "0" || ch == "1" ||ch == "2" ||ch == "3" ||ch == "4" ||ch == "5" ||ch == "6" ||ch == "7" ||ch == "8" ||ch == "9"||ch==" ") 
		{
			alert("Please fill valid value for First Name field");
			document.frm.fname.focus();		
			document.frm.fname.select();		
			return false;
		}
	}
	
	if(document.frm.lname.value=="")
	{
	alert("Please fill Last Name field!")
	document.frm.lname.focus()
	return false
	}
	str10 = document.frm.lname.value;
    for (var i = 0; i < str10.length; i++) {
		var ch = str10.substring(i, i + 1);
		if (ch == "0" || ch == "1" ||ch == "2" ||ch == "3" ||ch == "4" ||ch == "5" ||ch == "6" ||ch == "7" ||ch == "8" ||ch == "9"||ch==" ") 
		{
			alert("Please fill valid value for Last Name field");
			document.frm.lname.focus();		
			document.frm.lname.select();		
			return false;
		}
	}
	
	var flag1=0;
	for(var i=0;i<document.frm.gender.length;i++){
		if(document.frm.gender[i].checked){flag1=1;}
	}
	if(flag1==0){
	alert("Please select your Gender!")
	document.frm.gender[0].focus();
	return false
	}
	if(document.frm.date.value=="")
	{
	alert("Please fill Date field!")
	document.frm.date.focus()
	return false
	}
	if(document.frm.month.value=="")
	{
	alert("Please fill Month field!")
	document.frm.month.focus()
	return false
	}
	if(document.frm.year.value=="")
	{
	alert("Please fill Year field!")
	document.frm.year.focus()
	return false;
	}

	if (md < 1 || md > 12) { // check month range
		    alert("Month must be between 1 and 12.");
		    document.frm.month.focus()
			return false;
		  }
		
		  if (dd < 1 || dd > 31) {
		    alert("Day must be between 1 and 31.");
		    document.frm.date.focus()
			return false;
		  }
		var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
		
		  if ((md==4 || md==6 || md==9 || md==11) && dd==31) {
		    alert("Month " + months[md-1] + " doesn't have 31 days!")
			document.frm.date.focus()
		    return false;
		  }
		
		  if (md == 2) { // check for february 29th
		    var isleap = (yd % 4 == 0 && (yd % 100 != 0 || yd % 400 == 0));
		    if (dd > 29 || (dd==29 && !isleap)) {
		      alert("February " + yd + " doesn't have " + dd + " days!");
			  document.frm.date.focus()
		      return false;
		    }
		  }
	
		
	if(document.frm.maritalstatus.value=="")
	{
	alert("Please select your Marital State!")
	document.frm.maritalstatus.focus()
	return false
	}	
	if(document.frm.res_add1.value=="")
	{
	alert("Please enter Address!")
	document.frm.res_add1.focus()
	return false
	}
	if (document.frm.country.value=="select")
	{
	alert ("Please select your Country!")
	document.frm.country.focus()
	return false
	}

	if(document.frm.city.value=="")
	{
	alert("Please enter City!")
	document.frm.city.focus()
	return false
	}
	else (document.frm.city.value!="")
			{
				var mytext=document.frm.city.value;
				var number=IsNumeric(mytext);
				if (number=="false")
				{
					document.frm.city.value="";
	                document.frm.city.focus();
	                return false;
				}
		}// city validation
	
	
	str9 = document.frm.res_pincode.value
	if (str9=="")
	{
	alert("Please fill Pincode field!")
	document.frm.res_pincode.focus()
	return false
	}
	else{
    for (var i = 0; i < str9.length; i++) {
		var ch = str9.substring(i, i + 1);
		if (ch < "0" || "9" < ch) 
		{
		if(ch==" "){}
		else {
			alert("\nThe Pincode field only accepts integers.\n\nPlease re-enter your pincode..");
			document.frm.res_pincode.focus();		
			document.frm.res_pincode.select();		
			return false;
			}
		}
	}
	}
		ok=true

	var str9 = document.frm.res_phone.value
	if (str9 == "") {
		alert("The phone field is blank.\n\nPlease fill the phone field.")
	document.frm.res_phone.focus();		
	return false;
	}

	if (str9.indexOf("+") != 0) 
	{
		alert("Value of phone field should be as shown in e.g.\n\nPlease re-enter the phone field.")
		document.frm.res_phone.focus();		
		return false;
	}
	if (str9.indexOf("-") == -1) 
	{
		alert("Value of phone field should be as shown in e.g.\n\nPlease re-enter the phone field.")
		document.frm.res_phone.focus();		
		return false;
	}
	for (var i = 0; i < str9.length; i++) {
		var ch = str9.substring(i, i + 1);
		if ( (ch == "+") || (ch == "-" ) || (ch == " " ))
		{
		}
		else if (ch < "0" || "9" < ch)  
		{
			alert("The phone field only accepts integers.\n\nPlease re-enter your phone no.")
			document.frm.res_phone.select();		
			document.frm.res_phone.focus();		
			return false;
		}
	}
	ok=true

	var str9 = document.frm.off_phone.value
	if(str9!="")
	{
	if (str9.indexOf("+") != 0) 
	{
		alert("Value of phone field should be as shown in e.g.\n\nPlease re-enter the phone field.")
		document.frm.off_phone.focus();		
		return false;
	}
	if (str9.indexOf("-") == -1) 
	{
		alert("Value of phone field should be as shown in e.g.\n\nPlease re-enter the phone field.")
		document.frm.off_phone.focus();		
		return false;
	}
	for (var i = 0; i < str9.length; i++) {
		var ch = str9.substring(i, i + 1);
		if ( (ch == "+") || (ch == "-" ) || (ch == " " ))
		{
		}
		else if (ch < "0" || "9" < ch)  
		{
			alert("The phone field only accepts integers.\n\nPlease re-enter your phone no.")
			document.frm.off_phone.select();		
			document.frm.off_phone.focus();		
			return false;
		}
	}
	}
	ok=true

	if(document.frm.res_email.value=="")
	{
		alert("Please enter Email address.")
		document.frm.res_email.focus()
		ok=false
		return ok
	}
	else
	{
	var str =/[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9]+\.[-a-zA-Z0-9\.]+/;
	var eflag = document.frm.res_email.value.match(str);
	if(eflag!=document.frm.res_email.value)
	{
		alert("Please enter a valid Email Address")
		document.frm.res_email.focus();
		document.frm.res_email.select();
		return false;
	}
	}

	if(document.frm.rec_jobposition.value=="")
	{
	alert("Please select your job")
	document.frm.rec_jobposition.focus()
	return false
	}	
	if(document.frm.rec_jobposition.value=="other" && document.frm.otherpos.value=="")
	{
	alert("Please enter other job position")
	document.frm.otherpos.focus()
	return false
	}	
	if(document.frm.rec_designation.value=="")
	{
	alert("Please select your designation level ")
	document.frm.rec_designation.focus()
	return false
	}	
		
if(document.frm.exp[0].checked==true)
   {
	if(document.frm.ex_cname.value=="")
	{
	alert("Please fill Company Name")
	document.frm.ex_cname.focus()
	return false
	}
	if(document.frm.ex_dprt.value=="")
	{
	alert("Please fill department field")
	document.frm.ex_dprt.focus()
	return false
	} 
	if(document.frm.ex_desig.value=="")
	{
	alert("Please fill designation field")
	document.frm.ex_desig.focus()
	return false
	} 
	if(document.frm.ex_roll.value=="")
	{
	alert("Please fill role field")
	document.frm.ex_roll.focus()
	return false
	} 
  }
  
 if ((document.frm.fromyear.value-document.frm.toyear.value)>0)
  {
  alert("To date must be more then from date");
	document.frm.frommonth.focus();
	return false;
  } 
  if((document.frm.fromyear.value-document.frm.toyear.value)==0)
  {
  if((document.frm.frommonth.value-document.frm.tomonth.value)>0)
  {
  alert("To date must be more then from date!")
	document.frm.frommonth.focus()
	return false;
  }
  }  
if ((document.frm.fromyear1.value-document.frm.toyear1.value)>0)
  {
  alert("To date must be more then from date!");
	document.frm.frommonth1.focus();
	return false;
  } 
  if((document.frm.fromyear1.value-document.frm.toyear1.value)==0)
  {
  if((document.frm.frommonth1.value-document.frm.tomonth1.value)>0)
  {
  alert("To date must be more then from date!")
	document.frm.frommonth1.focus()
	return false;
  }
  } 
if ((document.frm.fromyear2.value-document.frm.toyear2.value)>0)
  {
  alert("To date must be more then from date!");
	document.frm.frommonth2.focus();
	return false;
  } 
  if((document.frm.fromyear2.value-document.frm.toyear2.value)==0)
  {
  if((document.frm.frommonth2.value-document.frm.tomonth2.value)>0)
  {
  alert("To date must be more then from date!")
	document.frm.frommonth2.focus()
	return false;
  }
  }

	var dd = parseInt(document.frm.ex_periodfrm_date.options[document.frm.ex_periodfrm_date.selectedIndex].value);
	var md = parseInt(document.frm.ex_periodfrm_month.options[document.frm.ex_periodfrm_month.selectedIndex].value);
	var yd = parseInt(document.frm.ex_periodfrm_year.options[document.frm.ex_periodfrm_year.selectedIndex].value);	
	if (md < 1 || md > 12) { // check month range
		    alert("Month must be between 1 and 12.");
		    document.frm.ex_periodfrm_month.focus()
			return false;
		  }
		
		  if (dd < 1 || dd > 31) {
		    alert("Day must be between 1 and 31.");
		    document.frm.ex_periodfrm_date.focus()
			return false;
		  }
		  if ((md==4 || md==6 || md==9 || md==11) && dd==31) {
		    alert("Month " + months[md-1] + " doesn't have 31 days!")
			document.frm.ex_periodfrm_date.focus()
		    return false;
		  }
		
		  if (md == 2) { // check for february 29th
		    var isleap = (yd % 4 == 0 && (yd % 100 != 0 || yd % 400 == 0));
		    if (dd > 29 || (dd==29 && !isleap)) {
		      alert("February " + yd + " doesn't have " + dd + " days!");
			  document.frm.ex_periodfrm_date.focus()
		      return false;
		    }
		  }


	var dd = parseInt(document.frm.ex_periodto_date.options[document.frm.ex_periodto_date.selectedIndex].value);
	var md = parseInt(document.frm.ex_periodto_month.options[document.frm.ex_periodto_month.selectedIndex].value);
	var yd = parseInt(document.frm.ex_periodto_year.options[document.frm.ex_periodto_year.selectedIndex].value);	
	if (md < 1 || md > 12) { // check month range
		    alert("Month must be between 1 and 12.");
		    document.frm.ex_periodto_month.focus()
			return false;
		  }
		
		  if (dd < 1 || dd > 31) {
		    alert("Day must be between 1 and 31.");
		    document.frm.ex_periodto_date.focus()
			return false;
		  }
		  if ((md==4 || md==6 || md==9 || md==11) && dd==31) {
		    alert("Month " + months[md-1] + " doesn't have 31 days!")
			document.frm.ex_periodto_date.focus()
		    return false;
		  }
		
		  if (md == 2) { // check for february 29th
		    var isleap = (yd % 4 == 0 && (yd % 100 != 0 || yd % 400 == 0));
		    if (dd > 29 || (dd==29 && !isleap)) {
		      alert("February  doesn't have " + dd + " days!");
			  document.frm.ex_periodto_date.focus()
		      return false;
		    }
		  }
		  
 if ((document.frm.ex_periodfrm_year.value-document.frm.ex_periodto_year.value)>0)
  {
    alert("Period To must be more then Period from!");
	document.frm.ex_periodfrm_date.focus();
	return false;
  }
  if (!((document.frm.ex_periodfrm_year.value-document.frm.ex_periodto_year.value)<0))
  {
  if((document.frm.ex_periodfrm_year.value-document.frm.ex_periodfrm_year.value)==0)
  {
  if((document.frm.ex_periodfrm_month.value-document.frm.ex_periodto_month.value)>0)
  {
  alert("Period To must be more then Period from!")
	document.frm.document.frm.ex_periodfrm_date.focus()
	return false;
  }
  if((document.frm.ex_periodfrm_month.value-document.frm.ex_periodto_month.value)==0)
  {
  if((document.frm.ex_periodfrm_date.value-document.frm.ex_periodto_date.value)>0)
  {
  	alert("Period To must be more then Period from!")
	document.frm.document.frm.ex_periodfrm_date.focus()
	return false;
  }  
 }
 }
}
		  
/* if ((document.frm.ex_periodfrm_year.value-document.frm.ex_periodto_year.value)>0)
  {
    alert("Period To must be more then Period from1!");
	document.frm.ex_periodfrm_date.focus();
	return false;
  } 
  if((document.frm.ex_periodfrm_year.value-document.frm.ex_periodfrm_year.value)==0)
  {
  if((document.frm.ex_periodfrm_month.value-document.frm.ex_periodto_month.value)<0)
  {
  alert("Period To must be more then Period from2!")
	document.frm.document.frm.ex_periodfrm_date.focus()
	return false;
  }
  if((document.frm.ex_periodfrm_month.value-document.frm.ex_periodto_month.value)==0)
  {
  if((document.frm.ex_periodfrm_date.value-document.frm.ex_periodto_date.value)<0)
  {
  alert("Period To must be more then Period from3!")
	document.frm.document.frm.ex_periodfrm_date.focus()
	return false;
  }  
  }
  }*/
			 
/********** Validation for upload file******/
			 
str=document.frm.file1.value
if(document.frm.file1.value !="") 
{
start=str.indexOf(".")
last=str.length
str1=str.substring(start+1,last)
if((str1!="txt") && (str1!="rtf")  )
{
alert("Please select .txt or .rtf file.")
return false
}

}
return true;
}
