/*.....................................................................................................*/
//APPLY JOB VALIDATION
function ApplyJobValidate()
{
  var username	= trim(document.frm1.username.value);
  var age		= trim(document.frm1.age.value);
  //var gender	= trim(document.frm1.gender.value);
  var email		= trim(document.frm1.email.value);
  var address	= trim(document.frm1.address.value);
  var phone		= trim(document.frm1.phone.value);
  var applied_for= trim(document.frm1.applied_for.value);
  var qualif	= trim(document.frm1.qualif.value);
  var cur_design= trim(document.frm1.cur_design.value);
  var cur_sal	= trim(document.frm1.cur_sal.value);
  var exp_sal	= trim(document.frm1.exp_sal.value);
  var resume_name= trim(document.frm1.resume_name.value);
  
  if(username == "")
  {
    alert("Username should not be Empty");
    document.frm1.username.focus();
    return false;
  }
  if(age == "")
  {
    alert("Age should not be Empty");
    document.frm1.age.focus();
    return false;
  }
  else if(isDigits(age)==false)
  {
   alert("Age should be in number");
   document.frm1.age.focus();
   return false;
  }
  /*if(gender == "")
  {
    alert("Gender should not be Empty");
    document.frm1.gender.focus();
    return false;
  }*/
  if(email == "")
  {
    alert("Email should not be Empty");
    document.frm1.email.focus();
    return false;
  }
  if(document.frm1.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
	alert("Please Enter valid Email Address")
	document.frm1.email.focus();
	return false;
  }
  if(address == "")
  {
    alert("Address should not be Empty");
    document.frm1.address.focus();
    return false;
  }
  if(phone == "")
  {
    alert("Phone no should not be Empty");
    document.frm1.phone.focus();
    return false;
  }
  else if(isDigits(phone)==false)
  {
   alert("Phone no should be in number");
   document.frm1.phone.focus();
   return false;
  }
  if(applied_for == "")
  {
    alert("Applied posting should not be Empty");
    document.frm1.applied_for.focus();
    return false;
  }
  if(qualif == "")
  {
    alert("Qualification should not be Empty");
    document.frm1.qualif.focus();
    return false;
  }
  if(cur_design == "")
  {
    alert("Current Designation should not be Empty");
    document.frm1.cur_design.focus();
    return false;
  }
  if(cur_sal == "")
  {
    alert("Current Salary(CTS) should not be Empty");
    document.frm1.cur_sal.focus();
    return false;
  }
  if(exp_sal == "")
  {
    alert("Expected Salary(ETS) should not be Empty");
    document.frm1.exp_sal.focus();
    return false;
  }
  if(resume_name == "")
  {
    alert("Please upload your resume");
    document.frm1.resume_name.focus();
    return false;
  }
}
/*.....................................................................................................*/
//CAREERS VALIDATION
function CareersValidate()
{
  var username	= trim(document.frm1.username.value);
  var age		= trim(document.frm1.age.value);
  //var gender	= trim(document.frm1.gender.value);
  var email		= trim(document.frm1.email.value);
  var address	= trim(document.frm1.address.value);
  var phone		= trim(document.frm1.phone.value);
  var applied_for= trim(document.frm1.applied_for.value);
  var qualif	= trim(document.frm1.qualif.value);
  var cur_design= trim(document.frm1.cur_design.value);
  var cur_sal	= trim(document.frm1.cur_sal.value);
  var exp_sal	= trim(document.frm1.exp_sal.value);
  //var resume_name= trim(document.frm1.resume_name.value);
  
  if(username == "")
  {
    alert("Username should not be Empty");
    document.frm1.username.focus();
    return false;
  }
  if(age == "")
  {
    alert("Age should not be Empty");
    document.frm1.age.focus();
    return false;
  }
  else if(isDigits(age)==false)
  {
   alert("Age should be in number");
   document.frm1.age.focus();
   return false;
  }
  /*if(gender == "")
  {
    alert("Gender should not be Empty");
    document.frm1.gender.focus();
    return false;
  }*/
  if(email == "")
  {
    alert("Email should not be Empty");
    document.frm1.email.focus();
    return false;
  }
  if(document.frm1.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
	alert("Please Enter valid Email Address")
	document.frm1.email.focus();
	return false;
  }
  if(address == "")
  {
    alert("Address should not be Empty");
    document.frm1.address.focus();
    return false;
  }
  if(phone == "")
  {
    alert("Phone no should not be Empty");
    document.frm1.phone.focus();
    return false;
  }
  else if(isDigits(phone)==false)
  {
   alert("Phone no should be in number");
   document.frm1.phone.focus();
   return false;
  }
  if(applied_for == "")
  {
    alert("Applied posting should not be Empty");
    document.frm1.applied_for.focus();
    return false;
  }
  if(qualif == "")
  {
    alert("Qualification should not be Empty");
    document.frm1.qualif.focus();
    return false;
  }
  if(cur_design == "")
  {
    alert("Current Designation should not be Empty");
    document.frm1.cur_design.focus();
    return false;
  }
  if(cur_sal == "")
  {
    alert("Current Salary(CTS) should not be Empty");
    document.frm1.cur_sal.focus();
    return false;
  }
  if(exp_sal == "")
  {
    alert("Expected Salary(ETS) should not be Empty");
    document.frm1.exp_sal.focus();
    return false;
  }
  /*if(resume_name == "")
  {
    alert("Please upload your resume");
    document.frm1.resume_name.focus();
    return false;
  }*/
}
/*.....................................................................................................*/
//HELP LINE VALIDATION
function HelplineValidate()
{
  var username		= trim(document.helpfrm.username.value);
  var phone			= trim(document.helpfrm.phone.value);
  var email			= trim(document.helpfrm.email.value);
  
  var subject		= trim(document.helpfrm.subject.value);
  var other_subject	= trim(document.helpfrm.other_subject.value);
  var message		= trim(document.helpfrm.message.value);
  
  if(username == "")
  {
    alert("Username should not be Empty");
    document.helpfrm.username.focus();
    return false;
  }
  if(phone == "")
  {
    alert("Phone should not be Empty");
    document.helpfrm.phone.focus();
    return false;
  }
  else if(isDigits(phone)==false)
  {
   alert("Phone should be in number");
   document.helpfrm.phone.focus();
   return false;
  }
  if(email == "")
  {
    alert("Email should not be Empty");
    document.helpfrm.email.focus();
    return false;
  }
  else if(document.helpfrm.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
	alert("Please enter valid Email Address")
	document.helpfrm.email.focus();
	return false;
  }
  
  if(subject == "0")
  {
    alert("Subject should not be Empty");
    document.helpfrm.subject.focus();
    return false;
  }
  if(subject == "-1")
  {
	  	if(other_subject == "")
	  	{
	    	alert("Other Subject should not be Empty");
	    	document.helpfrm.other_subject.focus();
	    	return false;
	  	}
  }
  if(message == "")
  {
    alert("Message should not be Empty");
    document.helpfrm.message.focus();
    return false;
  }
}
/*.....................................................................................................*/
//LOGIN VALIDATION
function LoginValidate()
{
  var username	= trim(document.loginfrm.username.value);
  var password	= trim(document.loginfrm.password.value);
  
  if(username == "")
  {
    alert("Username should not be Empty");
    document.loginfrm.username.focus();
    return false;
  }
  if(password == "")
  {
    alert("Password should not be Empty");
    document.loginfrm.password.focus();
    return false;
  }
}
/*.....................................................................................................*/
//REGISTER VALIDATION
function RegisterValidate()
{
  var username	= trim(document.regfrm.username.value);
  var password	= trim(document.regfrm.password.value);
  var email		= trim(document.regfrm.email.value);
  var phone		= trim(document.regfrm.phone.value);
  var qualif	= trim(document.regfrm.qualif.value);
  var edu_spec	= trim(document.regfrm.edu_spec.value);
  var yr_passout= trim(document.regfrm.yr_passout.value);
  var skillset	= trim(document.regfrm.skillset.value);
  var yr_exp	= trim(document.regfrm.yr_exp.value);
  
  var other_qualif	= trim(document.regfrm.other_qualif.value);
  var other_edu_spec	= trim(document.regfrm.other_edu_spec.value);
  var other_skillset	= trim(document.regfrm.other_skillset.value);
  
  if(username == "")
  {
    alert("Username should not be Empty");
    document.regfrm.username.focus();
    return false;
  }
  if(password == "")
  {
    alert("Password should not be Empty");
    document.regfrm.password.focus();
    return false;
  }
  if(email == "")
  {
    alert("Email should not be Empty");
    document.regfrm.email.focus();
    return false;
  }
  else if(document.regfrm.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
	alert("Please enter valid Email Address")
	document.regfrm.email.focus();
	return false;
  }
  if(phone == "")
  {
    alert("Phone should not be Empty");
    document.regfrm.phone.focus();
    return false;
  }
  else if(isDigits(phone)==false)
  {
   alert("Phone should be in number");
   document.regfrm.phone.focus();
   return false;
  }
  if(qualif == "0")
  {
    alert("Qualification should not be Empty");
    document.regfrm.qualif.focus();
    return false;
  }
  if(qualif == "-1")
  {
	  	if(other_qualif == "")
	  	{
	    	alert("Other Qualification should not be Empty");
	    	document.regfrm.other_qualif.focus();
	    	return false;
	  	}
  }
  if(edu_spec == "0")
  {
    alert("Educational Specification should not be Empty");
    document.regfrm.edu_spec.focus();
    return false;
  }
  if(edu_spec == "-1")
  {
	  	if(other_edu_spec == "")
	  	{
	    	alert("Other Educational Specification should not be Empty");
	    	document.regfrm.other_edu_spec.focus();
	    	return false;
	  	}
  }
  if(yr_passout == "0")
  {
    alert("Year of Passout should not be Empty");
    document.regfrm.yr_passout.focus();
    return false;
  }
  if(skillset == "")
  {
    alert("Skillset should not be Empty");
    document.regfrm.skillset.focus();
    return false;
  }
  if(skillset == "-1")
  {
	  	if(other_skillset == "")
	  	{
	    	alert("Other Skillset should not be Empty");
	    	document.regfrm.other_skillset.focus();
	    	return false;
	  	}
  }
  if(yr_exp == "0")
  {
    alert("Year of Experience should not be Empty");
    document.regfrm.yr_exp.focus();
    return false;
  }
}


/*.....................................................................................................*/
//COMMON METHOD
/*.....................................................................................................*/

//Trim
function trim(s) {
    return s.replace( /^\\s*/, "" ).replace( /\\s*$/, "" );
}

//EMAIL VALIDATION
function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID");
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID");
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID");
		return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID");
		return false;
	 }		
	 if (str.indexOf(" ")!=-1){
		alert("Please Enter a Valid E-mail ID");
		return false;
	 }
				
}

//DIGIT VALIDATION
function isDigits(argvalue) {
    argvalue = argvalue.toString();
    var validChars = "0123456789";
    var startFrom = 0;
    if (argvalue.substring(0, 2) == "0x") {
       validChars = "0123456789abcdefABCDEF";
       startFrom = 2;
    } else if (argvalue.charAt(0) == "0") {
       validChars = "01234567";
       startFrom = 1;
    }
    for (var n = 0; n < argvalue.length; n++) {
        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
    }
  return true;
}