// JavaScript Document
function validate_text(field,alerttxt)
{
	with(field)
	{
		if(value==null||value=="")
		{
			alert(alerttxt);
			return false;
		}
		else{return true;}
	}
}

function validate_gender(radio,radio2,alerttxt)
{
	if(!radio.checked && !radio2.checked)
	{
		alert(alerttxt);
		return false;
	}
	else {return true}
	
}

function validate_select1(field1,alerttxt)
{
	if(field1.selectedIndex<=0)
	{
		alert(alerttxt);
		return false;
	}
	else{return true;}
}

function validate_contact(field)
{
	with(field)
	{
		if(value==null||value=="")
		{
			return false;
		}
		else{return true;}
	}
}

function validated_contact(field1,field2,alerttxt)
{
	if(validate_contact(field1)==false && validate_contact(field2)==false)
	{
		alert(alerttxt)
		return false;
	}
	else{return true;}
}

function validate_email(field,alerttxt)
{
	with(field)
	{
		apos=value.indexOf("@")
		dotpos=value.indexOf(".")
		if(apos<1||dotpos-apos<2)
		{(alert(alerttxt));
		  return false; }
		  else
		  {return true;}
	}
}

function isCompleteDate(theElement, theName)
{
 // This function checks if the text entered in a field 
 // has the format MM/DD/YYYY. 
 // It also checks if the days and months are valid and
 // if the year is 1500 or later

 var objectName = theName;

 //---- since we need the same functionality for errors ----
 //---- we create a function to simplify error display  ----
 function showError(message)
 {
  alert(message);
  theElement.focus();
 }
 
 var date_regex = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
 
 var date_str = theElement.value;

 // ^ indicates start of expression
 // \d{1,2} - the \d means digits and {1,2} means 1 or 2 digits
 // $ indicates end f expression

 if (!date_regex.test(date_str)) 
 {
  showError(theElement.value + " is NOT a valid date");
  theElement.focus();
  return(false);
 }

 //---- separate the month, day and year ----
 var month = RegExp.$1;
 var day = RegExp.$2;
 var year = RegExp.$3;

 if (year < 1500)
 {
  showError(year + " is not a valid year");
  return(false);
 }

 if (month < 1 || month > 12)
 {
  showError(month + " is not a valid month");
  return(false);
 }

 if (day == 0)
 { 
  showError(day + " is not a valid day");
  return(false);
 }

 if ((month == 1 || month == 3 || month == 5 || month == 7 ||
    month == 8 || month == 10 || month == 12) && (day > 31))
 {
  showError(day + " is not a valid day for month " + month);
  return (false) ;
 }

 if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30))
 {
  showError(day + " is not a valid day for month " + month);
  return(false);
 } 

 if (month == 2)
 {
  //---- check for leap year -----
  if ((day > 28) && (year%4 != 0)) 
  {
   showError(day + " is not a valid day for month " + month 
         + " of year " + year);
   return(false);
  }

  if ((day > 29) && (year%4 == 0)) 
  {
    showError(day + " is not a valid day for month " + month 
         + " of year " + year);
    return(false);
  }

 }

 return(true);
}

function validate_form1(thisform)
{
	with(thisform)
	{
		if(validate_text(Name,"Please write your Full Name")==false)
		{Name.focus(); 
		Name.style.backgroundColor="#FFCC80";
		return false;}
		
		if(validate_gender(radio,radio2,"Please select Gender")==false)
		{radio.focus();
		radio.style.backgroundColor="#FFCC80";
		radio2.style.backgroundColor="#FFCC80";
		return false;}
		
		if(validate_select1(day,"Please select date")==false)
		{day.focus();
		return false;}
		
		if(validate_select1(month,"Please select Month")==false)
		{month.focus();
		return false;}
		
		if(validate_select1(year,"Please select year")==false)
		{year.focus();
		return false;}
		
		if(yes.checked)
		{
		if (validate_text(from_valid,"Please enter date ; Valid From: ")==false)
		{from_valid.focus();
		from_valid.style.backgroundColor="#FFCC80";
		return false;}
		else
		{isCompleteDate(from_valid,from_valid)}
		
		if (validate_text(to_valid,"Please enter date ; Valid To: ")==false)
		{to_valid.focus();
		to_valid.style.backgroundColor="#FFCC80";
		return false;}	
		else
		{isCompleteDate(to_valid,to_valid)}
		}
		
		if (validate_text(country,"Please enter country")==false)
		{country.focus();
		country.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(current_location,"Please enter current location")==false)
		{current_location.focus();
		current_location.style.backgroundColor="#FFCC80";
		return false;}		
		
		if (validate_text(permanent_address,"Please enter permanent address")==false)
		{permanent_address.focus();
		permanent_address.style.backgroundColor="#FFCC80";
		return false;}
		
		if(validated_contact(contact1,mobile,"Please specify at least one contact number")==false)
		{contact1.focus();
		contact1.style.backgroundColor="#FFCC80";
		mobile.style.backgroundColor="#FFCC80";
		return false;}
		
		if(validate_email(email,"Please enter a valid Email")==false)
		{
			email.focus();
			email.style.backgroundColor="#FFCC80";
			return false;}
	}	
	
}
	
function validate_form2(thisform)
{
	with(thisform)
	{
		if(validate_text(resume_headline,"Please write resume headline")==false)
		{resume_headline.focus(); 
		resume_headline.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(preffered_location,"Please enter preffered location")==false)
		{preffered_location.focus();
		preffered_location.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(experience_years,"Please enter experience in years")==false)
		{experience_years.focus();
		experience_years.style.backgroundColor="#FFCC80";
		return false;}		
		
		if (validate_text(experience_months,"Please enter experience in months")==false)
		{experience_months.focus();
		experience_months.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(functional_area,"Please enter functional area")==false)
		{functional_area.focus();
		functional_area.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(current_ctc,"Please enter current ctc")==false)
		{current_ctc.focus();
		current_ctc.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(expected_ctc,"Please enter expected ctc")==false)
		{expected_ctc.focus();
		expected_ctc.style.backgroundColor="#FFCC80";
		return false;}
		
		if (validate_text(key_skills,"Please enter key skills")==false)
		{key_skills.focus();
		key_skills.style.backgroundColor="#FFCC80";
		return false;}	
	
	
	}	
	
}

function validate_form3(thisform)
{
	with(thisform)
	{
		if(validate_text(basic_qualification,"Please write Education details")==false)
		{basic_qualification.focus(); 
		basic_qualification.style.backgroundColor="#FFCC80";
		return false;}
		
	}	
	
}