function trimString(str)
{
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function isCharsInBag (s, bag)
{  
    var i;
    for (i = 0; i < s.length; i++)
    {   
       
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return false;
    }
    return true;
}

//Email validation Start
function echeck(es){
  var v,s,s1;
  v=es;
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v)){
     s=v.split("@")
     //alert(s.length);
     if(s.length > 2 ){
		alert("Please enter valid  Email Address");
		return false;
      }    
      s1=s[0];
      for(i=0 ; i<s1.length ; i++){
	    c=s1.charAt(i);		
	   	if( ! ( (c >='0' && c <='9') || (c >='a' && c <='z')||(c>='A' && c<='Z') || ( c =='_' || c=='-'  || c=='.') ) ){  
		  alert("E-mail id should not contain any special character. Please enter valid Email id");
		  alert(c);
		  return false;
		}
	  }
      s1=s[1];
      for(i=0 ; i<s1.length ; i++){
	    c=s1.charAt(i);		
	   	if( ! ( (c >='0' && c <='9') || (c >='a' && c <='z')||(c>='A' && c<='Z') || ( c =='_' || c=='-' ||c== ' ' || c=='.') ) ){  
		  alert("E-mail id should not contain any special character Please Enter Valid Email id ");	 
		  return false;
		}
	 }
	 s=s1.split("."); 
     len=s.length;
     if(len > 3 ){
      alert(" Please enter valid  E-mail Address");     
      return false;
     }
     l=s[1];
     for(k=2;k<s.length;k++){     
       if(l==s[k]){
			alert(" Please enter valid E-mail Address");     
			return false;
       }
     }    
      
   //alert("valid E_mail address");
   return (true)
 }
	alert("Please enter valid E-mail Address")
	return (false);   

}
//Email validation End

function checkForm(f){
       	//Registration Form validation Start....
        if (trimString(f.txtname.value) == "") {
				alert("Please enter Name.");
				f.txtname.focus();
				return (false);
		}
		if (!isCharsInBag(f.txtname.value, "_-. abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )){
				alert("Your Name should be in characters" );
				f.txtname.focus();
				return(false);
		}
		if (trimString(f.txtcontperson.value) == "") {
				alert("Please enter Contact Person.");
				f.txtcontperson.focus();
				return (false);
    	}

		if (trimString(f.txtdesig.value) == "") {
			alert("Please enter Designation.");
			f.txtdesig.focus();
			return (false);
		}
		if (trimString(f.txtemail.value)==""){
				alert("Please Enter your email address:")
				f.txtemail.focus();
				return false;
       }
	    var   x=f.txtemail.value;
		   if(  echeck(x))
		   {
		   //return true;
		   }
		   else{ 
			   f.txtemail.focus();
			   return false;			  
		   }	 	
	   
		if (trimString(f.txtjobtitle.value) == "") {
			alert("Please enter Job Title.");
			f.txtjobtitle.focus();
			return (false);
		}
		if (trimString(f.txtqual.value) == "") {
			alert("Please enter Qualification.");
			f.txtqual.focus();
			return (false);
		}
		if (trimString(f.SltExperience.value) == "-1") {
			alert("Please select Relevant years of experience.");
			f.SltExperience.focus();
			return (false);
		}
		if (trimString(f.txtskillreq.value) == "") {
			alert("Please enter Skills Required.");
			f.txtskillreq.focus();
			return (false);
		}		
		if (trimString(f.txtjobdesc.value) == "") {
				alert("Please enter Job Description.");
				f.txtjobdesc.focus();
				return (false);
	    }
		if (trimString(f.txtindustry.value) == "") {
				alert("Please enter Industry Preference.");
				f.txtindustry.focus();
				return (false);
	    }
		if (trimString(f.txtage.value) == "") {
			alert("Please enter Age.");
			f.txtage.focus();
			return (false);
		}
		if (isNaN(f.txtage.value)){
				alert ("Please enter only numbers for Age.");
				f.txtage.focus();
				return (false);
	   }

		if (trimString(f.txtlocation.value) == "") {
				alert("Please enter Location.");
				f.txtlocation.focus();
				return (false);
	    }
		if (trimString(f.txtterm.value) == "") {
				alert("Please enter Term.");
				f.txtterm.focus();
				return (false);
	    }

		if (trimString(f.txtworkhrs.value) == "") {
			alert("Please enter No. of working hours per day.");
			f.txtworkhrs.focus();
			return (false);
		}
		
		if (trimString(f.txtteamsize.value) == "") {
			alert("Please enter Team Size.");
			f.txtteamsize.focus();
			return (false);
		}
		if (isNaN(f.txtteamsize.value)){
				alert ("Please enter only numbers for Team size.");
				f.txtteamsize.focus();
				return (false);
	   }
	   
		
		if (trimString(f.txtrepto.value) == "" ){
			    alert("Please enter Reporting To details.");
				f.txtrepto.focus();
				return (false);
		}
		if (trimString(f.txtrepby.value) == "" ){
			    alert("Please enter Reporting By details.");
				f.txtrepby.focus();
				return (false);
		}
		
		
		
	   
}
