/*This validation is using with fValidator - Functions used here
Validate()
isProper(string)
isProperAlphaNum(string)
deleteBlanks(entry)
CharsInBag(s)
isInteger(s)
echeck(str)
ismaxlength(obj)
numbersonly(e, decimal)
clearText(thefield)
replaceText(thefield)*/

function Validate(){
	var retVal =  true; 
	if ((deleteBlanks(document.applyjob.fname.value)==null)||(deleteBlanks(document.applyjob.fname.value)=="")){
		alert("Enter valid name");
		/*document.applyjob.fname.value = "";*/
		document.applyjob.fname.focus();
		retVal =  false;
		return false;
	}else if (isProperAlphaNum(document.applyjob.fname.value) == false) {
        alert("Enter valid name");
        document.applyjob.fname.focus();
		retVal =  false;
        return false;
    }
	
	/*Code for checking the first name conatins only ' sign*/
	var fname1 =  deleteBlanks(document.applyjob.fname.value);
	var countval = 0;
	for(var i=0;i<=fname1.length;i++) {
		if(fname1.charAt(i) == "'") {
			countval = countval+1;
		}
	}
	if(countval == fname1.length) {
			alert("Enter valid name");
			/*document.applyjob.fname.value="";*/
			document.applyjob.fname.focus();
			retVal =  false;
			return false;
	}
/*
 	if ((deleteBlanks(document.applyjob.address.value)==null)||(deleteBlanks(document.applyjob.address.value)=="")){
		alert("Enter valid address");
		document.applyjob.address.value = "";
		document.applyjob.address.focus();
		retVal =  false;
		return false;
	}

	if ((deleteBlanks(document.applyjob.city.value)==null)||(deleteBlanks(document.applyjob.city.value)=="") || !isProper(document.applyjob.city.value)){
		alert("Enter valid city");
		document.applyjob.city.focus();
		retVal =  false;
		return false;
	}
*/

	var phoneValid = /^[0-9]{10}$/;

	var mobilephone =  document.applyjob.mobilephone.value;
	if(!mobilephone.match(phoneValid)) {
		alert('Enter valid mobile phone');
		document.applyjob.mobilephone.focus();
		retVal =  false;
		return false;	
	} 	
 	var homephone =   document.applyjob.homephone.value ;
	if(homephone!='') {
		if(!homephone.match(phoneValid)) {
			alert('Enter valid home phone');
			document.applyjob.homephone.focus();
			retVal =  false;
			return false;	
		}
	}
 	if ((document.applyjob.email.value==null)||(document.applyjob.email.value=="")){
		alert("Enter valid E-mail");
		document.applyjob.email.focus();
		retVal =  false;
		return false;
	}
	if (echeck(document.applyjob.email.value)==false){
		document.applyjob.email.focus();
		retVal =  false;
		return false; 
	} 

	if ((deleteBlanks(document.applyjob.city.value)==null)||(deleteBlanks(document.applyjob.city.value)=="") || !isProper(document.applyjob.city.value)){
		alert("Enter valid Current Location (City)");
		document.applyjob.city.focus();
		retVal =  false;
		return false;
	}
	if(document.applyjob.totalexperienceyy.value=="") {
		alert("Select Total Experience (YY)");
		document.applyjob.totalexperienceyy.focus();
		retVal =  false;
		return false;
	}

	if(document.applyjob.totalexperiencemm.value=="") {
		alert("Total Experience (MM)");
		document.applyjob.totalexperiencemm.focus();
		retVal =  false;
		return false;
	}
	if(document.applyjob.releventexperienceyy.value=="") {
		alert("Select Relevant Experience (YY)");
		document.applyjob.releventexperienceyy.focus();
		retVal =  false;
		return false;
	}
	if(document.applyjob.releventexperiencem.value=="") {
		alert("Select Relevant Experience (MM)");
		document.applyjob.releventexperiencem.focus();
		retVal =  false;
		return false;
	}	
	if(document.applyjob.skills.value=="") {
		alert("Select Key Skills");
		document.applyjob.skills.focus();
		retVal =  false;
		return false;
	}
	if(document.applyjob.skills.value=="Others") {
		if(document.applyjob.otherkills.value=="") {
			alert("Enter valid other Key Skills");
			document.applyjob.otherkills.focus();
			retVal =  false;
			return false;
		}
	}
 	if(document.applyjob.graduation.value=="") {
		alert("Select Graduation Degree");
		document.applyjob.graduation.focus();
		retVal =  false;
		return false;
	}
	if ((deleteBlanks(document.applyjob.employer.value)==null)||(deleteBlanks(document.applyjob.employer.value)=="") || !isProperAlphaNum(document.applyjob.employer.value)){
		alert("Enter Present Employer");
		document.applyjob.employer.focus();
		retVal =  false;
		return false;
	}
	var salpackage =  document.applyjob.package.value;
	if(salpackage=='' || salpackage ==null) {
		alert('Enter Current package (in lacs)');
		document.applyjob.package.focus();
		retVal =  false;
		return false;	
	}	
 	var strcount = charCounts(salpackage,".")
	var checkValid = /^\d{1,2}.\d{1,2}$/;
	if((strcount >= 2) || !salpackage.match(checkValid)) {
			alert("Enter valid Current package (in lacs)");
			document.applyjob.package.focus();
			retVal =  false;
			return false;
	}
 	var salexpected =  document.applyjob.expected.value;
	if(salexpected=='' || salexpected ==null) {
		alert('Enter Expected package (in lacs)');
		document.applyjob.expected.focus();
		retVal =  false;
		return false;	
	}	
 	var strcount = charCounts(salexpected,".")
	if((strcount >= 2) || !salexpected.match(checkValid)) {
			alert("Enter valid Expected package (in lacs)");
			document.applyjob.expected.focus();
			retVal =  false;
			return false;
	}
	if(document.applyjob.notice.value=="" || document.applyjob.notice.value==null || !isProperAlphaNum(document.applyjob.notice.value) ) {
		alert("Enter Notice period before Joining");
		document.applyjob.notice.focus();
		retVal =  false;
		return false;
	}
	if(document.applyjob.position.value=="" || document.applyjob.position.value==null) {
		alert("Select Position Applied for");
		document.applyjob.position.focus();
		retVal =  false;
		return false;
	}

	if(document.applyjob.position.value=="Others") {
		if(document.applyjob.otehrposition.value=="") {
			alert("Enter valid Position Applied for");
			document.applyjob.otehrposition.focus();
			retVal =  false;
			return false;
		}
	}
	if (document.applyjob.hear.value=="") {
		alert("Select How did you hear about C3IT Software Solutions");
		document.applyjob.hear.focus();
		retVal =  false;
		return false;
	}

	//document.applyjob.action="email.php";
	//document.applyjob.submit();

	//alert('End of the function');
	}
	//Main function ends here
	function otherSkills() {
		if(document.applyjob.skills.value=="Others") {
			document.getElementById('otherkillsdiv').style.display="block";
		} else {
			document.getElementById('otherkillsdiv').style.display="none";
		}
	}

	function otherPosition() {
		if(document.applyjob.position.value=="Others") {
			document.getElementById('otherpositiondiv').style.display="block";
		} else {
			document.getElementById('otherpositiondiv').style.display="none";
		}
	}

	function charCounts (strtovalidate,strtocheck) {
		var countval = 0;
		for(var i=0;i<=strtovalidate.length;i++) {
			if(strtovalidate.charAt(i) == strtocheck) {
				countval = countval+1;
			}
		}
		return countval;
	}


	function isProper(string) {
	
	   if (!string) return false;
	   //var iChars = "*|,\":<>[]{}`\;()@&$#%1234567890";
	   var iChars = "`~!@#$%^&*()_-+=|\\{}[]:;\"\'<>.?/1234567890";
	
	   for (var i = 0; i < string.length; i++) {
		  if (iChars.indexOf(string.charAt(i)) != -1)
			 return false;
	   }
	   return true;
	} 

	function isProperAlphaNum(string) {
	
	   if (!string) return false;
	   var iChars = "*|,\":<>[]{}`\;()@&$#%";
	
	   for (var i = 0; i < string.length; i++) {
		  if (iChars.indexOf(string.charAt(i)) != -1)
			 return false;
	   }
	   return true;
	} 

	function deleteBlanks(entry)
	{
		var len = entry.length ;
		var foundBlank = 1;
		while(foundBlank == 1 && len > 0) 
		{
			var indx = entry.indexOf(" ");
			if(indx == -1) 
				foundBlank = 0 ;
			else
				entry = entry.substring(0,indx) + entry.substring(indx+1,len);
			len = entry.length;
		}
		return entry;
	}

	var bugchars = '!#$^&*()+|}{[]?><~%:;/,=`"\'';
	function CharsInBag(s)
	{   var i;
	var lchar="";
		// Search through string's characters one by one.
		// If character is not in bag.
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if(i>0)lchar=s.charAt(i-1)
			if (bugchars.indexOf(c) != -1 || (lchar=="." && c==".")) return false;
		}
		return true;
	}
	
	function isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is not a number.
			var c = s.charAt(i);
			if ((c >= "0") && (c <= "9") && (c != ".")) return false;
		}
		// All characters are numbers.
		return true;
	}
	function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var lastdot=str.lastIndexOf(dot)
		var lastval = parseInt(lstr) - parseInt(lastdot);

		if (lastval >5){
		   alert("Invalid E-mail")
		   return false;
		}
		if (lastval <3){
		   alert("Invalid E-mail")
		   return false;
		}

		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.substring(lastdot+1)==""){
		    alert("Invalid E-mail")
		    return false
		}
		 
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }
		if(CharsInBag(str)==false){
		    alert("Invalid E-mail")
		    return false
		 }
	   /*var arrEmail=str.split("@")
		 var ldot=arrEmail[1].indexOf(".")
		 if(isInteger(arrEmail[1].substring(ldot+1))==false){
		    alert("Invalid E-mail ID2")
		    return false
		 }*/
 		 return true					
	}

	//Function for checking the maximun characters in the teaxt area
	function ismaxlength(obj){
	/*var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""*/
	var mlength=250; 
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
	}
	//Function using to enter numbers only
	function numbersonly(e, decimal) {
		var key;
		var keychar;
	  
		 if (window.event) {
			key = window.event.keyCode;
		  }
		  else if (e) {
			 key = e.which;
		  }
		  else {
			 return true;
		  }
		  
		  keychar = String.fromCharCode(key);
	  
		  if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
			 return true;
		  }
		  else if ((("0123456789").indexOf(keychar) > -1)) {
			 return true;
		  }
		  else if (decimal && (keychar == ".")) { 
			return true;
		  }
		  else
			 return false;
	}

	//Validate Month
	function isValiddate(dateval) {
		var key = "/";
		var mm = dateval.split("/") ;
		if(mm[0] > 12) {
			return false;
		}
		return true;
	}

	//Checking the phone number is valid or not
	function checkPhone(entry)
	{
		var len = entry.length ;
		var foundBlank = 1;
		while(foundBlank == 1 && len > 0) 
		{
			var indx = entry.indexOf("-");
			if(indx == -1) 
				foundBlank = 0 ;
			else
				entry = entry.substring(0,indx) + entry.substring(indx+1,len);
			len = entry.length;
		}
		return entry;
	}

	//Checking the phone fileld is blank or not
	function checkPhoneBlanks(entry)
	{
		var len = entry.length ;
		var foundBlank = 1;
		while(foundBlank == 1 && len > 0) 
		{
			var indx = entry.indexOf("_");
			if(indx == -1) 
				foundBlank = 0 ;
			else
				entry = entry.substring(0,indx) + entry.substring(indx+1,len);
			len = entry.length;
		}
		return entry;
	}

	function selectnonmandatory() {
	if (document.applyjob.lawyer_comitted_legal_malpractice.value=="Yes") {
		if (document.applyjob.how_was_lawyer_hired.value=="") {
			alert("Select how did you hire your lawyer");
			document.applyjob.how_was_lawyer_hired.focus();
			retVal =  false;
			return false;
		}
	}
	}

	function trim_text(str,controlname,frm)
		{
			
			str = str.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
			cname = eval("document.forms[frm]."+controlname);
			cname.value=str; 
		}

//------------------- for clearing and replacing text in form input fields and textareas -------------------//
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue; }
}




