var tip = new Array();
tip["DOBMONTH"] = "Date of birth is for calculation of age only and will not displayed to other members.";
tip["DOBDAY"] = "Date of birth is for calculation of age only and will not displayed to other members.";
tip["DOBYEAR"] = "Date of birth is for calculation of age only and will not displayed to other members.";
tip["NOOFCHILDREN"] = "If the person seeking a partner has children, please select the no. of children and whether they are living with them.";
tip["GOTHRA_SEL"] = "It is a custom in India not to marry someone with the same Gothra. We collect this information to avoid sending you matches from members of your Gothra.";
tip["M_COUNTRYCODE"] = "Phone number will be displayed only to paid members. You also have the option to hide your phone number if you do not want to display it to everyone.";
tip["MOBILENO"] = "Phone number will be displayed only to paid members. You also have the option to hide your phone number if you do not want to display it to everyone.";
tip["P_COUNTRYCODE"] = "Phone number will be displayed only to paid members. You also have the option to hide your phone number if you do not want to display it to everyone.";
tip["PHONENO"] = "Phone number will be displayed only to paid members. You also have the option to hide your phone number if you do not want to display it to everyone.";
tip["EMAIL"] = "A valid e-mail ID will enable us to send you regular matching profiles to your inbox.";
tip["CEMAIL"] = "Retype your e-mail ID. This will ensure that you have entered the correct e-mail ID.";
tip["INCOME"] = "Annual Income is one of the key deciding factors in any marriage. We recommend you be honest while mentioning your income.<br>Please add digits only. You can use commas as separators. For Eg: 6,00,000 or 600000.";
tip["RESIDINGCITY"]="If the required city is not mentioned in the list, please select from the district list.";
tip["PASSWD1"] = "Your password must have a minimum of 4 characters. We recommend you choose an alphanumeric password.";
tip["DESCDET"] = "Do not mention any contact information like phone number, e-mail or your profile may get rejected.";

var error = new Array();

var pc_val=0;var gen_val=0;var dsys_val="0";var eflag=0;var email_err_msg="";var err_flag="1";var c_track=0;
var loading_img="<img src='http://imgs.bharatmatrimony.com/bmimages/loading-icon.gif' width='45' height='38' border='0'>";
MOTHERTONGUE_DOMAIN_MAPPING = {"1":"13","2":"13","3":"10","4":"7","5":"10","6":"10","7":"10","8":"10","9":"10","10":"0","11":"0","12":"10","13":"13","14":"5","15":"10","16":"10","17":"10","18":"10","19":"4","20":"10","21":"5","22":"13","23":"6","24":"11","25":"10","26":"5","27":"13","28":"10","29":"10","30":"10","31":"3","32":"13","33":"6","34":"14","35":"13","36":"13","37":"13","38":"7","39":"10","40":"11","41":"8","42":"14","43":"10","44":"11","45":"9","46":"1","47":"1","48":"2","49":"13","50":"4","51":"15","99":"0"};

$(document).ready(function (){
	$("#NAME").blur(function(){namechk();});
	$("#datespan").html("");
	if($("#AGE").val()==0) {
		$("#DOBDAY").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,297,0);});
		$("#DOBDAY").change(function (){agesel();});
		$("#DOBDAY").blur(function(){agechk();tooltip_cls(this.name);});

		$("#DOBMONTH").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,224,0);});
		$("#DOBMONTH").change(function(){updateDay('month','MatriForm','DOBYEAR','DOBMONTH','DOBDAY');agesel();});
		$("#DOBMONTH").blur(function(){agechk();tooltip_cls(this.name);});

		$("#DOBYEAR").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,131,0);});
		$("#DOBYEAR").change(function (){updateDay('year','MatriForm','DOBYEAR','DOBMONTH','DOBDAY');agesel();});
		$("#DOBYEAR").blur(function(){agechk();tooltip_cls(this.name);});
	} else {
		$("#DOBDAY").change(function (){agesel();});
		$("#DOBDAY").blur(function(){agechk();});

		$("#DOBMONTH").change(function(){updateDay('month','MatriForm','DOBYEAR','DOBMONTH','DOBDAY');agesel();});
		$("#DOBMONTH").blur(function(){agechk();});

		$("#DOBYEAR").change(function (){updateDay('year','MatriForm','DOBYEAR','DOBMONTH','DOBDAY');agesel();});
		$("#DOBYEAR").blur(function(){agechk();});	
	}
	
	//$("#AGE").focus(agefocus);
	$("#AGE").blur(function(){agechk();});
	$("input[name='GENDER']").bind( "click", genval);
	$("input[name='GENDER']").bind( "blur", function(){genchk();});


	$("#RELIGION").change(religion_chang);
	$("#RELIGION").blur(function(){religionchk();});

	$("#MOTHERTONGUE").change(mtounge_chang);
	$("#MOTHERTONGUE").blur(function(){mtoungechk();});
	
	$("#CASTE_NORMAL").change(caste_chang);
	$("#CASTE_NORMAL").blur(function(){caste_chk();});

	$("#CASTE_FREETEXT").blur(function(){casteother_blur();casteother_chk();});
	$("#CASTE_FREETEXT").focus(casteother_focus);

	$("#M_COUNTRYCODE").blur(function(){contactchk();});
	$("#M_COUNTRYCODE").change(mccode_chang);
	$("#P_COUNTRYCODE").change(pccode_chang);
	
	$("#AREACODE").click(function(){if (this.value == '- Area code -' || this.value == '- STD code -') { this.value = ''; }});
	$("#AREACODE").focus(function(){if (this.value == '- Area code -' || this.value == '- STD code -') { this.value = ''; }});
	$("#AREACODE").blur(function(){contactchk();});
	
	$("#PHONENO").click(function(){if (this.value == '- Landline number -') { this.value = ''; }});
	$("#PHONENO").focus(function(){tooltip_chk('show', this.name, this, 25,0,40);if (this.value == '- Landline number -') { this.value = ''; }});
	$("#PHONENO").blur(function(){tooltip_cls(this.name);contactchk();});
	
	$("#MOBILENO").click(function(){if (this.value == '- Mobile number -') { this.value = ''; }});
	$("#MOBILENO").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,0,0);if (this.value == '- Mobile number -') { this.value = ''; }});
	$("#MOBILENO").blur(function(){tooltip_cls(this.name);contactchk();});
	
	$("#EMAIL").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,0,0);});
	$("#EMAIL").blur(function(){emailchk();tooltip_cls(this.name);});
	
	$("#COUNTRY").change(countrychangeval);
	$("#COUNTRY").blur(countrychk);

	$("#PASSWD1").focus(function(){tooltip_chk('show', this.name, this, this.offsetWidth,0,0);});
	$("#PASSWD1").blur(function(){tooltip_cls(this.name);passchk();});

	$("#MatriForm").submit(function(){if(addpg1_validate()==true){
													var dnames=d_return(MOTHERTONGUE_DOMAIN_MAPPING[$("#MOTHERTONGUE").val()]);
													var dnames=dnames.toLowerCase(); 

													var surl="http://profile."+dnames+"matrimony.com/register/campaignregistration.php";
													
													if($("#CASTE_FREETEXT").val()=="- Enter caste -"){$("#CASTE_FREETEXT").val("");}
													if($("#OTHER_CASTE_TXT").val()=="- Enter subcaste -"){$("#OTHER_CASTE_TXT").val("");}
													if($("#SUBCASTE_OTHER_TXT").val()=="- Enter subcaste -"){$("#SUBCASTE_OTHER_TXT").val("");}

													if($("#GOTHRA_TXT").val()=="- Enter gothra -"){$("#GOTHRA_TXT").val("");}
													if($("#GOTHRA_OTHER_TXT").val()=="- Enter gothra -"){$("#GOTHRA_OTHER_TXT").val("");}
													
													if($("#MOBILENO").val()=="- Mobile number -"){$("#MOBILENO").val("");}
													if($("#PHONENO").val()=="- Landline number -"){$("#PHONENO").val("");}
													if($("#AREACODE").val()=="- Area code -"){$("#AREACODE").val("");}
													if($("#AREACODE").val()=="- STD code -"){$("#AREACODE").val("");}

													$("#MatriForm").attr("action",surl);
													return true;
													$("#MatriForm").submit();}else{return false;}
													});
});

function countrychangeval() {
	if($("#COUNTRY").val()=="888") {
		get_country('COUNTRY','country_err');
	}
	$("#P_COUNTRYCODE").val($("#COUNTRY").val());
	$("#M_COUNTRYCODE").val($("#COUNTRY").val());
}

function show_gen()
{
	pc_val=$("input[name='REGISTERED_BY']:checked").val();

	if(pc_val==8 || pc_val==9 || pc_val==10 || pc_val==11)
	{
		$("#gender_div").hide();
		if(pc_val==8){$("#ms_label").html("Widower");$("input[name='GENDER']")[0].checked=true;gen_val="M";$("#uage").hide();}
		if(pc_val==9){$("#ms_label").html("Widow");$("input[name='GENDER']")[1].checked=true;gen_val="F";$("#uage").hide();}
		if(pc_val==10){$("#ms_label").html("Widower");$("input[name='GENDER']")[0].checked=true;gen_val="M";$("#uage").hide();}
		if(pc_val==11){$("#ms_label").html("Widow");$("input[name='GENDER']")[1].checked=true;gen_val="F";$("#uage").hide();}
	}
	
	if(pc_val==1 || pc_val==12)
	{
		gen_val=0;

		var c=$("input[name='GENDER']").length;for(i=0;i<c;i++){$("input[name='GENDER']")[i].checked=false;}
		$("#ms_label").html("Widow/Widower");$("#gender_div").show();

		if(pc_val==1){$("#uage").hide();}
		if(pc_val==12){$("#uage").show();}
	}

	if($("#DOBDAY").val()!=0 || $("#DOBMONTH").val()!=0 || $("#DOBYEAR").val()!=0 || !IsTxtEmpty($("#AGE"),'text'))
	{agechk();}
}
//REGISTERED_BY check

//Name check
function namechk()
{
	var reg = /^([^0-9]*)$/;       
	if (IsTxtEmpty($("#NAME"),'text'))
	{$("#namespan").html("Please enter name.");return false;}
	else if(reg.test($("#NAME").val()) == false)
	{$("#namespan").html("You are not allowed to use numeric values");return false;}	
	else{$("#namespan").html("");return true;}
}
//Name check

//DOB and Age Check
function agechk() {
	$("#dobspan").html("");
	var isdob = 1;
	if($("#DOBYEAR").val()==0 && $("#DOBMONTH").val()==0 && $("#DOBDAY").val()==0){
		isdob = 0;
	}	
	if($("#DOBYEAR").val()!=0 && $("#DOBMONTH").val()!=0 && $("#DOBDAY").val()!=0 && $("#AGE").val()=="" ){
		$("#dobspan").html("");
		$("#datespan").html("");
		$("#monthspan").html("");
		$("#yearspan").html("");
		$("#age_err").html("");
		$("#AGE").val("");
		return true;
	}if(($("#DOBYEAR").val()==0 || $("#DOBMONTH").val()==0 || $("#DOBDAY").val()==0) && isdob==1 && $("#AGE").val()>0 ){
		$("#dobspan").html("Please select date of birth");
		$("#datespan").html("");
		$("#monthspan").html("");
		$("#yearspan").html("");
		$("#age_err").html("");
		return false;
	}if($("#DOBDAY").val()==0 && $("#DOBMONTH").val()==0 && $("#DOBYEAR").val()==0 && IsTxtEmpty($("#AGE"),'text'))	{
		$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#age_err").html("");
		$("#dobspan").html("Please select date of birth");
		return false;
	} else {
		if($("#DOBYEAR").val()!=0 && $("#DOBMONTH").val()!=0 && $("#DOBDAY").val()!=0 && $("#AGE").val()!=''){
			different = calculate_age($("#DOBYEAR").val(),$("#DOBMONTH").val(),$("#DOBDAY").val());
			if(different!=$("#AGE").val()){
				$('#dobspan').html("The age value does not match with the date-of-birth.Please enter the correct date-of-birth.");
				$("#datespan").html("");
				$("#monthspan").html("");
				$("#yearspan").html("");
				$("#age_err").html("");
				return false;
			}
		}
		if($("#AGE").val()==0) {
			if(datechk()==false){
				return false;
			} else if(monthchk()==false){
				return false;
			}  else if(yearchk()==false){
				return false;
			}
		} else {
			if (!ValidateNo($('#AGE').val(),'1234567890')) {
				$('#dobspan').html("Please enter a valid age");
				$("#datespan").html("");
				$("#monthspan").html("");
				$("#yearspan").html("");
				$("#age_err").html("");
				return false;
			} else {
				//$("#DOBDAY").val("");$("#DOBMONTH").val("");$("#DOBYEAR").val("");
				$("#dobspan").html("");
				$("#datespan").html("");
				$("#monthspan").html("");
				$("#yearspan").html("");					
				$("#age_err").html("");
			}
		}
        if($("#DOBYEAR").val()!=0 && $("#DOBMONTH").val()!=0 && $("#DOBDAY").val()!=0){
			diff = calculate_age($("#DOBYEAR").val(),$("#DOBMONTH").val(),$("#DOBDAY").val());
			$('#AGE').val(diff);			
	    }
		return true;
	}
}

function datechk()
{
	
	if($("#DOBDAY").val()==0){$("#age_err").html("");$("#dobspan").html("");$("#datespan").html("Please select date");return false;}
	else{$("#dobspan").html("");$("#datespan").html("");}
}

function monthchk()
{	
	if($("#DOBMONTH").val()==0){$("#age_err").html("");$("#dobspan").html("");$("#monthspan").html("Please select month");return false;}
	else{$("#dobspan").html("");$("#monthspan").html("");}
}

function yearchk()
{
	if($("#DOBDAY").val()==0 && $("#DOBMONTH").val()==0 && $("#DOBYEAR").val()==0)
	{
		$("#age_err").html("");$("#dobspan").html("Please select date of birth.");$("#datespan").html("");$("#monthspan").html("");
	}
	else if($("#DOBYEAR").val()==0){$("#age_err").html("");$("#dobspan").html("");$("#yearspan").html("Please select year");return false;}

	else{$("#yearspan").html("");}
}


function dob_cal()
{
	if(($("#DOBDAY").val()!=0)&&($("#DOBMONTH").val()!=0) &&($("#DOBYEAR").val()!=0))
	{
	
	var mchk=($("#DOBMONTH").val()%2);
	var ychk=($("#DOBYEAR").val()%4);			

	if($("#DOBMONTH").val()==2)
	{
		if($("#DOBDAY").val()>=30)
		{$("#dobspan").html("Please select correct date. This month doesn't have 30 or 31");return false;}
		else if($("#DOBDAY").val()==29)
		{
			if(ychk!=0){$("#dobspan").html("This is not a leap year. Please select the correct date");return false;}else{$("#dobspan").html("");return true;}
		}
		else{$("#dobspan").html("");return true;}
	}
	
	else if(($("#DOBMONTH").val()<=7)&&(mchk==0))
	{				
		if($("#DOBDAY").val()==31)
		{$("#dobspan").html("Please select correct date. This month doesn't have 31");return false;}	
	}
	
	 else if(($("#DOBMONTH").val()>=8)&&(mchk==1))
	{				
		if($("#DOBDAY").val()==31)
		{$("#dobspan").html("Please select correct date. This month doesn't have 31");return false;}	else{$("#dobspan").html("");return true;}
	}
	else{$("#dobspan").html("");return true;}
  }
}

function agefocus()
{
	if(!IsTxtEmpty($("#AGE"),'text'))
	{
		if($("#DOBYEAR").val()!="0" && $("#DOBMONTH").val()!="0" && $("#DOBDAY").val()!="0")
		{$("#DOBMONTH").val("0");$("#DOBDAY").val("0");$("#DOBYEAR").val("0");}
	}
}	

function agesel(){
	$("#AGE").val("");
	if($("#DOBYEAR").val()!=0 && $("#DOBMONTH").val()!=0 && $("#DOBDAY").val()!=0){
		diff = calculate_age($("#DOBYEAR").val(),$("#DOBMONTH").val(),$("#DOBDAY").val());
	    $('#AGE').val(diff);
	}
}
//DOB and Age Check

//Gender Check
function genchk() {
	var MatriForm = this.document.MatriForm;
	if (!MatriForm.GENDER[0].checked && !MatriForm.GENDER[1].checked) {
		$("#gen_err").html("Please select gender.");return false;
	} else if (MatriForm.GENDER[0].checked || MatriForm.GENDER[1].checked) {
		$("#gen_err").html("");
		genval();
	}
}

function genval()
{
	var gen_val=$("input[name='GENDER']:checked").val();
	if(gen_val=="M")
	{
		if($("#DOBMONTH").attr("value")!=0 && $("#DOBDAY").attr("value")!=0 && $("#DOBYEAR").attr("value")!=0)
		{
			var calyear = displayage($("#DOBYEAR").attr("value"),$("#DOBMONTH").attr("value"),$("#DOBDAY").attr("value"), 'years', 0, 'rounddown');			
			if(calyear < 21){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#dobspan").html("");$("#age_err").html("Sorry! The person needs to be 21 or above to register here.");$("#DOBDAY").focus();}
			else if(calyear > 70){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#age_err").html("");$("#dobspan").html("Maximum age allowed is 70.");$("#DOBDAY").focus();}
			else{$("#dobspan").html("");}
		}
		
		if(!IsTxtEmpty($("#AGE"),'text'))
		{
			var calyear = $("#AGE").val();
			if(calyear < 21){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#dobspan").html("");$("#age_err").html("Sorry! The person needs to be 21 or above to register here.");$("#DOBDAY").focus();}
			else if(calyear > 70){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#dobspan").html("");$("#age_err").html("Maximum age allowed is 70.");$("#DOBDAY").focus();}
			else{$("#age_err").html("");}
		}

		$("#ms_label").html("Widower");
	}
	if(gen_val=="F")
	{
			if($("#DOBMONTH").attr("value")!=0 && $("#DOBDAY").attr("value")!=0 && $("#DOBYEAR").attr("value")!=0)
			{
				var calyear = displayage($("#DOBYEAR").attr("value"),$("#DOBMONTH").attr("value"),$("#DOBDAY").attr("value"), 'years', 0, 'rounddown');
				if(calyear < 18){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#age_err").html("");$("#dobspan").html("Sorry! The person needs to be 18 or above to register here.");$("#AGE").focus();}
				else if(calyear > 70){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#age_err").html("");$("#dobspan").html("Maximum age allowed is 70.");$("#AGE").focus();}
				else{$("#dobspan").html("");}
			}
			
			if(!IsTxtEmpty($("#AGE"),'text'))
			{
			var calyear = $("#AGE").val();
			if(calyear < 18){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#dobspan").html("");$("#age_err").html("Sorry! The person needs to be 18 or above to register here.");$("#AGE").focus();}
			else if(calyear > 70){$("#datespan").html("");$("#monthspan").html("");$("#yearspan").html("");$("#dobspan").html("");$("#age_err").html("Maximum age allowed is 70.");$("#AGE").focus();}
			else{$("#age_err").html("");}
			}

			$("#ms_label").html("Widow");
	}
}
//Gender Check

//Religion Check
function religionchk()
{if($("#RELIGION").val()==0){$("#religion_err").html("Please select religion.");return false;}else{$("#religion_err").html("");return true;}}

function religion_chang()
{
	var def_sel = {"value":"0", "caption":"- Select -"};
	var def_castsel = {"value":"00", "caption":"- Select -"};

	$("#MOTHERTONGUE").val("0");
	$("#mtounge_err").html("");

	$("#CASTE_NORMAL").emptySelect();
	$("#CASTE_NORMAL").loadSelect([def_castsel]);
	$("#CASTE_FREETEXT").hide();$("#CASTE_FREETEXT").val("- Enter caste -");$("#caste_err").html("");

	var r_val=$("#RELIGION").val();

	if(r_val==2 || r_val==10 || r_val==11){$("#castelabel").html("Sect / Division");}
	else if(r_val==3 || r_val==12 || r_val==13 || r_val==14){$("#castelabel").html("Denomination");}
	else{$("#castelabel").html("Caste / Division");}
}
//Religion Check

//Mothertounge Check
function mtoungechk()
{
	if($("#MOTHERTONGUE").val()==0)
	{$("#mtounge_err").html("Please select mother tongue.");return false;}
	else{$("#mtounge_err").html("");return true;}
}

function mtounge_chang()
{
	sdomain="";dsys_val=0;
	var def_sel = {"value":"00", "caption":"- Select -"};
	var def_castsel = {"value":"00", "caption":"- Select -"};

	$("#mtounge_err").html("");

	$("#DOMAIN").emptySelect();
	$("#DOMAIN").loadSelect([def_sel]);$("#domain_err").html("");
	$("#CASTE_NORMAL").emptySelect();
	$("#CASTE_NORMAL").loadSelect([def_castsel]);
	$("#CASTE_FREETEXT").hide();$("#CASTE_FREETEXT").val("- Enter caste -");$("#caste_err").html("");

	//subcaste block
	$("#SUBCASTE_SEL").emptySelect();
	$("#SUBCASTE_SEL").loadSelect([def_sel]);
	$("#SUBCASTE_SEL").hide();	
	$("#OTHER_CASTE").show();$("#OTHER_CASTE_TXT").val("- Enter subcaste -");
	$("#SCASTE_OTHER").hide();$("#SUBCASTE_OTHER_TXT").val("- Enter subcaste -");
	$("#subcaste_err").html("");
	//subcaste block

	//gothra block
	$("#GOTHRA_LIST").hide();
	$("GOTHRA_SEL").val("0");
	
	$("#DEFAULT_GOTHRA").show();$("#GOTHRA_TXT").val("- Enter gothra -");
	$("#OTHER_GOTHRA").hide();$("#GOTHRA_OTHER_TXT").val("- Enter gothra -");
	$("#gothra_err").html("");
	//gothra block

	if($("#MOTHERTONGUE").val()>0)
	{
		var selbox = $('#DOMAIN');
		selbox.hide();$("#DOMAIN_LOADING").html(loading_img);
		selbox.emptySelect();
		$.getJSON('/register/ajax_registration.php',{type:"get_domain",mother_tongue: $("#MOTHERTONGUE").val()},
		function(data)
		{
				$("#DOMAIN_LOADING").html("");
				selbox.loadSelect(data);selbox.show();
			if($("#RELIGION").val()>0)
			{
				$('#CASTE_NORMAL').hide();
				$("#CASTE_LOADING").html(loading_img);
			
				var selbox1 = $('#CASTE_NORMAL');
				selbox1.emptySelect();
				$.getJSON('/register/ajax_registration.php',{type:"caste",language: data[0].value,religion:$("#RELIGION").val(),mothertongue:$("#MOTHERTONGUE").val()},
				function(data){
									$.each(data, function(index, obj) {selbox1.append($('<option></option').val(obj.value).html(obj.caption).css({color:obj.color}));});
									//selbox1.loadSelect(data);
									$("#CASTE_LOADING").html("");$('#CASTE_NORMAL').show();
									});
			}
		});
	}
}

//Caste Check
function caste_chk()
{
	if($("#CASTE_NORMAL").val()=="00"){$("#caste_err").html("Please select caste");return false;}else{$("#caste_err").html("");return true;}
}

function casteother_chk()
{
	if($("#CASTE_NORMAL").val()=="999" || $("#CASTE_NORMAL").val()=="424" || $("#CASTE_NORMAL").val()=="512" || $("#CASTE_NORMAL").val()=="609" || $("#CASTE_NORMAL").val()=="663")
	{
		if($("#CASTE_FREETEXT").val()=="- Enter caste -")
		{$("#caste_err").html("Please enter caste");return false}else{$("#caste_err").html(" ");}
	}
}

function casteother_blur(){if(IsTxtEmpty($("#CASTE_FREETEXT"),'text')) {$("#CASTE_FREETEXT").val("- Enter caste -");}}

function casteother_focus()
{
	if($("#CASTE_NORMAL").val()=="999" || $("#CASTE_NORMAL").val()=="424" || $("#CASTE_NORMAL").val()=="512" || $("#CASTE_NORMAL").val()=="609" || $("#CASTE_NORMAL").val()=="663")
	{if($("#CASTE_FREETEXT").val()=="- Enter caste -"){$("#CASTE_FREETEXT").val("");}}
}


var scaste=0;var gothra_state=0;

function caste_chang()
{
	var def_sel = {"value":"00", "caption":"- Select -"};var def_sel1 = {"value":"0", "caption":"- Select -"};

	$("#CASTE_FREETEXT").hide();$("#CASTE_FREETEXT").val("- Enter caste -");

	$("#SCASTE_SEL").hide();
	$("#SUBCASTE_SEL").emptySelect();
	$("#SUBCASTE_SEL").loadSelect([def_sel]);
	$("#OTHER_CASTE").hide();$("#OTHER_CASTE_TXT").val("- Enter subcaste -");
	$("#SCASTE_OTHER").hide();$("#SUBCASTE_OTHER_TXT").val("- Enter subcaste -");
	
	$("#GOTHRA_LIST").hide();$("#GOTHRA_SEL").val("0");
	$("#OTHER_GOTHRA").hide();$("#GOTHRA_OTHER_TXT").val("- Enter gothra -");
	$("#DEFAULT_GOTHRA").show();$("#GOTHRA_TXT").val("- Enter gothra -");


	$("#caste_err").html("");$("#subcaste_err").html("");$("#gothra_err").html("");

	//not others, select, don't,show more
	if($("#CASTE_NORMAL").val()=="999" || $("#CASTE_NORMAL").val()=="424" || $("#CASTE_NORMAL").val()=="512" || $("#CASTE_NORMAL").val()=="609" || $("#CASTE_NORMAL").val()=="663")
	{
		scaste=1;
		$("#CASTE_FREETEXT").show(); //Caste free txt
		//$("#OTHER_CASTE").show() //subcaste free span
		//$("#DEFAULT_GOTHRA").show(); 
	}

	else if($("#CASTE_NORMAL").val()=="no")
	{
		$("#CASTE_FREETEXT").hide();$("#OTHER_CASTE").hide();$("#SCASTE_OTHER").hide();
		
		//$("#SCASTE_SEL").emptySelect();
		//$("#SCASTE_SEL").loadSelect([def_sel1]);
		//$("#SCASTE_SEL").hide();
		
		//$("#OTHER_CASTE").show();$("#OTHER_CASTE_TXT").val("- Enter subcaste -");

		$("#CASTE_NORMAL").hide();$("#CASTE_LOADING").html(loading_img);

		var selbox = $('#CASTE_NORMAL');
		selbox.emptySelect();
		$.getJSON('/register/ajax_registration.php',{type:"caste",language: $("#DOMAIN").val(),religion:$("#RELIGION").val(),caste:"no"},
		function(data){$("#CASTE_LOADING").html("");selbox.loadSelect(data);scaste=0;$("#CASTE_NORMAL").show();});
	}
	//don't wish
	else if($("#CASTE_NORMAL").val()=="0")	
	{
		scaste=2;
		$("#subcaste_div").hide();
		$("#DEFAULT_GOTHRA").show();
		$("#GOTHRA_TXT").val("- Enter gothra -");
		$("#SUBCASTE").val("");$("#SUBCASTEID").val("");
		$("#GOTHRAM").val("");$("#GOTHRAMOTHERS").val("");
		$("#gothra_err").html("");
	}
	
	else if($("#CASTE_NORMAL").val()=="00")	
	{
		scaste=2;
		$("#subcaste_div").show();$("#SCASTE_SEL").show();
		var ex_selbox = $('#SUBCASTE_SEL');ex_selbox.emptySelect();ex_selbox.loadSelect([def_sel1]);

		$("#SCASTE_OTHER").hide();
		$("#DEFAULT_GOTHRA").show();$("#GOTHRA_TXT").val("- Enter gothra -");
		
		$("#OTHER_GOTHRA").hide();$("#GOTHRA_OTHER_TXT").val("- Enter gothra -");
		$("#GOTHRA_LIST").hide();

		$("#SUBCASTE").val("");$("#SUBCASTEID").val("");
		$("#GOTHRAM").val("");$("#GOTHRAMOTHERS").val("");
	}

	else if($("#CASTE_NORMAL").val()!="0")
	{
		scaste=0;$("#subcaste_div").show();$("#OTHER_CASTE").show();
		$("#OTHER_CASTE_TXT").val("- Enter subcaste -");
	}

	if($("#CASTE_NORMAL").val()==0 || $("#CASTE_NORMAL :selected").text()=="Intercaste" || $("#CASTE_NORMAL :selected").text()=="Jain - Intercaste" ||$("#CASTE_NORMAL :selected").text()=="Sikh - Intercaste")
	{$("#SAMECASTE").attr("checked",false);}else{$("#SAMECASTE").attr("checked",true);}

}

function other_scaste_chk()
{
	if($("#SUBCASTE_SEL :selected").text()=="Others")
	{
		if($("#SUBCASTE_OTHER_TXT").val()=="- Enter subcaste -")
		{$("#subcaste_err").html("Please enter sub caste.");return false;}
		else
		{	
			$("#SUBCASTEID").val($("#SUBCASTE_SEL").val());
			$("#SUBCASTE").val($("#SUBCASTE_OTHER_TXT").val());
			$("#subcaste_err").html("");return true;
		}
	}
}

function other_scaste_blur()
{
	if(IsTxtEmpty($("#SUBCASTE_OTHER_TXT"),'text')){$("#SUBCASTE_OTHER_TXT").val("- Enter subcaste -");}
}
//Sub Caste Check


//Contact info Check
function get_country(lobj,lspan)
{
	$.getJSON('/register/ajax_registration.php',{type:"country"},
	function(data)
	{
		$('#'+lobj).loadSelect(data);$('#'+lspan).hide();$('#'+lobj).show();
	});
}

function mccode_chang()
{
	var def_sel = {"value":"00", "caption":"- Select -"};

	if($("#M_COUNTRYCODE").val()>0)
	{
		$("#P_COUNTRYCODE").val($("#M_COUNTRYCODE").val());
		$("#INCOME_CURRENCY").val($("#M_COUNTRYCODE").val());

		if($("#P_COUNTRYCODE").val()=="98"){$("#AREACODE").val("- STD code -");}
		else{$("#AREACODE").val("- Area code -");}
	}
	else if($("#M_COUNTRYCODE").val()=="no")
	{
		$("#M_COUNTRYCODE").hide();$("#mobilecountry").show();$("#mobilecountry").html(loading_img);
		$("#M_COUNTRYCODE").emptySelect();get_country('M_COUNTRYCODE','mobilecountry');
	}
	else{$("#P_COUNTRYCODE").val("0");$("#INCOME_CURRENCY").val("0");$("#COUNTRY").val("0");}
}

function pccode_chang()
{
	if($("#P_COUNTRYCODE").val()>0)
	{
		if($("#M_COUNTRYCODE").val()==0)
		{
		$("#INCOME_CURRENCY").val($("#P_COUNTRYCODE").val());
		if($("#P_COUNTRYCODE").val()=="98"){$("#AREACODE").val("- STD code -");}
		else{$("#AREACODE").val("- Area code -");}
		}
		else{$("#INCOME_CURRENCY").val("0");$("#COUNTRY").val("0");}
	}
	else if($("#P_COUNTRYCODE").val()=="no")
	{
		$("#P_COUNTRYCODE").hide();$("#landlinecountry").show();$("#landlinecountry").html(loading_img);
		$("#P_COUNTRYCODE").emptySelect();get_country('P_COUNTRYCODE','landlinecountry');
	}
}

function contactchk()
{
	if(IsTxtEmpty($("#MOBILENO"),'text')){$("#MOBILENO").val("- Mobile number -");}
	if(IsTxtEmpty($("#PHONENO"),'text')){$("#PHONENO").val("- Landline number -");}
	if(IsTxtEmpty($("#AREACODE"),'text')){$("#AREACODE").val("- STD code -");}

	if($("#MOBILENO").val()=="- Mobile number -" && $("#PHONENO").val()=="- Landline number -")
	{$("#ph_err").html("Please enter a valid phone number.");return false;} else {$("#ph_err").html("");}

	if (!IsTxtEmpty($("#MOBILENO"),"text") && $("#MOBILENO").val()!="- Mobile number -")
	{
		if($("#M_COUNTRYCODE").val()==0){$("#mo_err").html("Please select country code.");return false;}
		else if(mobilevalidate($("#MOBILENO").val())==true){$("#mo_err").html(" ");}else{return false;}
	}

	if (!IsTxtEmpty($("#PHONENO"),"text") && $("#PHONENO").val()!="- Landline number -")
	{
		if(phonevalidate($("#PHONENO").val())==true){$("#ph_err").html("");}else{return false;}
	}

	return true;
}

//Contact info Check

//Email and Confirm Email Check
function emailchk()
{
	if(IsTxtEmpty($("#EMAIL"),"text"))
	{$("#email_err").html("Please enter an e-mail ID.");return false;}
	else if($("#EMAIL").val()!="")
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test($("#EMAIL").val()))) 
		{$("#email_err").html("Please enter a valid e-mail ID.");return false;}else{$("#email_err").html("");return true;}
	}
	else{$("#email_err").html("");return true;}
}

//Country Check
function countrychk()
{
	if($("#COUNTRY").val()==0 || $("#COUNTRY").val()=="")
	{$("#country_err").html("Please select country.");return false;}else{$("#country_err").html("");return true;}
}

//Pass Check
function passchk()
{
	if(IsTxtEmpty($("#PASSWD1"),"password"))
	{$("#pass_err").html("Please enter password.");return false;}
	else if(!IsTxtEmpty($("#PASSWD1"),"password"))
	{
		var pass_val=$("#PASSWD1").val();var NAME=$("#NAME").val();
		goodPasswd = 1;
		for ( var idx=0; idx< pass_val.length; idx++ ) {
		ch = pass_val.charAt(idx);
		if (( !((ch>='a') && (ch<='z')) && !((ch>='A') && (ch<='Z')) && !((ch>=0) && (ch <=9)) ) || (ch==' '))
			{goodPasswd = 0;break;}
		}
		if (pass_val.length<4)
		{$("#pass_err").html("Your password must have a minimum of 4 characters.");return false;}
		else if(pass_val.toUpperCase()==NAME.toUpperCase())
		{$("#pass_err").html("The name and password cannot be the same. Please change the password.");return false;}
		else if ( goodPasswd ==0 ) 
		{$("#pass_err").html("Spaces or special characters are not allowed in the password.");return false;}
		else if(pass_val=='123456')
		{$("#pass_err").html("Sorry, your password has been rejected.It is recommended that you submit a password with alphanumeric characters.");return false;}
		else{$("#pass_err").html("");return true;}
	}
	else{$("#pass_err").html("");return true;}
}
//Pass Check


//calender
var one_day=1000*60*60*24
var one_month=1000*60*60*24*30
var one_year=1000*60*60*24*30*12

function displayage(yr, mon, day, unit, decimal, round){
today=new Date()
var pastdate=new Date(yr, mon-1, day)

var countunit=unit
var decimals=decimal
var rounding=round
finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
decimals=(decimals<=0)? 1 : decimals*10

if (unit!="years"){
if (rounding=="rounddown")
alert (Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+' '+countunit)
else
alert (Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+' '+countunit)
}
else
{
yearspast=today.getFullYear()-yr-1
tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
pastdate.setFullYear(today.getFullYear())
pastdate2=new Date(today.getFullYear()-1, mon-1, day)
tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
var calyear=yearspast+tail;
}
return calyear;
}
//calender

//load select
(function($) {
  $.fn.emptySelect = function() {
    return this.each(function(){
      if (this.tagName=='SELECT') this.options.length = 0;
    });
  }

  $.fn.loadSelect = function(optionsDataArray) {
    return this.emptySelect().each(function(){
      if (this.tagName=='SELECT') {
        var selectElement = this;
        $.each(optionsDataArray,function(index,optionData){
          var option = new Option(optionData.caption,
                                  optionData.value);
          if ($.browser.msie) {
            selectElement.add(option);
          }
          else {
            selectElement.add(option,null);
          }
        });
      }
    });
  }
})(jQuery);

//load select

//Submit Action start
function addpg1_validate()
{
	if(namechk()==false){$("#NAME").focus();return false;}
	if(agechk()==false){ $("#DOBDAY").focus();return false;}

	if(genchk()==false){$("#GENDER1").focus();return false;}
	if($("#age_err").html()!='') {$("#DOBDAY").focus();return false;}

	if(religionchk()==false){$("#RELIGION").focus();return false;}

	if(mtoungechk()==false){$("#MOTHERTONGUE").focus();return false;}

	if(caste_chk()==false){$("#CASTE_NORMAL").focus();return false;}

	if(casteother_chk()==false){$("#CASTE_FREETEXT").focus();return false;}

	if(countrychk()==false){$("#COUNTRY").focus();return false;}

	if(contactchk()==false)
	{
		//alert(contactchk());
		
			if($("#MOBILENO").val()=="- Mobile number -" && $("#PHONENO").val()=="- Landline number -")
			{$("#MOBILENO").focus();return false;}
		
			
			if (!IsTxtEmpty($("#MOBILENO"),"text") && $("#MOBILENO").val()!="- Mobile number -")
			{
				
				if($("#M_COUNTRYCODE").val()==0)
				{
					$("#M_COUNTRYCODE").focus();return false;
				}
				else if(mobilevalidate($("#MOBILENO").val())==false)
				{$("#MOBILENO").focus();return false;}
			}
			
			if (!IsTxtEmpty($("#PHONENO"),"text") && $("#PHONENO").val()!="- Landline number -")
			{
				
				if(phonevalidate($("#PHONENO").val())==false){$("#PHONENO").focus();return false;}				
				if($("#P_COUNTRYCODE").val()==0){$("#P_COUNTRYCODE").focus();return false;}	
				if (IsTxtEmpty($("#AREACODE"),"text") || $("#AREACODE").val()=="- STD code -" || $("#AREACODE").val()=="- Area code -")
				{$("#AREACODE").focus();return false;}
			}
	}

	if(emailchk()==false){$("#EMAIL").focus();return false;}
	if(eflag==1){$("#EMAIL").focus();$("#email_err").html(email_err_msg);return false;}else{$("#email_err").html("");}
	if(passchk()==false){$("#PASSWD1").focus();return false;}
	//if(termschk()==false){$("#TERMS").focus();return false;}
	return true;
}

//Submit Action End


var prev_str="";
function mid_post()
{
	$.post("/register/ajax_registration.php", { 
			REGISTERED_BY:$("input[name='REGISTERED_BY']:checked").val(),
			NAME: $("#NAME").val(), 
            DOBMONTH:$("#DOBMONTH").val(),
            DOBDAY:$("#DOBDAY").val(),
			DOBYEAR:$("#DOBYEAR").val(),
            AGE:$("#AGE").val(),
			GENDER:$("input[name='GENDER']:checked").val(),
			FEET:$("#FEET").val(),
			CMS:$("#CMS").val(),
			INCMS:$("#INCMS").val(),
			MARITAL_STATUS:$("input[name='MARITAL_STATUS']:checked").val(),
			NOOFCHILDREN:$("#NOOFCHILDREN").val(),
			CHILDLIVINGWITHME:function(){
														if($('input[name=CHILDLIVINGWITHME]').is(':checked')==true)
														{return $('input[name=CHILDLIVINGWITHME]:checked').val()}else{return " ";}
													  },
			RELIGION:$("#RELIGION").val(),
			MOTHERTONGUE:$("#MOTHERTONGUE").val(),
			DOMAIN:$("#DOMAIN").val(),

			CASTE_NORMAL:$("#CASTE_NORMAL").val(),
		    CASTE_FREETEXT:function(){
													if($("#CASTE_NORMAL").val()=="999" || $("#CASTE_NORMAL").val()=="424" || $("#CASTE_NORMAL").val()=="512" || $("#CASTE_NORMAL").val()=="609" || $("#CASTE_NORMAL").val()=="663")
													{
														if($("#CASTE_FREETEXT").val()=="- Enter caste -")
														{return $("#CASTE_FREETEXT").val("");}else{return $("#CASTE_FREETEXT").val();}
													}
												  },

			SAMECASTE:function(){
											if($('input[name=SAMECASTE]').is(':checked')==false){return 'N';}else{return 'Y'}
											},
			SUBCASTEID:$("#SUBCASTEID").val(),
			SUBCASTE:$("#SUBCASTE").val(),
			GOTHRAM:$("#GOTHRAM").val(),
			GOTHRAMOTHERS:$("#GOTHRAMOTHERS").val(),
			M_COUNTRYCODE:$("#M_COUNTRYCODE").val(),
			MOBILENO:function(){var mno=$("#MOBILENO").val();
										  if(mno!="- Mobile number -"){return mno;}else{mno="";return mno;}
										},
			P_COUNTRYCODE:$("#P_COUNTRYCODE").val(),
			AREACODE:function(){var ano=$("#AREACODE").val();
										  if(ano!="- Area code -" && ano!="- STD code -" ){return ano;}else{ano="";return ano;}
										},
			PHONENO:function(){var pno=$("#PHONENO").val();
										  if(pno!="- Landline number -"){return pno;}else{pno="";return pno;}
										},
			EMAIL:$("#EMAIL").val(),
			CEMAIL:$("#CEMAIL").val(),
			KEYWORDCAPTUREID:$("input[name='KEYWORDCAPTUREID']").val(),
			type: "partlyreg_post" 
			}, 
			function(data){
								if(data=="email_err1")
								{
								email_err_msg="Sorry, you are allowed to register a maximum of two profiles only with the same e-mail ID.";
								$("#email_err").html("Sorry, you are allowed to register a maximum of two profiles only with the same e-mail ID.");eflag=1;}
								else if(data=="email_err2")
								{
								email_err_msg="Sorry, you are allowed to register a maximum of two profiles only with the same e-mail ID.";
								$("#email_err").html("Sorry, you are allowed to register a maximum of two profiles only with the same e-mail ID.");eflag=1;
								}
								else if(data=="email_err3")
								{	email_err_msg="Invalid e-mail ID. Please enter a correct e-mail ID.";
									$("#email_err").html("Invalid e-mail ID. Please enter a correct e-mail ID.");eflag=1;
								}
								else if(ValidateNo(data,"1234567890")==true)
								{
									eflag=0;
									$("#RegID").val(data);
									surl="http://campaign.bharatmatrimony.com/track/leadtrack.php?regid="+data+"&language="+$("#DOMAIN").val();
									$("#track_frame").attr("src",surl);
								}
								else{eflag=0;}
								$("#EDUCATION").focus();
							    });
}

//Top bar

function regslidemtab(dname, hpscount) {
	for(var i=1; i<=hpscount; i++)
	{
			var divid = "rsdiv"+i;
			var tdivid = "rstab"+i;
			var tdividc = "rstabc"+i;			
			obj_$(divid).style.display="none";
			obj_$(tdivid).style.display="none";
			obj_$(tdividc).style.display="block";		
	}

	for(var i=1; i<=hpscount; i++)
	{
			var divid1 = "rsdiv"+i;
			var tdivid = "rstab"+i;
			var tdividc = "rstabc"+i;
			if(divid1==dname)
		{				
				obj_$(dname).style.display = "block";
				obj_$(tdivid).style.display = "block";
				obj_$(tdividc).style.display = "none";			
			}
		}
	}

$(window).load(function () 
{ 
	if($('input[name=REGISTERED_BY]').is(':checked')==true)
	{
		var re_by=$('input[name=REGISTERED_BY]:checked').val();
		if(re_by=="8"){gen_val="M";$("#uage").hide();}
		if(re_by=="9"){gen_val="F";$("#uage").hide();}
		if(re_by=="10"){gen_val="M";$("#uage").hide();}
		if(re_by=="11"){gen_val="F";$("#uage").hide();}

		if(re_by=="1")
		{
			$("#uage").hide();
			if($('input[name=GENDER]').is(':checked')==true)
			{
				gen_val=$('input[name=GENDER]:checked').val();
			}
		}

		if(re_by=="12")
		{
			$("#uage").show();
			if($('input[name=GENDER]').is(':checked')==true)
			{
				gen_val=$('input[name=GENDER]:checked').val();
			}
		}
	}

	//$("#RELIGION").val("0");$("#MOTHERTONGUE").val("0"); thava
	//commented this line for form based banner mail
	$("#COUNTRY").val("0");
	$("#religion_err").html(" ");$("#mtounge_err").html(" ");$("#country_err").html(" ");
 }); 

function frame_errmsg()
{
	var dval=$("#DOMAIN").val();
	var secondval=dsys_val;
	var utext=d_return(dval);var dtext=d_return(secondval);
	error["DOMAIN"]="<font color='red'>You have chosen to receive matches from "+utext+"Matrimony. We recommend "+dtext+"Matrimony as a suitable regional portal for you as it will enable you to get better and more matches.</font>";
}

function d_return(dval)
{
	if(dval==1){utext="Tamil";}
	if(dval==2){utext="Telugu";}
	if(dval==3){utext="Kerala";}
	if(dval==4){utext="Kannada";}
	if(dval==5){utext="Gujarati";}
	if(dval==6){utext="Marathi";}
	if(dval==7){utext="Bengali";}
	if(dval==8){utext="Punjabi";}
	if(dval==9){utext="Sindhi";}
	if(dval==10){utext="Hindi";}
	if(dval==11){utext="Oriya";}
	if(dval==12){utext="Parsi";}
	if(dval==13){utext="Assamese";}
	if(dval==14){utext="Marwadi";}	
	if(dval==15){utext="Urdu";}
	if(dval==0){utext="Bharat";}
	return utext;
}

function calculate_age(dobyear,dobmonth,dobday){	
	var diff = '';
	if(dobyear!=0 && dobmonth!=0 && dobday!=0){
		var today = new Date();		
		var dob = new Date(dobyear,dobmonth-1,dobday);
		var one_year = 1000*60*60*24*365.25;
		diff = today-dob;	
		diff = Math.floor(diff/one_year);
	}
	return diff;	
}

function updateDay(change,formName,yearName,monthName,dayName){
  var form = document.forms[formName];
  var yearSelect = form[yearName];
  var monthSelect = form[monthName];
  var daySelect = form[dayName];
  var year = yearSelect[yearSelect.selectedIndex].value;
  var month = monthSelect[monthSelect.selectedIndex].value;
  var day = daySelect[daySelect.selectedIndex].value;
  if(month>0){
     if(change == 'month' || (change == 'year' && month == 2)){
      var i=31;
      var flag = true;
      while(flag){
       var date = new Date(year,month-1,i);
       if(date.getMonth() == month - 1){
        flag = false;
       }else{
        i=i-1;
       }
      }
      daySelect.length = 0;
      daySelect.length = i;
      var j=1;
	  daySelect[0] = new Option('- Date -',0);
      while(j <= i){			 
       daySelect[j] = new Option(j,j);		  
       j=j+1;
      }
	  if(day>=i){
		  daySelect.selectedIndex = i;
	  }else if(day > 0 && day<i){
		  daySelect.selectedIndex = day;
	  }else{
		  daySelect.selectedIndex = 0;
	  }
     }
  }
}
