var Jsg_sws="";
function InitArray() {
	this.length=InitArray.arguments.length
	for (var i=0; i < this.length; i++)
	this[i+1]=InitArray.arguments[i]
}

function ValidateDate( Mon, Day, Year) {
	Months=new InitArray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var monthInt=Mon.options[Mon.selectedIndex].value;
	var dayInt=Day.options[Day.selectedIndex].value;
	var yearInt=Year.options[Year.selectedIndex].value;

	if(monthInt < 1 || monthInt > 12 || dayInt < 1 || dayInt > 31 || yearInt < 1997)
	return(false);

	if(dayInt > Months[ monthInt ] )
	if(monthInt != 2) return false;
	else  if(dayInt > 29) return false;
	else if(yearInt % 400==0) return true;
	else if(yearInt % 100==0) return false;
	else if(yearInt % 4 != 0) return false;
	return true;
}

function childlivingst() {		
	var frm=document.MatriForm;
	if(!frm.MARITAL_STATUS1.checked && !frm.MARITAL_STATUS2.checked && !frm.MARITAL_STATUS3.checked && !frm.MARITAL_STATUS4.checked) {
		if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
		frm.HAVECHILDREN[0].disabled=true;
		frm.HAVECHILDREN[1].disabled=true;		
		frm.HAVECHILDREN[2].disabled=true;
		frm.HAVECHILDREN[3].disabled=true;
		$BN("havechild_id1",'n');
		$BN("havechild_id2",'n');
		$BN("havechild_id3",'n');
		}
		frm.MARITAL_STATUS0.checked=true;
	}
	if(frm.MARITAL_STATUS1.checked && !frm.MARITAL_STATUS2.checked && !frm.MARITAL_STATUS3.checked && !frm.MARITAL_STATUS4.checked) {
		document.MatriForm.MARITAL_STATUS0.checked=false;
		if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
			frm.HAVECHILDREN[0].disabled=true;
			frm.HAVECHILDREN[1].disabled=true;		
			frm.HAVECHILDREN[2].disabled=true;
			frm.HAVECHILDREN[3].disabled=true;
			$BN("havechild_id1",'n');
			$BN("havechild_id2",'n');
			$BN("havechild_id3",'n');		
		}
	}
	else if(frm.MARITAL_STATUS2.checked){
		setMartialStatus(frm);
	}		
	else if(frm.MARITAL_STATUS3.checked){
		setMartialStatus(frm);
	}
	else if(frm.MARITAL_STATUS4.checked){
		setMartialStatus(frm);			
	}	
}	

function childlivingstany() {
var frm=document.MatriForm;
if (MatriForm.MARITAL_STATUS0.checked) {
	frm.MARITAL_STATUS1.checked=false;
	frm.MARITAL_STATUS2.checked=false;
	frm.MARITAL_STATUS3.checked=false;
	frm.MARITAL_STATUS4.checked=false;
	if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
		frm.HAVECHILDREN[0].disabled=false;
		frm.HAVECHILDREN[1].disabled=false;
		frm.HAVECHILDREN[2].disabled=false;
		frm.HAVECHILDREN[3].disabled=false;
		$BN("havechild_id1",'b');
		$BN("havechild_id2",'b');
		$BN("havechild_id3",'b');
	}
}
}

function setMartialStatus(frm) {
	document.MatriForm.MARITAL_STATUS0.checked=false;		
	if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
	frm.HAVECHILDREN[0].disabled=false;
	frm.HAVECHILDREN[1].disabled=false;		
	frm.HAVECHILDREN[2].disabled=false;
	frm.HAVECHILDREN[3].disabled=false;
	$BN("havechild_id1",'b');
	$BN("havechild_id2",'b');
	$BN("havechild_id3",'b');
	}
}

function frmvalidate() {
	var MatriForm=this.document.MatriForm;

	if(!validateGender(MatriForm,'gendererr')) {
		return false;
	}
	if(!validateAge(MatriForm,'ageerr')) {
		return false;
	}
	if(!validateHeight(MatriForm,'heighterr')) {
		return false;
	}
	if(Jsg_sws=="subc"){
		if(!validateReligion(MatriForm,'religionerr')) {
			return false;
		}
		if(MatriForm.SUBCASTE1){
			if(MatriForm.SUBCASTE1.length>30){
				alert("Sorry, you can select only up to 30 Subcaste in your search criteria.");
				MatriForm.SUBCASTE1.focus();
				return false;
			}
		}
		if(MatriForm.GOTHRA1){
			if(MatriForm.GOTHRA1.length>30){
				alert("Sorry, you can select only up to 30 Gothras in your search criteria.");
				MatriForm.GOTHRA1.focus();
				return false;
			}
		}
		if(gothratxtflg=="Y") {
			if(!validateGothra(MatriForm,'gothraerr')) {
				return false;
			}
		}
	}
	if(MatriForm.DAYS[1].checked && !ValidateDate( MatriForm.ST_MONTH, MatriForm.ST_DAY, MatriForm.ST_YEAR)) {
		$("dateerr").innerHTML="Sorry, "+MatriForm.ST_MONTH.options[MatriForm.ST_MONTH.selectedIndex].text +
		 " " + MatriForm.ST_DAY.options[MatriForm.ST_DAY.selectedIndex].text + 
		 " " + MatriForm.ST_YEAR.value + " is not a valid date.";
		MatriForm.ST_MONTH.focus();
		return false;
	}
	return true;
}

function validate() {
	if (frmvalidate()==true) {
		selall();
        var f=document.MatriForm;
		var js_randid=$genNumbers();
		f.randid.value=js_randid;
		var filepath="/search/smartsearch.php?randid="+js_randid;
		if(arguments[0]=="rmi"){
            f.action=filepath+"&RMIID="+arguments[0];
		} else {
			f.action=filepath;
		}
		document.MatriForm.submit();
		return true;
	}
	else {
		return false;
	}
}

function savevalidate() {
	if (frmvalidate()==true) {		
		if(multiple_save()==true) {
			selall();
			var js_randid=$genNumbers();
			document.MatriForm.randid.value=js_randid;
			document.MatriForm.action="/search/smartsearch.php?randid="+js_randid;
			document.MatriForm.submit();
			return false;
		}
		else {return false;}
	}
	else {return false;}
}

function multiple_save(){
	if(IsEmpty(document.ss1.search_name,'text'))	{
		$("saveeerr").innerHTML="Please enter a name for your search.";
		document.ss1.search_name.focus();
		return false;
	} else {
		$("saveeerr").innerHTML="";
		document.MatriForm.search_name.value=document.ss1.search_name.value;
		document.MatriForm.but_save.value=1;
		return true;
	}
}

function check_div_status() {
	var edu_blk=$('edublock-off');
	var loc_blk=$('locblock-off');
	var ast_blk=$('astblock-off');
	var life_blk=$('lifeblock-off');
	var hid_val="";

	if (edu_blk.style.display=="block") {
		hid_val+="1";
	}
	else {
		hid_val+="0";
	}

	hid_val+="~";
	if (loc_blk.style.display=="block") {
		hid_val+="1";
	}
	else {
		hid_val+="0";
	}

	hid_val+="~";
	if (ast_blk.style.display=="block") {
		hid_val+="1";
	}
	else {
		hid_val+="0";
	}

	hid_val+="~";
	if (life_blk.style.display=="block") {
		hid_val+="1";
	}
	else {
		hid_val+="0";
	}
}

function state_div_enable_disable(show_status) {
	if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
	$BN('state_id2',show_status);
	$BN('state_id3',show_status);	
	}
}
function city_div_enable_disable(show_status) {
	if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
	$BN('city_id1',show_status);
	$BN('city_id2',show_status);
	$BN('city_id3',show_status);
   }
}

function pop_country_state(){
var country_len=selected_country.length	
var ind_len=selected_ind_states.length;
var usa_len=selected_usa_states.length;
var state_enable_flag=false;
var city_enable_flag=false;
var m=0, retain=m, len=0, opt=0, city_opt=0,cnt_name=0;
state_div_enable_disable('n');
city_div_enable_disable('n');
if(country_len>0){	
		for(j in selected_country)
		{	
			cnt_name=selected_country[j]; //get country id			
			if(cnt_name==98 || cnt_name==222)
			{
			state_enable_flag=true;
			len=states[cnt_name].length;
			for(m=0;m<len;m++)
			{	
				var sta_arr=states[cnt_name][m];
				var s_val=sta_arr.split("|");
				document.MatriForm.RESIDINGSTATE.options[retain]=new Option(s_val[0],s_val[1]);
				for(var r=0;r<ind_len;r++)
				{		
					
					if(selected_ind_states[r]==s_val[1])  //check for indian state names to be selected
					{
					document.MatriForm.RESIDINGSTATE.options[retain].selected=true;
					document.MatriForm.RESIDINGSTATE1.options[opt]=new Option(s_val[0],s_val[1]);
					document.MatriForm.RESIDINGSTATE1.options[opt].selected=true;
					opt++;
					var dist_len=selected_ind_dist.length;
					var st_name=selected_ind_states[r];		//get state id												
					var cit_len=cities[st_name].length;
					for(var c=0;c<cit_len;c++)
					{
						city_enable_flag=true;
						var c_arr=cities[st_name][c];
						var c_val=c_arr.split("|");
						document.MatriForm.RESIDINGCITY.options[city_opt]=new Option(c_val[0],c_val[1]);					
						for(var d=0;d<dist_len;d++)
						{
						if(c_val[1]==selected_ind_dist[d]) //check for city names to be selected
						{							
						document.MatriForm.RESIDINGCITY.options[city_opt].selected=true;
						document.MatriForm.RESIDINGCITY1.options[d]=new Option(c_val[0],c_val[1]);
						document.MatriForm.RESIDINGCITY1.options[d].selected=true;							
						} //if
						}  //for
						city_opt++;
					} //for
					}	//if						
				} //for
				for(var u=0;u<usa_len;u++)
				{
					city_enable_flag=true;
					if(selected_usa_states[u]==s_val[1])  //check for usa state names to be selected
					{
					document.MatriForm.RESIDINGSTATE.options[retain].selected=true;
					document.MatriForm.RESIDINGSTATE1.options[opt]=new Option(s_val[0],s_val[1]);
					document.MatriForm.RESIDINGSTATE1.options[opt].selected=true;
					opt++;
					}
				}
				retain++;
			}
			}
		} 
	}
	if(state_enable_flag==true) {
		state_div_enable_disable('b');
	}
	if(city_enable_flag==true) {
		city_div_enable_disable('b');
	}
}

function view_all(showall) {
	var st="";
	if(showall=="viewall") 
		st="b";	
	else 
		st="n"; 
	srchblocking('edublock-off','edu-img',st);
	srchblocking('locblock-off','loc-img',st);
	srchblocking('astblock-off','ast-img',st);
	srchblocking('lifeblock-off','life-img',st);
	srchblocking('keywords-off','key-img',st);
}

function srchblocking(tag,im,newState) {
	if ($(tag)!="") {
		var state=$(tag).style.display;		
	}
	if(newState=='') {
		if(state=="block") {
			newState="n";
			$(im).src="http://"+DOMAINARRAY['domainnameimgs']+"/bmimages/hob-minus-icon.gif";
		} else {
			newState="b";
			$(im).src="http://"+DOMAINARRAY['domainnameimgs']+"/bmimages/hob-plus-icon.gif";
		}
	}
	else {
		if(newState=='n') {
			$(im).src="http://"+DOMAINARRAY['domainnameimgs']+"/bmimages/hob-minus-icon.gif";
		} else {
			$(im).src="http://"+DOMAINARRAY['domainnameimgs']+"/bmimages/hob-plus-icon.gif";
		}
	}
	if ($(tag)!="") {
		$BN(tag,newState);
	} 	
}

var NS4=(navigator.appName=="Netscape" && parseInt(navigator.appVersion) < 5);
function addOption(theSel, theText, theValue){
	var newOpt=new Option(theText, theValue);
	var selLength=theSel.length;
	theSel.options[selLength]=newOpt;
}

function deleteOption(theSel, theIndex){	
	var selLength=theSel.length;
	if(selLength>0)	{
		theSel.options[theIndex]=null;
	}
}

function moveOptions(theSelFrom, theSelTo){	
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou1=1;
	var adflag=0;
	var i;
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			for(j=0;j<theSelTo.length;j++)
			{
				cou1=1;
				if(theSelTo.options[j].text==theSelFrom.options[i].text)
				{cou1=0}
			}	
			
			if (cou1==1) {
			selectedText[selectedCount]=theSelFrom.options[i].text;
			selectedValues[selectedCount]=theSelFrom.options[i].value;
			selectedCount++;
			}
		}			
	}
	
	if (theSelTo.length>0)	{
			for(i=selectedCount-1; i>=0; i--){	
				adflag=0;
				for (j=0;j<theSelTo.length;j++)	{
					if(selectedText[i]==theSelTo.options[j].text && adflag==0)
					{adflag=1}
				}
				if(adflag==0){addOption(theSelTo, selectedText[i], selectedValues[i]);}
			}
	}
	else
	{
		for(i=selectedCount-1; i>=0; i--)
		{ addOption(theSelTo, selectedText[i], selectedValues[i]);}	
	}

	if(NS4) history.go(0);
}
function moveOptions_occ(theSelFrom, theSelTo)
{		
	var selLength=eval($(theSelFrom).length);
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou1=1;
	var adflag=0;
	var i;
	var sel1;var sel2
	sel1=$(theSelFrom);
	sel2=$(theSelTo);

	for(i=selLength-1; i>=0; i--)
	{
		if(sel1.options[i].selected)
		{
			for(j=0;j<sel2.length;j++)
			{
				cou1=1;
				if(sel2.options[j].text==sel1.options[i].text)
				{cou1=0}
			}	
			
			if (cou1==1) {
			selectedText[selectedCount]=sel1.options[i].text;
			selectedValues[selectedCount]=sel1.options[i].value;
			selectedCount++;
			}
		}			
	}
	
	if (sel2.length>0)
	{

			for(i=selectedCount-1; i>=0; i--)
			{	
				adflag=0;
				for (j=0;j<sel2.length;j++)
				{
					if(selectedText[i]==sel2.options[j].text && adflag==0)
					{adflag=1}
				}
				if(adflag==0){addOption(sel2, selectedText[i], selectedValues[i]);}
			}
	}
	else
	{
		for(i=selectedCount-1; i>=0; i--)
		{ addOption(sel2, selectedText[i], selectedValues[i]);}	
	}

	if(NS4) history.go(0);
}

function moveOptions1(theSelFrom, theSelTo)
{
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var i;

	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount]=theSelFrom.options[i].text;
			selectedValues[selectedCount]=theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}
	if(NS4) history.go(0);
}

//Moving Country
//*********************

function CaddOption(theSel, theText, theValue)
{
	var newOpt=new Option(theText, theValue);
	var selLength=theSel.length;
	theSel.options[selLength]=newOpt;
	
	if(theSel.id=="COUNTRY1")
	{
		if (theValue=="98") {
			updatestate("India",'RESIDINGSTATE','states');
		}
		else if (theValue=="222") {
			updatestate("United States of America",'RESIDINGSTATE','states');
		}
	}
	
	if(theSel.id=="RESIDINGSTATE1")
	{
		for (i=0;i<states['India'].length;i++)
		{
			if (states['India'][i]==theValue)
			updatecity(theText,'RESIDINGCITY','cities');
		}
	}
}

function CdeleteOption(theSel, theIndex)
{	
	var selLength=theSel.length;
	if(selLength>0)
	{
		theSel.options[theIndex]=null;
	}
}

function CmoveOptions(theSelFrom, theSelTo)
{	
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou1=1;
	var adflag=0;
	var i;
	
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			for(j=0;j<theSelTo.length;j++)
			{
				cou1=1;
				if(theSelTo.options[j].text==theSelFrom.options[i].text)
				{cou1=0}
			}	
			
			if (cou1==1) {
			selectedText[selectedCount]=theSelFrom.options[i].text;
			selectedValues[selectedCount]=theSelFrom.options[i].value;
			selectedCount++;
			}
		}			
	}
	
	if (theSelTo.length>0)
	{

			for(i=selectedCount-1; i>=0; i--)
			{	
				adflag=0;
				for (j=0;j<theSelTo.length;j++)
				{
					if(selectedText[i]==theSelTo.options[j].text && adflag==0)
					{adflag=1}
				}
				if(adflag==0){CaddOption(theSelTo, selectedText[i], selectedValues[i]);}
			}
	}
	else
	{
		for(i=selectedCount-1; i>=0; i--)
		{CaddOption(theSelTo, selectedText[i], selectedValues[i]);}	
	}

	if(NS4) history.go(0);
}

function countrymove(theSelFrom, theSelTo)
{
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou;
	var i;
	
//Removal of States and Cities
if (theSelFrom.id=="COUNTRY1")
{
for(i=selLength-1; i>=0; i--)
{
	if(theSelFrom.options[i].selected)
	{
	if (theSelFrom.options[i].value==98 || theSelFrom.options[i].value==222)
	{
			for (j=0;j<states[theSelFrom.options[i].text].length;j++)
			{		
				for (k=0;k<document.MatriForm.RESIDINGSTATE.length;k++)
				{
					if (document.MatriForm.RESIDINGSTATE.options[k].text==states[theSelFrom.options[i].text][j])
					{
						for (m=0;m<document.MatriForm.RESIDINGSTATE1.length;m++)
						{
							if(theSelFrom.options[i].value==98)
							{
								var ci=document.MatriForm.RESIDINGSTATE1.options[m].text;
								for (r=0;r<states['India'].length;r++)
								{
									if (states['India'][r]==ci)
									{
										for (n=0;n<cities[ci].length;n++)
										{
											for(p=0;p<document.MatriForm.RESIDINGCITY.length;p++)
											{
												for (q=0;q<document.MatriForm.RESIDINGCITY1.length;q++)
												{
													if(document.MatriForm.RESIDINGCITY1.options[q].text==document.MatriForm.RESIDINGCITY.options[p].text){document.MatriForm.RESIDINGCITY1.remove(q);}
												}
												if(document.MatriForm.RESIDINGCITY.options[p].text==cities[ci][n]){document.MatriForm.RESIDINGCITY.remove(p)}
											}
										}
									}
								}
							}
							if(document.MatriForm.RESIDINGSTATE1.options[m].text==document.MatriForm.RESIDINGSTATE.options[k].text)
							document.MatriForm.RESIDINGSTATE1.remove(m);	
						}
						document.MatriForm.RESIDINGSTATE.remove(k);	
					}
				}
			}
				selectedCount++;
		}
}
}
}

	citymove(document.MatriForm.COUNTRY1,document.MatriForm.COUNTRY);
	if(NS4) history.go(0);
}

function statemove(theSelFrom, theSelTo)
{
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou;
	var i;
//Removal of Cities
if (theSelFrom.id=="RESIDINGSTATE1")
{
for(i=selLength-1; i>=0; i--)
{
	if(theSelFrom.options[i].selected)
	{
	for (t=0;t<states['India'].length;t++)
	{
		if (states['India'][t]==theSelFrom.options[i].text)
		{
			for (j=0;j<cities[theSelFrom.options[i].text].length;j++)
			{
				for (k=0;k<document.MatriForm.RESIDINGCITY.length;k++)
				{
					if (document.MatriForm.RESIDINGCITY.options[k].text==cities[theSelFrom.options[i].text][j])
					{
						for (m=0;m<document.MatriForm.RESIDINGCITY1.length;m++)
						{if(document.MatriForm.RESIDINGCITY1.options[m].text==document.MatriForm.RESIDINGCITY.options[k].text){document.MatriForm.RESIDINGCITY1.remove(m)}	}
						document.MatriForm.RESIDINGCITY.remove(k);	
					}
				}
			}
		}
	}
		selectedCount++;
	}
}
}
	citymove(document.MatriForm.RESIDINGSTATE1,document.MatriForm.RESIDINGSTATE);
	if(NS4) history.go(0);
}

function citymove(theSelFrom, theSelTo) {
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou, i;

	for(i=selLength-1; i>=0; i--) {
		if(theSelFrom.options[i].selected) {
			CdeleteOption(theSelFrom, i);
			selectedCount++;
		}			
	}	
	if(NS4) history.go(0);
}

function updatestate(j,obj,aryname)
{
	var aryname=eval(aryname);
	var obj1=$(obj);
	for (var i=0; i<aryname[j].length; i++)
	{obj1.options[obj1.options.length]=new Option(aryname[j][i],aryname[j][i])}
}

function updatecity(j,obj,aryname)
{
	var aryname=eval(aryname);
	var obj1=$(obj);
		for (var i=0; i<aryname[j].length; i++)
		{obj1.options[obj1.options.length]=new Option(aryname[j][i],aryname[j][i])}
}

function country_addOption(theSel, theText, theValue) {
	var newOpt=new Option(theText, theValue);
	var selLength=theSel.length;
	theSel.options[selLength]=newOpt;
	
		if(theSel.id=="COUNTRY1")//country2
		{
			if (theValue==98 || theValue==222) {
				if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
					state_div_enable_disable('b');
					country_updatestate(theValue,'RESIDINGSTATE','states');
				}
				}//state1
			}
	
		if(theSel.id=="RESIDINGSTATE1") {
			if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
				country_updatecity(theValue,'RESIDINGCITY','cities');//city1
			}
		}
}

function country_deleteOption(theSel, theIndex) {	
	var selLength=theSel.length;
	if(selLength>0) {
		theSel.options[theIndex]=null;
	}
}

function country_moveOptions(theSelFrom, theSelTo) {
	var divid="";
	if(arguments[2]=="COUNTRY") {
		divid="countryerr";
	}
	if(arguments[2]=="RESIDINGSTATE") {
		divid="stateerr";
	}
	$(divid).innerHTML="";
	
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou1;
	var i;
	
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			for(j=0;j<theSelTo.length;j++)
			{
				if(theSelTo.options[j].text==theSelFrom.options[i].text)
				{cou1=0}
			}	
			if (cou1!=0)
			{
			selectedText[selectedCount]=theSelFrom.options[i].text;
			selectedValues[selectedCount]=theSelFrom.options[i].value;
			selectedCount++;
			}

		}			
	}

		var tp_c=theSelTo.length;

			for(i=selectedCount-1; i>=0; i--)
			{
				country_addOption(theSelTo, selectedText[i], selectedValues[i]);
				tp_c++;
			}
	
	if(NS4) history.go(0);
}

function country_moveOptions1(theSelFrom, theSelTo)
{
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou;
	var i;
	var cres;
	$("countryerr").innerHTML="";
//Removal of States and Cities
if (theSelFrom.id=="COUNTRY1" && document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH")   //country2
{
for(i=selLength-1; i>=0; i--)
{
	if(theSelFrom.options[i].selected)
	{
		if (theSelFrom.options[i].value==98 || theSelFrom.options[i].value==222)
		//if (theSelFrom.options[i].value==98)
		{
			for (j=0;j<states[theSelFrom.options[i].value].length;j++)
			{		
				for (k=0;k<document.MatriForm.RESIDINGSTATE.length;k++)
				{
					if (document.MatriForm.RESIDINGSTATE.options[k].value==states[theSelFrom.options[i].value][j].split("|")[1])
					{document.MatriForm.RESIDINGSTATE.remove(k);}
				}
				
				for (m=0;m<document.MatriForm.RESIDINGSTATE1.length;m++)
				{
					if (document.MatriForm.RESIDINGSTATE1.options[m].value==states[theSelFrom.options[i].value][j].split("|")[1])
					{document.MatriForm.RESIDINGSTATE1.remove(m);}
				}

			}

			if (theSelFrom.options[i].value==98)
			{
					city_div_enable_disable('n');
					for (var p=0;p<document.MatriForm.RESIDINGCITY.length;) 
					{
					if (document.MatriForm.RESIDINGCITY.options[p])
					{document.MatriForm.RESIDINGCITY.remove(p);}
					else {p++;};
					};
								
					for (var q=0;q<document.MatriForm.RESIDINGCITY1.length;) 
					{
					if (document.MatriForm.RESIDINGCITY1.options[q])
					{document.MatriForm.RESIDINGCITY1.remove(q);}
					else {q++;};
					};
			}

			selectedCount++;
		}
	}
	}
}
	
	country_moveOptions3(document.MatriForm.COUNTRY1,document.MatriForm.COUNTRY);
	country_based_enable_disable(document.MatriForm.COUNTRY1);
	if(NS4) history.go(0);
}
function country_based_enable_disable(theSelFrom) {
	var selLength=theSelFrom.length;
	var state_flag=true;
	if (theSelFrom.id=="COUNTRY1" && document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH")   //country2 
	{
		for(i=selLength-1; i>=0; i--)
		{
			if (theSelFrom.options[i].value==98 || theSelFrom.options[i].value==222) {
				state_flag=false;
			}
		}
	}
	if(state_flag==true) {
		state_div_enable_disable('n');
	}
}
function country_moveOptions2(theSelFrom, theSelTo)
{
var selLength=theSelFrom.length;
var cselectedText=new Array();
var cselectedValues=new Array();
var cselectedCount=0;
var cou;
var i;
//Removal of Cities

	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			cselectedText[cselectedCount]=theSelFrom.options[i].text;
			cselectedValues[cselectedCount]=theSelFrom.options[i].value;
			cselectedCount++;
		}
	}

	for(d=cselectedCount-1; d>=0; d--)
	{
		var stobj=cselectedValues[d];
		if(stobj.substr(0,2)==98)
		{
		for (t=0;t<cities[stobj].length;t++)
		{
			for (k=0;k<document.MatriForm.RESIDINGCITY.length;k++)
			{
				if (document.MatriForm.RESIDINGCITY.options[k].value==cities[stobj][t].split("|")[1])
				{document.MatriForm.RESIDINGCITY.remove(k);}
			}

			for (g=0;g<document.MatriForm.RESIDINGCITY1.length;g++)
			{
				if (document.MatriForm.RESIDINGCITY1.options[g].value==cities[stobj][t].split("|")[1])
				{document.MatriForm.RESIDINGCITY1.remove(g);}
			}
		}
		}
	}
	
country_moveOptions3(document.MatriForm.RESIDINGSTATE1,document.MatriForm.RESIDINGSTATE);
state_based_enable_disable(document.MatriForm.RESIDINGSTATE1);
if(NS4) history.go(0);
}

function state_based_enable_disable(theSelFrom) {
	var selLength=theSelFrom.length;
	var cselectedText=new Array();
	var cselectedValues=new Array();
	var cselectedCount=0;
	var city_flag=true;
	for(i=selLength-1; i>=0; i--)
	{
		cselectedValues[cselectedCount]=theSelFrom.options[i].value;
		cselectedCount++;
	}
	for(d=cselectedCount-1; d>=0; d--)
	{
		var stobj=cselectedValues[d];
		if(stobj.substr(0,2)==98)
		{
			city_flag=false;
			break;
		}
	}
	if(city_flag==true) {
		city_div_enable_disable('n');
	}
}

function country_moveOptions3(theSelFrom, theSelTo)
{
	var selLength=theSelFrom.length;
	var selectedText=new Array();
	var selectedValues=new Array();
	var selectedCount=0;
	var cou;
	
	var i;
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			country_deleteOption(theSelFrom, i);
			selectedCount++;
		}			
	}	
	if(NS4) history.go(0);
}


function country_updatestate(j,obj,aryname)
{	
	var aryname=eval(aryname);
	var obj1=$(obj);
	for (var i=0; i<aryname[j].length; i++)
	{
		obj1.options[obj1.options.length]=new Option(aryname[j][i].split("|")[0],aryname[j][i].split("|")[1])
	}
}  

function country_updatecity(j,obj,aryname)
{
	var aryname=eval(aryname);
	var obj1=$(obj);
	if(j.substr(0,2)==98)
	{
		city_div_enable_disable('b');
		for (var i=0; i<aryname[j].length; i++)
		{obj1.options[obj1.options.length]=new Option(aryname[j][i].split("|")[0],aryname[j][i].split("|")[1])}
	}
}

function selall()
{
		var frm =document.MatriForm;

		if(Jsg_sws=="subc"){
			if(document.MatriForm.SUBCASTE1) {
				for(var i=0;i < frm.SUBCASTE1.length;i++)
				{frm.SUBCASTE1.options[i].selected=true;}
			}
			if(document.MatriForm.GOTHRA1) {
				for(var i=0;i < frm.GOTHRA1.length;i++)
				{frm.GOTHRA1.options[i].selected=true;}
			}
		}
		else {
			for(var i=0;i < frm.LANGUAGE.length;i++)
			{frm.LANGUAGE.options[i].selected=true;}

			for(var i=0;i < frm.CASTE1.length;i++)
			{frm.CASTE1.options[i].selected=true;}
		}
		for(var i=0;i < frm.EDUCATION1.length;i++)
		{frm.EDUCATION1.options[i].selected=true;}

		for(var i=0;i < frm.CITIZENSHIP1.length;i++)
		{frm.CITIZENSHIP1.options[i].selected=true;}

		for(var i=0;i < frm.COUNTRY1.length;i++)
		{frm.COUNTRY1.options[i].selected=true;}

		if(document.MatriForm.SEARCH_TYPE.value=="ADVANCESEARCH") {
			for(var i=0;i < frm.MOTHERTONGUE1.length;i++)
			{frm.MOTHERTONGUE1.options[i].selected=true;}

			for(var i=0;i < frm.OCCUPATION1.length;i++)
			{frm.OCCUPATION1.options[i].selected=true;}

			for(var i=0;i < frm.RESIDINGSTATE1.length;i++)
			{frm.RESIDINGSTATE1.options[i].selected=true;}
			
			for(var i=0;i < frm.RESIDINGCITY1.length;i++)
			{frm.RESIDINGCITY1.options[i].selected=true;}

			for(var i=0;i < frm.STAR1.length;i++)
			{frm.STAR1.options[i].selected=true;}
		}
}

function checkGenderAge(sf) {
	for(var i=0;i<2;i++){
		if(sf.GENDER[i].checked==true) {
			var GENDER=sf.GENDER[i].value;
		}
	}	
	if(Jsg_memberid!="") {
		if(Jsg_loggedin_gender=="F") {
			if(GENDER=="F") 
				sf.STAGE.value=18;
			else 
				sf.STAGE.value=sf.ppage.value;
		} else {
			if(GENDER=="F") 
				sf.STAGE.value=sf.ppage.value;
			else 
				sf.STAGE.value=21;		
		}

	} else {
		if(GENDER=="F") 
			sf.STAGE.value=18;
		else
			sf.STAGE.value=21;	
	}
}

function validateAge(sf,did) {
	var minage=0;
	var maxage=70;
	stAge=sf.STAGE.value;
	endAge=sf.ENDAGE.value;	
	if(arguments[2]!="" && arguments[2]!="undefined" && arguments[2]!=undefined) {
		var GENDER=arguments[2];
	} else {
		for(var i=0;i<2;i++){
			if(sf.GENDER[i].checked==true) {
				var GENDER=sf.GENDER[i].value;  
			}
		}
	}

	(GENDER=="F") ? minage=18 : minage=21;			
	var FINALAGE=parseInt(endAge)-parseInt(stAge);
	$BN(did,'b');

	if(IsEmpty(sf.STAGE,"text")) {
		agefocus();
		$(did).innerHTML="Please enter the age range.";
		return false;
	} else if(!(CompareValue(sf.STAGE.value,"0123456789"))) {
		agefocus();
		$(did).innerHTML="Sorry, Invalid Age "+stAge+".";
		return false;
	} else if(IsEmpty(sf.ENDAGE, "text")) {
		$(did).innerHTML="Please enter the age range.";
		return false;
	}  else if(!(CompareValue(sf.ENDAGE.value,"0123456789"))) {
		agefocus();
		$(did).innerHTML="Sorry, Invalid Age "+endAge+".";
		return false;
	} else if(stAge!=0 && endAge<stAge) {
		agefocus();
		$(did).innerHTML="Sorry, Invalid age range. "+stAge+" to "+endAge+".";
		return false;
	} else if(stAge < minage || stAge > maxage) {
		agefocus();
		$(did).innerHTML= "Sorry, invalid age "+stAge+" (Min. age is "+minage+". Max. age is "+maxage+")." ;
		return false;
	} else if(parseInt(stAge)<18 || parseInt(stAge)>maxage) {
		agefocus();
		$(did).innerHTML="Sorry, invalid age "+stAge+" (Min. age is "+minage+". Max. age is "+maxage+").";	
		return false;
	} else if(parseInt(FINALAGE)>22) {
		agefocus();
		$(did).innerHTML="The difference between a partner's \"From\" and \"To\" age should not exceed 22 years.";
		return false;	
	} else {
		$BN(did,'n');
		$(did).innerHTML="&nbsp;";
		return true;
	}	
}

function agefocus() {
	window.location.href="#agf";
}

function validateGender(sf,did) {
	if(IsEmpty(sf.GENDER,"radio")) {
		$BN(did,'b');
		window.location.href="#gdf";
		$(did).innerHTML="Please select the Looking For.";
		sf.GENDER[0].focus();
		return false;
	} else {
		$BN(did,'n');
		return true;
	}
}

function validateHeight(sf,did) {
	if (sf.ENDHEIGHT.selectedIndex  < sf.STHEIGHT.selectedIndex) {	
		$BN(did,'b');
		$(did).innerHTML="Sorry, invalid height range.";
		window.location.href="#htf";
		return false;
	} else {
		$BN(did,'n');
		return true;
	}
}

function validateReligion(sf,did) {
	if (sf.RELIGION1.selectedIndex<=0) {	
		$BN(did,'b');
		$(did).innerHTML="Please select religion.";
		window.location.href="#rtf";
		return false;
	} else {
		$BN(did,'n');
		return true;
	}
}

function validateGothra(sf,did) {
	if (sf.OTHERGOTHRA.value=='') {	
		$BN(did,'b');
		$(did).innerHTML="Please enter Gothra(m) of the prospect.";
		window.location.href="#gothraf";
		return false;
	} else {
		$BN(did,'n');
		return true;
	}
}

function validateKeyword(sf,did,v) {
	if(IsEmpty(sf.keytext, "text")) {
		$BN(did,'b');
		$(did).innerHTML="Please enter the keywords.";
		if(v=='') {
			sf.keytext.focus();
		}
		return false;
	} else if(sf.keytext.value.length<3) {
		$BN(did,'b');
		$(did).innerHTML="The keywords should have a minimum of 3 characters.";
		sf.keytext.focus();
		return false;
	}
	else {
		$BN(did,'n');
		return true;
	}
} 

function members_frmvalidate() {
	var MatriForm=document.MatriForm;

	if(!validateGender(MatriForm,'gendererr')) {
		return false;
	}
	if(!validateAge(MatriForm,'ageerr')) {
		return false;
	}
	if(!validateHeight(MatriForm,'heighterr')) {
		return false;
	}
			
	if (!MatriForm.MARITAL_STATUS0.checked && !MatriForm.MARITAL_STATUS1.checked && !MatriForm.MARITAL_STATUS2.checked && !MatriForm.MARITAL_STATUS3.checked && !MatriForm.MARITAL_STATUS4.checked) {
		$BN("maritalerr",'b');
		window.location.href="#msf";		
		$("maritalerr").innerHTML="Please select the type of person you are looking for.";
		return false;
	}
	membersonline_selall();
	document.MatriForm.action="/search/smartsearch.php?";
	document.MatriForm.submit();
	return true;
}

function membersonline_selall() {
	var frm =document.MatriForm;
	for(var i=0;i < frm.LANGUAGE.length;i++)
	{frm.LANGUAGE.options[i].selected=true;}

	for(var i=0;i < frm.CASTE1.length;i++)
	{frm.CASTE1.options[i].selected=true;}
	
	for(var i=0;i < frm.COUNTRY1.length;i++)
	{frm.COUNTRY1.options[i].selected=true;}
}

function savesrch_overlay(curobj, srch_saveobj){
	if (document.getElementById){
		var srch_saveobj=document.getElementById(srch_saveobj)
		srch_saveobj.style.left=savesrch_getposOffset(curobj, "left")-183+"px"
		srch_saveobj.style.top=savesrch_getposOffset(curobj, "top")-130+"px"
		srch_saveobj.style.display="block"
		document.ss1.search_name.focus();
		return false
	}
	else
		return true
}

function savesrch_getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function savesrch_overlayclose(srch_saveobj){
	document.getElementById(srch_saveobj).style.display="none"
}

function clickIE() {if (document.all) {return false;}}
function clickNS(e) { if(document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {return false;}}}

if (document.layers) { document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS; }
else { document.onmouseup=clickNS;document.oncontextmenu=clickIE; }
document.oncontextmenu=new Function("return false");

function srch_in_array(string, array)  
 {  
    for (i = 0; i < array.length; i++)  
    {  
       if(array[i] == string)  
       {  
          return true;  
       }  
    }  
 return false;  
} 
