// email validation script 

function validMail(obj)	{				
	var EmailOk  = true
	var Temp     = obj
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1   // Array is from 0 to length-1

	if(obj.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
		    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
		    (Period == Length ) ||             // Must be atleast one valid char after '.'
		    (Space  != -1))                    // No empty spaces permitted
			   {  
		      EmailOk = false
		      alert("Please enter a valid e-mail address!");
			      Temp.value="";
			      Temp.focus();
		      return EmailOk;
   			}
		}
	}





function contactus_Validator(x)
	{
	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }
	 
	//First Name
	x.fname.value = LTrim(x.fname.value);
	x.fname.value = RTrim(x.fname.value);
	if (!emptystring(x.fname.value))
		 {
			alert("Please enter your First Name");
			x.fname.focus();
			flag=false;
			return (false);
		}else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
		if (!(validate(x.fname.value,checkOk)))
		{
		alert("The Name field only accepts letters & spaces.\n\nPlease re-enter your name");
		x.fname.value= "";
		x.fname.focus();
		flag=false;
		return (false);
		}
     }
	 
	 //Last Name
	x.lname.value = LTrim(x.lname.value);
	x.lname.value = RTrim(x.lname.value);
	if (!emptystring(x.lname.value))
		 {
			alert("Please enter your Last Name");
			x.lname.focus();
			flag=false;
			return (false);
		}else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
		if (!(validate(x.lname.value,checkOk)))
		{
		alert("The Name field only accepts letters & spaces.\n\nPlease re-enter your name");
		x.lname.value= "";
		x.lname.focus();
		flag=false;
		return (false);
		}
     }
  
     //Company
	x.company.value = LTrim(x.company.value);
	x.company.value = RTrim(x.company.value);
	if (!emptystring(x.company.value))
		 {
			alert("Please enter your Company");
			x.company.focus();
			flag=false;
			return (false);
		}
		
	//JobTitle
	x.jobTitle.value = LTrim(x.jobTitle.value);
	x.jobTitle.value = RTrim(x.jobTitle.value);
	if (!emptystring(x.jobTitle.value))
		 {
			alert("Please enter your Job Title");
			x.jobTitle.focus();
			flag=false;
			return (false);
		}
	
	//Email
	x.email.value = LTrim(x.email.value);
	x.email.value = RTrim(x.email.value);
	if (!emptystring(x.email.value))
		 {
			alert("Please enter the Email id");
			x.email.focus();
			flag=false;
			return (false);
		}else {
		var flag  = true
		var Temp     = x.email
		var AtSym    = Temp.value.indexOf('@')
		var Period   = Temp.value.lastIndexOf('.')
		var Space    = Temp.value.indexOf(' ')
		var Length   = Temp.value.length - 1   // Array is from 0 to length-1
		
		if(x.email.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
		   {  
			  flag = false
			  alert("Please enter a valid e-mail address!");
			  Temp.value="";
			  Temp.focus();
			  return flag;
		   }
		}
		}

	
	//Phone
	x.phone.value = LTrim(x.phone.value);
	x.phone.value = RTrim(x.phone.value);
	if (!emptystring(x.phone.value))
		 {
			alert("Please enter your Phone Number");
			x.phone.focus();
			flag=false;
			return (false);
		} else {
           var checkOk = "0123456789 ";
			if (!(validate(x.phone.value,checkOk)))
				{
				alert("Please Enter the Valid Phone Number");
				x.phone.value= "";
				x.phone.focus();
				flag=false;
				return (false);
				}
		}
						
		
	//address
	x.address.value = LTrim(x.address.value);
	x.address.value = RTrim(x.address.value);
	if (!emptystring(x.address.value))
		 {
			alert("Please enter your Mailing Address");
			x.address.focus();
			flag=false;
			return (false);
		}
		
	//city
	x.city.value = LTrim(x.city.value);
	x.city.value = RTrim(x.city.value);
	if (!emptystring(x.city.value))
		 {
			alert("Please enter your City");
			x.city.focus();
			flag=false;
			return (false);
		}
		
	//Zip code
	x.zip.value = LTrim(x.zip.value);
	x.zip.value = RTrim(x.zip.value);
	if (!emptystring(x.zip.value))
		 {
			alert("Please enter your Zip code");
			x.zip.focus();
			flag=false;
			return (false);
		} else {
           var checkOk = "0123456789 ";
			if (!(validate(x.zip.value,checkOk)))
				{
				alert("Please Enter the Valid Zip code");
				x.zip.value= "";
				x.zip.focus();
				flag=false;
				return (false);
				}
		}
  	//country
	x.country.value = LTrim(x.country.value);
	x.country.value = RTrim(x.country.value);
	if (!emptystring(x.country.value))
		 {
			alert("Please enter your Country");
			x.country.focus();
			flag=false;
			return (false);
		}
			
	//Set this return value to true when you want to submit the form
	return (flag);
}


function Form2_Validator(x)
{
  	//Validate Function 
	function validate(value,checkOk)
	{
	var checkStr = value;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOk.length;  j++)
		if (ch == checkOk.charAt(j))
			break;
			if (j == checkOk.length) {
			 allValid = false;
			 break;
			}
		}
	  if (!allValid) {
		return (false);
	  }
	else { return (true); }
  }

		//Trim script
		function Trim(STRING){
		STRING = LTrim(STRING);
		return RTrim(STRING);
		}

		function RTrim(STRING){
		while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
		}
		return STRING;
		}

		function LTrim(STRING){
		while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
		}
		return STRING;
		}
	 // emptycheck
	 var flag=true;
	 function emptystring(value)
	 {
	   if (value=="") return (false);
	   else return(true);
	 }


    //First Name	
	x.First_Name.value = LTrim(x.First_Name.value);
	x.First_Name.value = RTrim(x.First_Name.value);
	if (!emptystring(x.First_Name.value))
		 {
			alert("Please enter your First Name");
			x.First_Name.focus();
			flag=false;
			return (false);
		}else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
			if (!(validate(x.First_Name.value,checkOk)))
			{
			alert("The Name field only accepts letters & spaces.\n\nPlease re-enter your name");
			x.First_Name.value= "";
			x.First_Name.focus();
			flag=false;
			return (false);
			}
		}

	 //Last Name
	x.Last_Name.value = LTrim(x.Last_Name.value);
	x.Last_Name.value = RTrim(x.Last_Name.value);
	if (!emptystring(x.Last_Name.value))
		 {
			alert("Please enter your Last Name");
			x.Last_Name.focus();
			flag=false;
			return (false);
		}else {

           var checkOk = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .";
		if (!(validate(x.Last_Name.value,checkOk)))
		{
		alert("The Name field only accepts letters & spaces.\n\nPlease re-enter your name");
		x.Last_Name.value= "";
		x.Last_Name.focus();
		flag=false;
		return (false);
		}
     }

//Email
	x.Email.value = LTrim(x.Email.value);
	x.Email.value = RTrim(x.Email.value);
	if (!emptystring(x.Email.value))
		 {
			alert("Please enter the Email id");
			x.Email.focus();
			flag=false;
			return (false);
		}else {
		var flag  = true
		var Temp     = x.Email
		var AtSym    = Temp.value.indexOf('@')
		var Period   = Temp.value.lastIndexOf('.')
		var Space    = Temp.value.indexOf(' ')
		var Length   = Temp.value.length - 1   // Array is from 0 to length-1
		
		if(x.email.value !=""){
		if ((AtSym < 1) ||                     // '@' cannot be in first position
			(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
			(Period == Length ) ||             // Must be atleast one valid char after '.'
			(Space  != -1))                    // No empty spaces permitted
		   {  
			  flag = false
			  alert("Please enter a valid e-mail address!");
			  Temp.value="";
			  Temp.focus();
			  return flag;
		   }
		}
		}

   	//Phone
	x.Contact_Number.value = LTrim(x.Contact_Number.value);
	x.Contact_Number.value = RTrim(x.Contact_Number.value);
	if (!emptystring(x.Contact_Number.value))
		 {
			alert("Please enter your Contact Number");
			x.Contact_Number.focus();
			flag=false;
			return (false);
		} else {
           var checkOk = "0123456789 ";
			if (!(validate(x.Contact_Number.value,checkOk)))
				{
				alert("Please Enter the Valid Contact Number");
				x.Contact_Number.value= "";
				x.Contact_Number.focus();
				flag=false;
				return (false);
				}
		}
						
		
	//address
	x.Address.value = LTrim(x.Address.value);
	x.Address.value = RTrim(x.Address.value);
	if (!emptystring(x.Address.value))
		 {
			alert("Please enter your Mailing Address");
			x.Address.focus();
			flag=false;
			return (false);
		}
	
	//address
	x.City.value = LTrim(x.City.value);
	x.City.value = RTrim(x.City.value);
	if (!emptystring(x.City.value))
		 {
			alert("Please enter your City");
			x.City.focus();
			flag=false;
			return (false);
		}
		
  	//country
	x.Country.value = LTrim(x.Country.value);
	x.Country.value = RTrim(x.Country.value);
	if (!emptystring(x.Country.value))
		 {
			alert("Please enter your Country");
			x.Country.focus();
			flag=false;
			return (false);
		}
		
	//Mostrecent_employer
	x.Mostrecent_employer.value = LTrim(x.Mostrecent_employer.value);
	x.Mostrecent_employer.value = RTrim(x.Mostrecent_employer.value);
	if (!emptystring(x.Mostrecent_employer.value))
		 {
			alert("Please enter your Most recent employee");
			x.Mostrecent_employer.focus();
			flag=false;
			return (false);
		}
		
	//Mostrecent_jobtitle
	x.Mostrecent_jobtitle.value = LTrim(x.Mostrecent_jobtitle.value);
	x.Mostrecent_jobtitle.value = RTrim(x.Mostrecent_jobtitle.value);
	if (!emptystring(x.Mostrecent_jobtitle.value))
		 {
			alert("Please enter your Most recent Jobtitle");
			x.Mostrecent_jobtitle.focus();
			flag=false;
			return (false);
		}
		
	//major_area_study
	x.Major_area_study.value = LTrim(x.Major_area_study.value);
	x.Major_area_study.value = RTrim(x.Major_area_study.value);
	if (!emptystring(x.Major_area_study.value))
		 {
			alert("Please enter your Major area of study");
			x.Major_area_study.focus();
			flag=false;
			return (false);
		}
		
	   	//Phone
	x.Salary.value = LTrim(x.Salary.value);
	x.Salary.value = RTrim(x.Salary.value);
	if (!emptystring(x.Salary.value))
		 {
			alert("Please enter your Minimum Salary Expectation");
			x.Salary.focus();
			flag=false;
			return (false);
		} else {
           var checkOk = "0123456789 ,/-Rs";
			if (!(validate(x.Salary.value,checkOk)))
				{
				alert("Please Enter the Salary in Number");
				x.Salary.value= "";
				x.Salary.focus();
				flag=false;
				return (false);
				}
		}

   	//preferred_location
	x.Preferred_location.value = LTrim(x.Preferred_location.value);
	x.Preferred_location.value = RTrim(x.Preferred_location.value);
	if (!emptystring(x.Preferred_location.value))
		 {
			alert("Please enter your Preferred Location");
			x.Preferred_location.focus();
			flag=false;
			return (false);
		}

	//Set this return value to true when you want to submit the form
	return (flag);
}

function trim(String)
{
   if (String == null)
   {   
   	return (false);
   }
   return String.replace(/(^\s+)|(\s+$)/g,"");
}


function removeText(obj,text)
{
	fieldObj=eval("document.form1."+obj.id);
	if (trim(fieldObj.value)==text) fieldObj.value='';
}

function checkEmpty(obj,text)
{
	fieldObj=eval("document.form1."+obj.id);
	if (trim(fieldObj.value)=="") fieldObj.value=text;
}


function zipvalidation() {
	var zip = document.form.zip.value;
	if(isNaN(zip)) {
		alert("Please enter valid zipcode number");
		document.form.zip.value="";
		document.form.zip.focus();
	}
}

function conformmailid() {
	var email = document.form.email.value;
	var cemail = document.form.cEmail.value;
	
	if (email != cemail)
		 {
			alert("Email mismatching....");
			document.form.email.value="";
			document.form.cEmail.value="";
			document.form.cEmail.focus();
		}
}

function phonevalidation() {
	var phone = document.form.phone.value;
	if(isNaN(phone)) {
		alert("Please enter valid phone number");
		document.form.phone.value="";
		document.form.phone.focus();
	}
}


