/*.....................................................................................................*/
//STUDY ABROAD VALIDATION
function StudyAbroadValidate(){
  
  var user_name		= trim(document.myform.user_name.value);
  //var gender		= trim(document.myform.gender.value);
  var phone			= trim(document.myform.phone.value);
  var mobile		= trim(document.myform.mobile.value);
  var fax			= trim(document.myform.fax.value);
  var email			= trim(document.myform.email.value);
  var address		= trim(document.myform.address.value);
  var city			= trim(document.myform.city.value);
  var country		= trim(document.myform.country.value);
  var dob_date		= trim(document.myform.dob_date.value);
  var dob_month		= trim(document.myform.dob_month.value);
  var dob_year		= trim(document.myform.dob_year.value);
  var enq_matter	= trim(document.myform.enq_matter.value);
  var country_study	= trim(document.myform.country_study.value);
  var subject		= trim(document.myform.subject.value);
  var edu_qualif	= trim(document.myform.edu_qualif.value);
  var year			= trim(document.myform.year.value);
  var soure_of_fund	= trim(document.myform.soure_of_fund.value);
  var info			= trim(document.myform.info.value);
  var upload_resume	= trim(document.myform.upload_resume.value);
  
  if(user_name == ""){
    alert("Username should not be Empty");
    document.myform.user_name.focus();
    return false;
  }
  if(mobile == ""){
    alert("Mobile should not be Empty");
    document.myform.mobile.focus();
    return false;
  }
  if(email == ""){
    alert("Email-ID should not be Empty");
    document.myform.email.focus();
    return false;
  }
  if(document.myform.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.myform.email.focus();
	return false;
  }
  if(address == ""){
    alert("Address should not be Empty");
    document.myform.address.focus();
    return false;
  }
  if(city == ""){
    alert("City should not be Empty");
    document.myform.city.focus();
    return false;
  }
  if(country == ""){
    alert("Country should not be Empty");
    document.myform.country.focus();
    return false;
  }
  if(dob_date == ""){
    alert("Birth Date should not be Empty");
    document.myform.dob_date.focus();
    return false;
  }
  if(dob_month == ""){
    alert("Birth Month should not be Empty");
    document.myform.dob_month.focus();
    return false;
  }
  if(dob_year == ""){
    alert("Birth Year should not be Empty");
    document.myform.dob_year.focus();
    return false;
  }
  if(enq_matter == ""){
    alert("Enquiry Matter should not be Empty");
    document.myform.enq_matter.focus();
    return false;
  }
  if(country_study == ""){
    alert("Country preferred to study should not be Empty");
    document.myform.country_study.focus();
    return false;
  }
  if(subject == ""){
    alert("Course /  Subject should not be Empty");
    document.myform.subject.focus();
    return false;
  }
  if(edu_qualif == ""){
    alert("Educational Qualification should not be Empty");
    document.myform.edu_qualif.focus();
    return false;
  }
  if(upload_resume == ""){
    alert("Upload your CV should not be Empty");
    document.myform.upload_resume.focus();
    return false;
  }
}
/*.....................................................................................................*/
//JOB SEEKER VALIDATION
function JobSeekerValidate(){
  
  var user_name			= trim(document.myform.user_name.value);
  //var dob				= trim(document.myform.dob.value);
  //var address			= trim(document.myform.address.value);
  //var phone				= trim(document.myform.phone.value);
  var mobile			= trim(document.myform.mobile.value);
  var email				= trim(document.myform.email.value);
  //var position_desired	= trim(document.myform.position_desired.value);
  // edu_qualif		= trim(document.myform.edu_qualif.value);
  //var prof_qualif		= trim(document.myform.prof_qualif.value);
  //var primary_skill		= trim(document.myform.primary_skill.value);
  //var work_exp			= trim(document.myform.work_exp.value);
  var upload_resume		= trim(document.myform.upload_resume.value);
  
  if(user_name == ""){
    alert("Username should not be Empty");
    document.myform.user_name.focus();
    return false;
  }
  /*if(dob == ""){
    alert("Date of Birth should not be Empty");
    document.myform.dob.focus();
    return false;
  }
  if(address == ""){
    alert("Address should not be Empty");
    document.myform.address.focus();
    return false;
  }
  if(phone == ""){
    alert("Telephone should not be Empty");
    document.myform.phone.focus();
    return false;
  }*/
  if(mobile == ""){
    alert("Mobile should not be Empty");
    document.myform.mobile.focus();
    return false;
  }
  if(email == ""){
    alert("Email-ID should not be Empty");
    document.myform.email.focus();
    return false;
  }
  if(document.myform.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.myform.email.focus();
	return false;
  }
  /*if(position_desired == ""){
    alert("Position Desired should not be Empty");
    document.myform.position_desired.focus();
    return false;
  }
  if(edu_qualif == ""){
    alert("Educational Qualification should not be Empty");
    document.myform.edu_qualif.focus();
    return false;
  }
  if(prof_qualif == ""){
    alert("Professional Qualification should not be Empty");
    document.myform.prof_qualif.focus();
    return false;
  }
  if(primary_skill == ""){
    alert("Primary Skill should not be Empty");
    document.myform.primary_skill.focus();
    return false;
  }
  if(work_exp == ""){
    alert("Work Experience should not be Empty");
    document.myform.work_exp.focus();
    return false;
  }*/
  if(upload_resume == ""){
    alert("Upload your CV should not be Empty");
    document.myform.upload_resume.focus();
    return false;
  }
}
/*.....................................................................................................*/
//EMPLOYER VALIDATION
function EmployerValidate(){
  
  var job_title		= trim(document.myform.job_title.value);
  var job_desc		= trim(document.myform.job_desc.value);
  var no_of_vacant	= trim(document.myform.no_of_vacant.value);
  var area_exp		= trim(document.myform.area_exp.value);
  var exp_req_min	= trim(document.myform.exp_req_min.value);
  var exp_req_max	= trim(document.myform.exp_req_max.value);
  var skill_set		= trim(document.myform.skill_set.value);
  var qualif_req	= trim(document.myform.qualif_req.value);
  var job_country	= trim(document.myform.job_country.value);
  var job_city		= trim(document.myform.job_city.value);
  var phone			= trim(document.myform.phone.value);
  var email			= trim(document.myform.email.value);
  
  if(job_title == ""){
    alert("Job Title should not be Empty");
    document.myform.job_title.focus();
    return false;
  }
  if(job_desc == ""){
    alert("Job Description should not be Empty");
    document.myform.job_desc.focus();
    return false;
  }
  if(no_of_vacant == ""){
    alert("No. of Vacancies should not be Empty");
    document.myform.no_of_vacant.focus();
    return false;
  }
  if(area_exp == "0"){
    alert("Area of Experience should not be Empty");
    document.myform.area_exp.focus();
    return false;
  }
  if(exp_req_min == "0"){
    alert("Minimum Experience Required should not be Empty");
    document.myform.exp_req_min.focus();
    return false;
  }
  if(exp_req_max == "0"){
    alert("Maximum Experience Required should not be Empty");
    document.myform.exp_req_max.focus();
    return false;
  }
  if(skill_set == "0"){
    alert("Skill set should not be Empty");
    document.myform.skill_set.focus();
    return false;
  }
  if(qualif_req == "0"){
    alert("Qualification Required should not be Empty");
    document.myform.qualif_req.focus();
    return false;
  }
  if(job_country == "0"){
    alert("Job Country should not be Empty");
    document.myform.job_country.focus();
    return false;
  }
  if(job_city == "0"){
    alert("Job City should not be Empty");
    document.myform.job_city.focus();
    return false;
  }
  
  if(phone != ""){
   if(isDigits(phone)==false){
     alert("Phone no should be in number");
     document.myform.phone.value="";
     document.myform.phone.focus();
     return false;
   }
  }
  if(email != ""){
    if(document.myform.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.myform.email.focus();
	  return false;
   }
  }
}
/*.....................................................................................................*/
//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;
  }
}
/*.....................................................................................................*/
//ENQUIRY VALIDATION
function EnquiryValidate(){
  
  var user_name		= trim(document.myform.user_name.value);
  var phone			= trim(document.myform.phone.value);
  var email			= trim(document.myform.email.value);
  var company_name	= trim(document.myform.company_name.value);
  var designation	= trim(document.myform.designation.value);
  var hiring_req	= trim(document.myform.hiring_req.value);
  
  if(user_name == ""){
    alert("Conatct Person should not be Empty");
    document.myform.user_name.focus();
    return false;
  }
  if(phone == ""){
    alert("Phone no should not be Empty");
    document.myform.phone.focus();
    return false;
  }
  else if(isDigits(phone)==false){
   alert("Phone no should be in number");
   document.myform.phone.value="";
   document.myform.phone.focus();
   return false;
  }
  if(email == ""){
    alert("Email should not be Empty");
    document.myform.email.focus();
    return false;
  }
  if(document.myform.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.myform.email.focus();
	return false;
  }
  if(company_name == ""){
    alert("Company Name should not be Empty");
    document.myform.company_name.focus();
    return false;
  }
  if(designation == ""){
    alert("Designation should not be Empty");
    document.myform.designation.focus();
    return false;
  }
  if(hiring_req == "0"){
    alert("Hiring Requirement should not be Empty");
    document.myform.hiring_req.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;
}