/*
   Written By : Rajiv Gonsalves
   Designation : Senior Programmer
*/

function validatetel(tel) {
ok = 0; 
for (i=0;i<tel.length;i++) {
   a = tel.substr(i,1);
   if (a != "0" && a != "1" && a != "2" && a != "3" && a != "4" && a != "5" && a != "6" && a != "7" && a != "8" && a != "9" && a != "-") {
   ok = 1;
   }
}
	if (ok == 0) { return false; }
	else { return true; }
}

function thebox(t,e)
{
  ok=0
  for (i=1;i<=e;i++)
	{
     boxer = eval("document.forms[0]."+t+i);
	 if (boxer.checked) { ok = 1  }
	}
	if (ok == 0) { return true; }
	else { return false; }
}

function multibox(thename)
{
ok=0
for (i=0;i<thename.length ;i++ )
{
	if (thename[i].selected) { ok =1 }
}
	if (ok == 0) { return true; }
	else { return false; }
}

function multibox1(thename)
{
j = 0
ok1 = 0
for (i=0;i<thename.length ;i++ )
{
	if (thename[i].selected) { 
		if (thename[i].text == "Any/No Preference") {ok1 = 1};	
		j++
    }

}

	if (ok1 == 1 && j > 1) { return true;}
	else { return false; }
}

function multibox5check(thename)
{
j = 0
for (i=0;i<thename.length;i++ )
{
	if (thename[i].selected) { 
		j++
    }

}

	if (j > 5) { return true; }
	else { return false; }
}


function isblank(s)  {
	if ((s == null) || (s == "")) return true;
	for(var i=0;i<s.length;i++)  {
	   var c = s.charAt(i);		
	   if((c != ' ') && (c != '\\n') && (c != '\\t')) return false;
        }
	return true;
}

function ischecked(val)
{
	ok = 0;
	for (var i=0;i<val.length;i++)
	{
		if (val[i].checked) {
			ok=1;}
	}
	if (ok == 0) { return true; }
	else { return false; }
}

function regform(f) {
    var msg = "";    
	var err = "";
	if (f.sex[f.sex.selectedIndex].text == f.sex[0].text) {err +="[] Please choose your sex.\n";}
 	if (isblank(f.username.value)) {err += "[] Enter your Username.\n";} 
	if (isblank(f.password.value)) {err +="[] Enter your Password.\n";}
    if (isblank(f.cpassword.value)) {err +="[] Confirm your Password.\n";}
    if (f.password.value != f.cpassword.value) {err +="[] Please re-enter your password.\n";}
    if (f.email.value != f.email1.value) {err +="[] Please re-enter your Email address.\n";}
	if (isblank(f.firstname.value)) {err += "[] Enter your First Name.\n";} 
	if (isblank(f.lastname.value))  {err +="[] Enter your Last Name.\n";} 
	if (f.dd[f.dd.selectedIndex].text == f.dd[0].text || f.mm[f.mm.selectedIndex].text == f.mm[0].text || f.yy[f.yy.selectedIndex].text == f.yy[0].text) {err +="[] Please choose a proper date of birth.\n";}
    var y = f.email.value.indexOf("\@");
  	var x = f.email.value.indexOf(".");
  	var z = y + 1;
  	if(y < 0 || x < 0 || x == z)  { err += "[] The email address is wrong.\n"; }
    if (f.resphone.value != '' && validatetel(f.resphone.value)) {err +="[] Enter a valid Residence Telephone number.\n";}
	if (f.offphone.value != '' && validatetel(f.offphone.value)) {err +="[] Enter a valid Office Telephone number.\n";}
    if (f.mobile.value != '' && validatetel(f.mobile.value)) {err +="[] Enter a valid Mobile number.\n";}
    if (isblank(f.resphone.value) && isblank(f.offphone.value) && isblank(f.mobile.value)  ) {err +="[] Enter a Contact number.\n";    }
	if (isblank(f.address.value))  {err +="[] Enter your Address.\n";} 
	if (isblank(f.pincode.value) || isNaN(f.pincode.value)) { err += "[] Enter a valid pincode\n"	}
	if ((f.city[f.city.selectedIndex].text == "Others" && isblank(f.other_city.value)) || (f.city[f.city.selectedIndex].text == f.city[0].text)) {err +="[] Please choose a city.\n";}
	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}

function updateform(f) {

    var msg = "";    
	var err = "";
	if (isblank(f.password.value)) {err +="[] Enter your Password.\n";}
    if (isblank(f.cpassword.value)) {err +="[] Confirm your Password.\n";}
    if (f.password.value != f.cpassword.value) {err +="[] Password do not match.\n";}
	if (isblank(f.firstname.value)) {err += "[] Enter your First Name.\n";} 
	if (isblank(f.lastname.value))  {err +="[] Enter your Last Name.\n";} 
	if (f.dd[f.dd.selectedIndex].text == f.dd[0].text || f.mm[f.mm.selectedIndex].text == f.mm[0].text || f.yy[f.yy.selectedIndex].text == f.yy[0].text) {err +="[] Please choose a proper date of birth.\n";}
    var y = f.email.value.indexOf("\@");
  	var x = f.email.value.indexOf(".");
  	var z = y + 1;
  	if(y < 0 || x < 0 || x == z)  { err += "[] The email address is wrong.\n"; }
    if (f.resphone.value != '' && validatetel(f.resphone.value)) {err +="[] Enter a valid Residence Telephone number.\n";}
	if (f.offphone.value != '' && validatetel(f.offphone.value)) {err +="[] Enter a valid Office Telephone number.\n";}
    if (f.mobile.value != '' && validatetel(f.mobile.value)) {err +="[] Enter a valid Mobile number.\n";}
    if (isblank(f.resphone.value) && isblank(f.offphone.value) && isblank(f.mobile.value)  ) {err +="[] Enter a Contact number.\n";    }
	if (isblank(f.address.value))  {err +="[] Enter your Address.\n";} 
	if (isblank(f.pincode.value) || isNaN(f.pincode.value)) { err += "[] Enter a valid pincode\n"	}
	if ((f.city[f.city.selectedIndex].text == "Others" && isblank(f.other_city.value))) {err +="[] Please choose a city.\n";}
	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}

function matri1(f) {
    var msg = "";    
	var err = "";
    if (f.height[f.height.selectedIndex].text == f.height[0].text) {err +="[] Please choose your height.\n";}
	if (f.body[f.body.selectedIndex].text == f.body[0].text) {err +="[] Please choose your body type.\n";}
	if (f.skin[f.skin.selectedIndex].text == f.skin[0].text) {err +="[] Please choose a Skin tone.\n";}
	if ((f.eye[f.eye.selectedIndex].text == f.eye[0].text)) {err +="[] Please choose a eye color.\n";}
	if ((f.hair[f.hair.selectedIndex].text == f.hair[0].text)) {err +="[] Please choose a type of hair.\n";}
	if (f.education[f.education.selectedIndex].text == f.education[0].text) {err +="[] Please choose your education.\n";}
	if (f.occupation[f.occupation.selectedIndex].text == f.occupation[0].text) {err +="[] Please choose your occupation.\n";}
    if (isblank(f.occdesc.value)) { err +="[] Please enter your occupation description.\n";  }
	if (f.income[f.income.selectedIndex].text == f.income[0].text){err +="[] Please choose your income.\n";}
	if ((f.religion[f.religion.selectedIndex].text == f.religion[0].text)) {err +="[] Please choose your religion.\n";}
	if ((f.caste[f.caste.selectedIndex].text == f.caste[0].text)) {err +="[] Please choose your caste.\n";}
	if ((f.community[f.community.selectedIndex].text == f.community[0].text)) {err +="[] Please choose your state of origin/community.\n";}
	if (isblank(f.bcountry.value))  {err +="[] Enter your country of birth.\n";} 
	if (isblank(f.bcity.value))  {err +="[] Enter your city of birth.\n";} 
	if (f.hours[f.hours.selectedIndex].text == f.hours[0].text || f.minute[f.minute.selectedIndex].text == f.minute[0].text ) {err +="[] Please choose proper Time of birth.\n";}
	if (isblank(f.family.value))	{ err +="[] Enter your family background.\n"; }
	if (f.pfilled[f.pfilled.selectedIndex].text == f.pfilled[0].text) {err +="[] Please choose by whom this form was filled.\n";}
	if (f.smoke[f.smoke.selectedIndex].text == f.smoke[0].text) {err +="[] Do you smoke.\n";}
	if (f.drink[f.drink.selectedIndex].text == f.drink[0].text) {err +="[] Do you drink.\n";}
	if (isblank(f.headline.value))	{ err +="[] Please enter your headline.\n"; }
	if (isblank(f.personaldesc.value))	{ err +="[] Enter your description.\n"; }


	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}

function matri2(f) {
    var msg = "";    
	var err = "";

	if (isblank(f.pagefrom.value) || isNaN(f.pagefrom.value)) {err +="[] Enter a valid from age.\n";}
    if (f.pagefrom.value < 18 || f.pageto.value > 50)     { err +="[] Age of the person your looking for should be between 18-50.\n";   }
	if (isblank(f.pageto.value) || isNaN(f.pageto.value)) {err +="[] Enter a valid to age.\n";}
	if (f.pageto.value < f.pagefrom.value) { err +="[] Enter a proper age criteria.\n";}
	if (f.pheightto.value < f.pheightfrom.value) { err +="[] Enter a proper height criteria.\n";}
	if (multibox(f.pbody)) { err += "[] Please choose the body of the person your looking for.\n";}
	if (multibox(f.peducation)) { err += "[] Please choose the education of the person your looking for.\n";}
	if (multibox(f.poccupation)) { err += "[] Please choose the occupation of the person your looking for.\n";}
	if (multibox(f.preligion)) { err += "[] Please choose the religion of the person your looking for.\n";}
	if (multibox(f.pcaste)) { err += "[] Please choose the caste of the person your looking for.\n";}
    if (multibox(f.pcommunity)) { err += "[] Please choose the state of origin/ community of the person your looking for.\n";}

	if (multibox1(f.pbody)) { err += "[] Incorrect criteria selected for body type of the person your looking for.\n";}
	if (multibox1(f.peducation)) { err += "[] Incorrect criteria selected for  education of the person your looking for.\n";}
	if (multibox1(f.poccupation)) { err += "[] Incorrect criteria selected for occupation of the person your looking for.\n";}
	if (multibox1(f.preligion)) { err += "[] Incorrect criteria selected for religion of the person your looking for.\n";}
	if (multibox1(f.pcaste)) { err += "[] Incorrect criteria selected for caste of the person your looking for.\n";}
    if (multibox1(f.pcommunity)) { err += "[] Incorrect criteria selected for state of origin/ community of the person your looking for.\n";}


	if (multibox5check(f.pbody)) { err += "[] You can only choose a maximum of five option for bodytype.\n";}
	if (multibox5check(f.peducation)) { err += "[] You can only choose a maximum of five option for education.\n";}
	if (multibox5check(f.poccupation)) { err += "[] You can only choose a maximum of five option for occupation.\n";}
	if (multibox5check(f.preligion)) { err += "[] You can only choose a maximum of five option for religion.\n";}
	if (multibox5check(f.pcaste)) { err += "[] You can only choose a maximum of five option for caste.\n";}
	if (multibox5check(f.pcommunity)) { err += "[] You can only choose a maximum of five option for community.\n";}


	
	if (isblank(f.pdesc.value)) { err += "[] Please fill in the description of the person your looking for.\n";}
  
	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}

function dating1(f) {
    var msg = "";    
	var err = "";
	if (f.skin[f.skin.selectedIndex].text == f.skin[0].text) {err +="[] Please choose a Skin tone.\n";}
	if ((f.eye[f.eye.selectedIndex].text == f.eye[0].text)) {err +="[] Please choose a eye color.\n";}
	if ((f.hair[f.hair.selectedIndex].text == f.hair[0].text)) {err +="[] Please choose a type of hair.\n";}
    if (f.height[f.height.selectedIndex].text == f.height[0].text) {err +="[] Please choose your height.\n";}
	if (f.body[f.body.selectedIndex].text == f.body[0].text) {err +="[] Please choose your body type.\n";}
    if (isblank(f.sexappeal.value)) {err +="[] Please enter your most attractive characteristic.\n";}
	if (isblank(f.headline.value))	{ err +="[] Please enter your headline.\n"; }
	if ((f.education[f.education.selectedIndex].text == f.education[0].text)) {err +="[] Please choose your education.\n";}
	if ((f.occupation[f.occupation.selectedIndex].text == f.occupation[0].text)) {err +="[] Please choose your occupation.\n";}
	if ((f.income[f.income.selectedIndex].text == f.income[0].text)) {err +="[] Please choose your income.\n";}
	if ((f.smoke[f.smoke.selectedIndex].text == f.smoke[0].text)) {err +="[] Do you smoke.\n";}
	if ((f.drink[f.drink.selectedIndex].text == f.drink[0].text)) {err +="[] Do you drink.\n";}
	if ((f.gamble[f.gamble.selectedIndex].text == f.gamble[0].text)) {err +="[] Do you gamble.\n";}
	if (isblank(f.favfood.value))	{ err +="[] What is your Favorite food.\n"; }
	if ((f.status[f.status.selectedIndex].text == f.status[0].text)) {err +="[] Please choose a relationship status.\n";}
	if (isblank(f.personaldesc.value))	{ err +="[] Please enter some gyan about yourself.\n"; }


	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}


function dating2(f) {
    var msg = "";    
	var err = "";

	if ((isblank(f.pagefrom.value) || isNaN(f.pagefrom.value)) || (isblank(f.pageto.value) || isNaN(f.pageto.value))) {err +="[] Enter a valid age criteria.\n";}
	if (f.pagefrom.value < 18 || f.pageto.value > 50)     { err +="[] Age of the person your looking for should be between 18-50.\n";   }
	if (f.pageto.value < f.pagefrom.value) { err +="[] Enter a proper age criteria.\n";}
	if (f.pheightto.value < f.pheightfrom.value) { err +="[] Enter a proper height criteria.\n";}
	if (multibox(f.pbody)) { err += "[] Please choose the body of the person your looking for.\n";}
	if (multibox1(f.pbody)) { err += "[] Incorrect criteria selected for bodytype of the person your looking for.\n";}
	if (isblank(f.hate.value)) { err += "[] Which type of people you cannot stand.\n";}
	if (isblank(f.love.value)) { err += "[] Which type of people you love.\n";}
	if (isblank(f.idealrel.value)) { err += "[] What is an ideal relationship to you.\n";}
	if (isblank(f.pdesc.value)) { err += "[] Please fill in the description of the person your looking for.\n";}
  
	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
       	return(false);	}
	else { return (true); }
}

function matri_search() {
	f = document.forms[1];
    var msg = "";    
	var err = "";
	if (multibox5check(f.skin)) { err += "[] You can only choose a maximum of five option for skin.\n";}
	if (multibox5check(f.body)) { err += "[] You can only choose a maximum of five option for bodytype.\n";}
	if (multibox5check(f.education)) { err += "[] You can only choose a maximum of five option for education.\n";}
	if (multibox5check(f.occupation)) { err += "[] You can only choose a maximum of five option for occupation.\n";}
	if (multibox5check(f.religion)) { err += "[] You can only choose a maximum of five option for religion.\n";}
	if (multibox5check(f.caste)) { err += "[] You can only choose a maximum of five option for caste.\n";}
	if (multibox5check(f.community)) { err += "[] You can only choose a maximum of five option for community.\n";}

	
	if(err != "")
	 { msg += "The Form Was Not Submitted.\n";
           msg += "Please Do The Following And Re-submit\n";
           msg += "-------------------------------------------------------------------------\n";	           msg += err;
           alert(msg);
  	}
	else { f.submit(); }
}

function thejumper() {
var jumpert = document.forms[0].newselect[document.forms[0].newselect.selectedIndex].value;
location.replace(jumpert);
}


