/*........................................................................ .............................*/
//CONTACT US VALIDATION
function ContactValidate(theform){	

  var email			= trim(theform.email.value);
  var subject		= trim(theform.subject.value);
  var verify_code	= trim(theform.verify_code.value);
  var message		= trim(theform.message.value);
  
  if(email == ""){
    alert("Please enter Email");
    theform.email.focus();
    return false;
  }
  if(email != ""){
	  if(theform.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
		alert("Please Enter valid Email Address");
		theform.email.focus();
		return false;
	  }
  }
  if(subject == ""){
    alert("Please enter Subject");
    theform.subject.focus();
    return false;
  }
  if(verify_code == ""){
    alert("Please enter Verification code");
    theform.verify_code.focus();
    return false;
  }
  if(message == ""){
    alert("Please enter Message");
    theform.message.focus();
    return false;
  }
}
/*.....................................................................................................*/
//REGISTER VALIDATION
function RegisterValidate(theform)
{
  var user_name		= trim(theform.user_name.value);
  var password		= trim(theform.password.value);
  var con_password	= trim(theform.con_password.value);
  
  var dob_date		= trim(theform.dob_date.value);
  var dob_month		= trim(theform.dob_month.value);
  var dob_year		= trim(theform.dob_year.value);
  
  var birth_hour	= trim(theform.birth_hour.value);
  var birth_min		= trim(theform.birth_min.value);
  var birth_sec		= trim(theform.birth_sec.value);
  var birth_type	= trim(theform.birth_type.value);
  
  var height		= trim(theform.height.value);
  var colour		= trim(theform.colour.value);
  
  var religion		= trim(theform.religion.value);
  var caste			= trim(theform.caste.value);
  var other_caste	= trim(theform.other_caste.value);
  
  /*var phys_handicap	= trim(theform.phys_handicap.value);*/
  /*var handicap_desc	= trim(theform.handicap_desc.value);*/
  
  var qualif		= trim(theform.qualif.value);
  var occu			= trim(theform.occu.value);
  /*var occu_sec		= trim(theform.occu_sec.value);*/
  var mon_income	= trim(theform.mon_income.value);
  
  var father_name	= trim(theform.father_name.value);
  var mother_name	= trim(theform.mother_name.value);
  
  var birth_order	= trim(theform.birth_order.value);
  var bro_tot		= trim(theform.bro_tot.value);
  var bro_mar		= trim(theform.bro_mar.value);
  var bro_unmar		= trim(theform.bro_unmar.value);
  var sis_tot		= trim(theform.sis_tot.value);
  var sis_mar		= trim(theform.sis_mar.value);
  var sis_ummar		= trim(theform.sis_ummar.value);
  //var house_type	= trim(theform.house_type.value);
  
  var country		= trim(theform.country.value);
  var state			= trim(theform.state.value);
  var city			= trim(theform.city.value);
  
  var con_address	= trim(theform.con_address.value);
  var mobile		= trim(theform.mobile.value);
  var email			= trim(theform.email.value);
  
  var about_partner	= trim(theform.about_partner.value);
  
  var star			= trim(theform.star.value);
  var rasi			= trim(theform.rasi.value);
  
  var raghu			= trim(theform.raghu.value);
  var chevvai		= trim(theform.chevvai.value);
  var magadasa		= trim(theform.magadasa.value);
  var magadasa_yrs	= trim(theform.magadasa_yrs.value);
  var magadasa_mons	= trim(theform.magadasa_mons.value);
  var magadasa_days	= trim(theform.magadasa_days.value);
  
  var agree			= trim(theform.agree.value); 
  
  if(user_name == ""){
    alert("Please enter Username");
    theform.user_name.focus();
    return false;
  }
  if(password == ""){
    alert("Please enter Password");
    theform.password.focus();
    return false;
  }
  if(con_password == ""){
    alert("Please enter Confirm password");
    theform.con_password.focus();
    return false;
  }
  if(password != con_password){
		alert("Password Mismatch! Please Retype Correct Password");
		theform.con_password.focus();
		theform.con_password.select();
		return false;
  }	
  if(theform.gender[0].checked == false && theform.gender[1].checked == false){
		alert("Please select gender");
		theform.gender[0].focus();
		return false;
  }	
	if(theform.dob_date.options[theform.dob_date.selectedIndex].value == ""){
		alert("Please select your date of birth");
		theform.dob_date.focus();
		return false;
	}
	if(theform.dob_month.options[theform.dob_month.selectedIndex].value == ""){
		alert("Please select your date of birth");
		theform.dob_month.focus();
		return false;
	}
	if(theform.dob_year.options[theform.dob_year.selectedIndex].value == ""){
		alert("Please select your date of birth");
		theform.dob_year.focus();
		return false;
	}
  if(birth_hour == ""){
    alert("Birth Hour should not be Empty");
    theform.birth_hour.focus();
    return false;
  }
  if(birth_min == ""){
    alert("Birth Min should not be Empty");
    theform.birth_min.focus();
    return false;
  }
  if(birth_sec == ""){
    alert("Birth Sec should not be Empty");
    theform.birth_sec.focus();
    return false;
  }
  if(birth_type == ""){
    alert("Please select Am / PM");
    theform.birth_type.focus();
    return false;
  }
  
  if(height == ""){
    alert("Please select Height");
    theform.height.focus();
    return false;
  }
  if(colour == ""){
    alert("Please select Colour");
    theform.colour.focus();
    return false;
  }
  
  if(religion == ""){
    alert("Please select Religion");
    theform.religion.focus();
    return false;
  }
  if(caste == ""){
    alert("Please select Caste");
    theform.caste.focus();
    return false;
  }
  if(caste == "138"){
	if(other_caste == ""){
	    alert("Please enter Other caste");
	    theform.other_caste.focus();
	    return false;
  	}
  }
  
  if(qualif == ""){
    alert("Please select Qualification");
    theform.qualif.focus();
    return false;
  }
  if(occu == ""){
    alert("Please select Occupation");
    theform.occu.focus();
    return false;
  }
  if(!theform.occu_sec[0].checked && !theform.occu_sec[1].checked && !theform.occu_sec[2].checked){
    alert("Please check Occupation Sector");
    theform.occu_sec.focus();
    return false;
  }
  if(mon_income == "0"){
    alert("Please select Monthly Income");
    theform.mon_income.focus();
    return false;
  }
  
  if(father_name == ""){
    alert("Please enter Father name");
    theform.father_name.focus();
    return false;
  }
  if(mother_name == ""){
    alert("Please enter Mother name");
    theform.mother_name.focus();
    return false;
  }
  if(birth_order == ""){
    alert("Please select Birth Order");
    theform.birth_order.focus();
    return false;
  }
  if(bro_tot == ""){
    alert("Please select total Brother");
    theform.bro_tot.focus();
    return false;
  }
  if(bro_mar == ""){
    alert("Please select total Brother");
    theform.bro_mar.focus();
    return false;
  }
  if(bro_unmar == ""){
    alert("Please select total Brother");
    theform.bro_unmar.focus();
    return false;
  }
  if(sis_tot == ""){
    alert("Please select total Sister");
    theform.sis_tot.focus();
    return false;
  }
  if(sis_mar == ""){
    alert("Please select total Sister");
    theform.sis_mar.focus();
    return false;
  }
  if(sis_ummar == ""){
    alert("Please select total Sister");
    theform.sis_ummar.focus();
    return false;
  }
  if(!theform.house_type[0].checked && !theform.house_type[1].checked){
    alert("Please check Living in");
    theform.house_type[0].focus();
    return false;
  }
  
  
  if(country == ""){
    alert("Please select Country");
    theform.country.focus();
    return false;
  }
  if(state == ""){
    alert("Please select State");
    theform.state.focus();
    return false;
  }
  if(city == ""){
    alert("Please enter City");
    theform.city.focus();
    return false;
  }
  if(con_address == ""){
    alert("Please enter Contact address");
    theform.con_address.focus();
    return false;
  }
  if(mobile == ""){
    alert("Please enter Phone no / Mobile");
    theform.phone.focus();
    return false;
  }
  else if((isDigits(mobile)==false)){
   alert("Mobile should be in number");
   theform.phone.focus();
   return false;
  }
  if(email != ""){
	  if(theform.email.value.search(/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)){
		alert("Please Enter valid Email Address")
		theform.email.focus();
		return false;
	  }
  }
  if(about_partner == ""){
    alert("Please enter Partner expectation");
    theform.about_partner.focus();
    return false;
  }
  if(star == ""){
    alert("Please select Star");
    theform.star.focus();
    return false;
  }
  if(rasi == ""){
    alert("Please select Rasi");
    theform.rasi.focus();
    return false;
  }
  if(raghu == ""){
    alert("Please select Lagnam to Raghu");
    theform.raghu.focus();
    return false;
  }
  if(chevvai == ""){
    alert("Please select Lagnam to Chevvai");
    theform.chevvai.focus();
    return false;
  }
  if(magadasa == ""){
    alert("Please enter Magadasa");
    theform.magadasa.focus();
    return false;
  }
  if(magadasa_yrs == ""){
    alert("Please enter Magadasa in yrs");
    theform.magadasa_yrs.focus();
    return false;
  }
  if(magadasa_mons == ""){
    alert("Please enter Magadasa in months");
    theform.magadasa_mons.focus();
    return false;
  }
  if(magadasa_days == ""){
    alert("Please enter Magadasa in days");
    theform.magadasa_days.focus();
    return false;
  }
  
  if(!theform.agree.checked)
  {
    alert("Please check the terms and conditions ");
    theform.agree.focus();
    return false;
  }
  
}
/*........................................................................ .............................*/
//LOGIN VALIDATION
function LoginValidate(theform){	

  var profileid		= trim(theform.profileid.value);
  var password		= trim(theform.password.value);

  if(profileid == ""){
    alert("Please enter Profile Id");
    theform.profileid.focus();
    return false;
  }
  if(password == ""){
    alert("Please enter Password");
    theform.password.focus();
    return false;
  }
}
/*........................................................................ .............................*/
//CHANGE PASSWORD VALIDATION
function chgpwdvalidate(){
	 
  var oldpass		= trim(document.chgpwdfrm.oldpass.value);
  var newpass		= trim(document.chgpwdfrm.newpass.value);
  var confirmpass	= trim(document.chgpwdfrm.confirmpass.value);

  if(oldpass == "")
  {
    alert("Please enter Old Password");
    document.chgpwdfrm.oldpass.focus();
    return false;
  }
  if(newpass == ""){
    alert("Please enter New Password");
    document.chgpwdfrm.newpass.focus();
    return false;
  }
  if(confirmpass == ""){
    alert("Please enter Confirm Password");
    document.chgpwdfrm.confirmpass.focus();
    return false;
  }
}
/*.....................................................................................................*/
//FORGOT PWD VALIDATION
function forgetpwdvalidate()
{
  var email				= trim(document.forgetpwdfrm.email.value);

  if(email == "")
  {
    alert("Please enter Email");
    document.forgetpwdfrm.email.focus();
    return false;
  }
  if(document.forgetpwdfrm.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.forgetpwdfrm.email.focus();
	return false;
  }
}
/*.....................................................................................................*/
//QUICK SEARCH VALIDATION
function QuickSearchValidate(theform){
	
  var religion		= trim(theform.religion.value);
  var caste			= trim(theform.caste.value);

  if(religion == "0"){
    alert("Please select Religion");
    theform.religion.focus();
    return false;
  }
  if(caste == "0"){
    alert("Please select Community");
    theform.caste.focus();
    return false;
  }
}
/*.....................................................................................................*/
//QUICK SEARCH VALIDATION
function QuickSearchValidate1(theform){
	
  var religion		= trim(theform.religion.value);
  var caste			= trim(theform.caste.value);

  if(religion == "0"){
    alert("Please select Religion");
    theform.religion.focus();
    return false;
  }
  if(caste == "0"){
    alert("Please select Community");
    theform.caste.focus();
    return false;
  }
}
/*.....................................................................................................*/
//INSTANT SEARCH VALIDATION
function InstantSearchValidate()
{
  var profileid		= trim(document.insearchfrm.profileid.value);

  if(profileid == "")
  {
    alert("Please enter Profile Id");
    document.insearchfrm.profileid.focus();
    return false;
  }
}
/*.....................................................................................................*/
//ADVANCE SEARCH VALIDATION
function AdvanceSearchValidate()
{
  var religion		= trim(document.advancesearchfrm.religion.value);
  var caste			= trim(document.advancesearchfrm.caste.value);

  if(religion == "0")
  {
    alert("Religion should not be Empty");
    document.advancesearchfrm.religion.focus();
    return false;
  }
  if(caste == "0")
  {
    alert("Community should not be Empty");
    document.advancesearchfrm.caste.focus();
    return false;
  }
}
/*.....................................................................................................*/
//STAR SEARCH VALIDATION
function StarSearchValidate(theform){
	
  var star		= trim(theform.star.value);

  if(star == ""){
    alert("Please select star");
    theform.star.focus();
    return false;
  }
}
/*.....................................................................................................*/
//OCCUPATION SEARCH VALIDATION
function OccupSearchValidate(theform){
	
  var occu		= trim(theform.occu.value);

  if(occu == ""){
    alert("Please select Occupation");
    theform.occu.focus();
    return false;
  }
}
/*.....................................................................................................*/
//EDUCATION SEARCH VALIDATION
function EduSearchValidate(theform){
	
  var qualif		= trim(theform.qualif.value);

  if(qualif == ""){
    alert("Please select Qualification");
    theform.qualif.focus();
    return false;
  }
}
/*.....................................................................................................*/
//CITY SEARCH VALIDATION
function CitySearchValidate(theform){
	
  var city		= trim(theform.city.value);

  if(city == ""){
    alert("Please enter City");
    theform.city.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;
}
