function isWhitespace(s)
{
   var i;
   for (i = 0; i < s.length; i++)
   {
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if(c!=" ")
		return false;
   }
   // All characters are whitespace.
   return true;
}

function checkcity()
{
	
	if (frm.txtcity.options[frm.txtcity.selectedIndex].value == "other")
	{
	get = document.getElementById("txtothercity")
	get.disabled = false;
	frm.txtothercity.focus()
	}
	else
	{
		get = document.getElementById("txtothercity")
		get.disabled = true;
	}
}
function checktech()
{
	
	if (frm.txttechnical.options[frm.txttechnical.selectedIndex].value == "other")
	{
	get = document.getElementById("txtothertechnical")
	get.disabled = false;
	frm.txtothertechnical.focus()
	}
	else
	{
		get = document.getElementById("txtothertechnical")
		get.disabled = true;
	}

	
}
var dtCh= "/";
var minYear=2000;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function emailCheck (emailStr) 
{
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {

// alert("The e-mail address appears to be incorrect (check @ and .'s)")
 return false
}
var user=matchArray[1]
var domain=matchArray[2]
 
if (user.match(userPat)==null) {
    // user is not valid
  //  alert("The e-mail address username appears to be incorrect")
    return false
}
 
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
   for (var i=1;i<=4;i++) {
     if (IPArray[i]>255) {
  //       alert("Destination IP address is invalid!")
  return false
     }
    }
    return true
}
 
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
  // alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

if (len<2) {
   //var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}
 
// If we've gotten this far, everything's valid!
return true;
}


function formvalidation()
{
if (frm.txtpost.value == "")
{
	alert("Select the Post for your apply.")
	frm.txtpost.focus()
	return false;
}
if(frm.txtfirstname.value=="")
{
	alert("Enter Firstname")
	frm.txtfirstname.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtfirstname.value))
	{
		alert("First name cannnot contain only space")
		frm.txtfirstname.focus()
		return false;
	}
}


if(frm.txtmiddlename.value!="")
{
	if(isWhitespace(frm.txtmiddlename.value))
	{
		alert("Middle name cannnot contain only space")
		frm.txtmiddlename.focus()
		return false;
	}
}
if(frm.txtlastname.value=="")
{
	alert("Enter Lastname")
	frm.txtlastname.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtlastname.value))
	{
		alert("Last name cannnot contain only space")
		frm.txtlastname.focus()
		return false;
	}
}
if(frm.txtaddress1.value=="")
{
	alert("Enter Address 1")
	frm.txtaddress1.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtaddress1.value))
	{
		alert("Address I cannnot contain only space")
		frm.txtaddress1.focus()
		return false;
	}
}
if(frm.txtaddress2.value!="")
{
	if(isWhitespace(frm.txtaddress1.value))
	{
		alert("Address II cannnot contain only space")
		frm.txtaddress1.focus()
		return false;
	}
}

if(frm.txtaddress3.value!="")
{
	if(isWhitespace(frm.txtaddress3.value))
	{
		alert("Address III cannnot contain only space")
		frm.txtaddress3.focus()
		return false;
	}
}
if(frm.txtcity.value == "all" && frm.txtothercity.value == "")
{
		alert("Select City")
		frm.txtcity.focus()
		return false;
}
if(frm.txtothercity.value!="")
{
	if(isWhitespace(frm.txtothercity.value))
	{
		alert("City Name cannnot contain only space")
		frm.txtothercity.focus()
		return false;
	}
}
if(frm.txtstate.value=="all")
{
		alert("Select State")
		frm.txtstate.focus()
		return false;
}

if(frm.txtpincode.value=="")
{
	alert("Enter Pincode Number")
	frm.txtpincode.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtpincode.value))
		{
			alert("Pincode Number cannnot contain only space")
			frm.txtpincode.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtpincode.value)))
		{
			alert("Pincode Number should be numeric only")
			frm.txtpincode.focus()
			return false;
		}

	if(frm.txtpincode.value.length < 6)
		{
			alert("Invalid Pincode Number")
			frm.txtpincode.focus()
			return false;
		}
}

if(frm.txtstdcode.value!="")
{
	if(isWhitespace(frm.txtstdcode.value))
		{
			alert("Residence STD Code cannnot contain only space")
			frm.txtstdcode.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtstdcode.value)))
		{
			alert("Residence STD Code Number should be numeric only")
			frm.txtstdcode.focus()
			return false;
		}
		
}
if(frm.txtResno.value!="")
{
	if(isWhitespace(frm.txtResno.value))
		{
			alert("Residence Number cannnot contain only space")
			frm.txtResno.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtResno.value)))
		{
			alert("Residence Number should be numeric only")
			frm.txtResno.focus()
			return false;
		}
		
}
if(frm.txtppcode.value!="")
{
	if(isWhitespace(frm.txtppcode.value))
		{
			alert("PP STD Code cannnot contain only space")
			frm.txtppcode.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtppcode.value)))
		{
			alert("PP STD Code Number should be numeric only")
			frm.txtppcode.focus()
			return false;
		}
		
}
if(frm.txtppno.value!="")
{
	if(isWhitespace(frm.txtppno.value))
		{
			alert("PP Number cannnot contain only space")
			frm.txtppno.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtppno.value)))
		{
			alert("PP Number should be numeric only")
			frm.txtppno.focus()
			return false;
		}
		
}

if(frm.txtmobile.value!="")
{
	if(isWhitespace(frm.txtmobile.value))
		{
			alert("Mobile Number cannnot contain only space")
			frm.txtmobile.focus()
			return false;
		}
	if(isNaN(parseInt(frm.txtmobile.value)))
		{
			alert("Mobile Number should be numeric only")
			frm.txtmobile.focus()
			return false;
		}
		
}

if(frm.txtpriemail.value!="")
{
	if(isWhitespace(frm.txtpriemail.value))
		{
			alert("Primary Email ID cannnot contain only space")
			frm.txtpriemail.focus()
			return false;
		}
	if(emailCheck(frm.txtpriemail.value)==false)
		{
			alert("Invalid Primary Email ID")
			frm.txtpriemail.focus()
			return false;
		}
}

if(frm.txtsecemail.value!="")
{
	if(isWhitespace(frm.txtsecemail.value))
		{
			alert("Secondary Email ID cannnot contain only space")
			frm.txtsecemail.focus()
			return false;
		}
	if(emailCheck(frm.txtpriemail.value)== false)
		{
			alert("Invalid Secondary Email ID")
			frm.txtsecemail.focus()
			return false;
		}
		
}
if(frm.txtgender.value == "all" )
{
		alert("Select Gender")
			frm.txtgender.focus()
			return false;	
}
if(frm.txtbirthdate.value == "" )
{
		alert("Select Birth Date")
		frm.txtbirthdate.focus()
		return false;	
}
if(frm.txtbirthmonth.value == "" )
{
		alert("Select Birth Month")
		frm.txtbirthmonth.focus()
		return false;	
}
if(frm.txtbirthyear.value == "" )
{
		alert("Select Birth Year")
		frm.txtbirthyear.focus()
		return false;	
}
if(frm.txtreftocode.value != "" )
{
		if(isWhitespace(frm.txtreftocode.value))
		{
			alert("Employee code cannnot contain only space")
			frm.txtreftocode.focus()
			return false;
		}
}
if(frm.txtreftoname.value != "" )
{
		if(isWhitespace(frm.txtreftoname.value))
		{
			alert("Employee Name cannnot contain only space")
			frm.txtreftoname.focus()
			return false;
		}
}
if(frm.txtreftoemail.value != "" )
{
		if(isWhitespace(frm.txtreftoemail.value))
		{
			alert("Employee Email cannnot contain only space")
			frm.txtreftoemail.focus()
			return false;
		}
		if(emailCheck(frm.txtreftoemail.value)== false)
		{
			alert("Invalid Employee Email ID")
			frm.txtreftoemail.focus()
			return false;
		}
}
if(frm.txtrefbycode.value != "" )
{
		if(isWhitespace(frm.txtrefbycode.value))
		{
			alert("Employee code cannnot contain only space")
			frm.txtrefbycode.focus()
			return false;
		}
}
if(frm.txtrefbyname.value != "" )
{
		if(isWhitespace(frm.txtrefbyname.value))
		{
			alert("Employee Name cannnot contain only space")
			frm.txtrefbyname.focus()
			return false;
		}
}
if(frm.txtrefbyemail.value != "" )
{
		if(isWhitespace(frm.txtrefbyemail.value))
		{
			alert("Employee Email cannnot contain only space")
			frm.txtrefbyemail.focus()
			return false;
		}
		if(emailCheck(frm.txtrefbyemail.value)== false)
		{
			alert("Invalid Employee Email ID")
			frm.txtrefbyemail.focus()
			return false;
		}
}
if(frm.txtlang.value=="")
{
	alert("Enter Langauge")
	frm.txtlang.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtlang.value))
	{
		alert("Langauge cannnot contain only space")
		frm.txtlang.focus()
		return false;
	}
}
if(frm.txtsource.value=="all")
{
	alert("Select Source")
	frm.txtsource.focus()
	return false;
}
if(frm.txtxqul.value=="")
{
	alert("Enter Qualification")
	frm.txtxqul.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtxqul.value))
	{
		alert("Qualification cannnot contain only space")
		frm.txtxqul.focus()
		return false;
	}
}
if(frm.txtxuni.value=="")
{
	alert("Enter University / Board Name")
	frm.txtxuni.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtxuni.value))
	{
		alert("University / Board Name cannnot contain only space")
		frm.txtxuni.focus()
		return false;
	}
}
if(frm.txtxyear.value=="")
{
	alert("Select Passing Year")
	frm.txtxyear.focus()
	return false;
}
if(frm.txtxgrade.value=="")
{
	alert("Enter Grade")
	frm.txtxgrade.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtxgrade.value))
	{
		alert("Grade cannnot contain only space")
		frm.txtxgrade.focus()
		return false;
	}
}

if(frm.txtxiiqul.value!="")
{
	if(isWhitespace(frm.txtxiiqul.value))
	{
		alert("Qualification cannnot contain only space")
		frm.txtxiiqul.focus()
		return false;
	}
	
		if(frm.txtxiiuni.value=="")
	{
		alert("Enter University / Board Name")
		frm.txtxiiuni.focus()
		return false;
	}
	else
	{
		if(isWhitespace(frm.txtxiiuni.value))
		{
			alert("University / Board Name cannnot contain only space")
			frm.txtxiiuni.focus()
			return false;
		}
	}
	if(frm.txtxiiyear.value=="")
	{
		alert("Select Passing Year")
		frm.txtxiiyear.focus()
		return false;
	}
	if(frm.txtxiigrade.value=="")
	{
		alert("Enter Grade")
		frm.txtxiigrade.focus()
		return false;
	}
	else
	{
		if(isWhitespace(frm.txtxiigrade.value))
		{
			alert("Grade cannnot contain only space")
			frm.txtxiigrade.focus()
			return false;
		}
	}
}
if(frm.txtgrdqul.value!="")
{
	if(frm.txtgrduni.value=="")
{
	alert("Enter University / Board Name")
	frm.txtgrduni.focus()
	return false;
}
else
{
	if(isWhitespace(frm.txtgrduni.value))
	{
		alert("University / Board Name cannnot contain only space")
		frm.txtgrduni.focus()
		return false;
	}
	}
	if(frm.txtgrdyear.value=="")
	{
		alert("Select Passing Year")
		frm.txtgrdyear.focus()
		return false;
	}
	if(frm.txtgrdgrade.value=="")
	{
		alert("Enter Grade")
		frm.txtgrdgrade.focus()
		return false;
	}
	else
	{
		if(isWhitespace(frm.txtgrdgrade.value))
		{
			alert("Grade cannnot contain only space")
			frm.txtgrdgrade.focus()
			return false;
		}
	}

}

if(frm.txtpgqul.value!="")
{

if(frm.txtpguni.value!="")
{
	if(isWhitespace(frm.txtpguni.value))
	{
		alert("University / Board Name cannnot contain only space")
		frm.txtpguni.focus()
		return false;
	}
}
if(frm.txtpguni.value!="")
{
	if(frm.txtpgyear.value=="")
	{
		alert("Select Year")
		frm.txtpgyear.focus()
		return false;
	}
}
if(frm.txtpguni.value!="")
{
	if(frm.txtpggrade.value=="")
	{
		alert("Enter Grade")
		frm.txtpggrade.focus()
		return false;
	}
else
	{
		if(isWhitespace(frm.txtpggrade.value))
		{
			alert("Grade cannnot contain only space")
			frm.txtpggrade.focus()
			return false;
		}
	}
}
}
if(frm.txtotherqul.value!="")
	{
		if(isWhitespace(frm.txtotherqul.value))
		{
			alert("Qualification cannnot contain only space")
			frm.txtotherqul.focus()
			return false;
		}
		
		if(frm.txtotheruni.value!="")
		{
			if(isWhitespace(frm.txtotheruni.value))
			{
				alert("University Name cannnot contain only space")
				frm.txtotheruni.focus()
				return false;
			}
		}
		if(frm.txtotheryear.value=="all")
		{
				alert("Select Passing Year")
				frm.txtotheryear.focus()
				return false;
		}
		if(frm.txtothergrade.value!="")
		{
			if(isWhitespace(frm.txtothergrade.value))
			{
				alert("Grade cannnot contain only space")
				frm.txtothergrade.focus()
				return false;
			}
		}
		
	}

if(frm.txttechnical.value=="all")
{
	alert("Select Technical Skill")
	frm.txttechnical.focus()
	return false;
}
if(frm.txttechnical.value=="other")
{
	if(frm.txtothertechnical.value=="")
	{
	alert("Enter Technical Skill")
	frm.txtothertechnical.focus()
	return false;
	}
	if(isWhitespace(frm.txtothertechnical.value))
			{
				alert("Technical Skill cannnot contain only space")
				frm.txtothertechnical.focus()
				return false;
			}
}
if(frm.txtcuremp.value!="")
{
	if(isWhitespace(frm.txtcuremp.value))
	{
		alert("Current Employer cannnot contain only space")
		frm.txtcuremp.focus()
		return false;
	}
}
if(frm.txtcurdesign.value!="")
{
	if(isWhitespace(frm.txtcurdesign.value))
	{
		alert("Designation cannnot contain only space")
		frm.txtcurdesign.focus()
		return false;
	}
}
if(frm.txtexpcectsal.value=="0.0")
	{
	alert("Enter Expect Salary")
	frm.txtexpcectsal.focus()
	return false;
	}
frm.txtexpcectsal.value = parseFloat(frm.txtexpcectsal.value)
if (frm.txtpresal.value != "")
{
	frm.txtpresal.value = parseFloat(frm.txtpresal.value)
}
if(frm.txtcomppackage.value!="")
{
	if(isWhitespace(frm.txtcomppackage.value))
	{
		alert("Package cannnot contain only space")
		frm.txtcomppackage.focus()
		return false;
	}
}
if(frm.txtcomplang.value!="")
{
	if(isWhitespace(frm.txtcomplang.value))
	{
		alert("Language cannnot contain only space")
		frm.txtcomplang.focus()
		return false;
	}
}

if(frm.txtbrief.value=="")
	{
	alert("Enter Brief Profile")
	frm.txtbrief.focus()
	return false;
	}
else
{
	if(isWhitespace(frm.txtbrief.value))
	{
	alert("Brief Profile cannnot contain only space")
	frm.txtbrief.focus()
	return false;
	}
}

if(frm.txtradjswsel.value == "yes")
{
	if (frm.txtselmth.value == "all")
	{
	alert("Select Month")
	frm.txtselmth.focus()
	return false;
	}
	if (frm.txtselyear.value == "all")
	{
	alert("Select Year")
	frm.txtselyear.focus()
	return false;
	}
}
if(frm.txtfile.value != "")
{
	if(isWhitespace(frm.txtfile.value))
	{
	alert("File cannnot contain only space")
	frm.txtfile.focus()
	return false;
	}
	
	file = frm.txtfile.value
	files = file.split(".")
	if (files[1] == "DOC" || files[1] == "doc" || files[1] == "txt" || files[1] == "TXT" )
	{
	
	//return true;
	
	}
	else
	{
		alert("Select .DOC or .TXT file")
		frm.txtfile.focus();
		return false;
	}
	
	
}
}

