var js_randid; var version=0;
var action_path = "smartsearch";

if(navigator.appVersion.indexOf("MSIE")!=-1) {
	temp = navigator.appVersion.split("MSIE");
	version = parseFloat(temp[1]);
}

if(((parseInt(version) < 5.5) && js_br=="I") || js_br=="N" || js_br=="O" || js_br=="S") {
	action_path = "dosearch";
}

function genNumbers() {
  var i, rannum;

  for(i = 1000000; i < 1000010; i++) {
    rannum = Math.random()*1000000;
    rannum = Math.round(rannum);
  }
  var rand_flag = "a"+rannum+"s";
  return rand_flag;
}

function IsEmpty(obj, obj_type)
{
	if (obj_type == "text")	
	{
		var objValue;
		objValue = obj.value.replace(/\s+$/,"");	
			if (objValue.length == 0) 
			{
			return true;
			}
			else {return false;}
	}
}

	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()
	{	
		if ( MatriForm.MARITAL_STATUS1.checked && !MatriForm.MARITAL_STATUS2.checked && !MatriForm.MARITAL_STATUS3.checked && !MatriForm.MARITAL_STATUS4.checked)
		{
			document.MatriForm.MARITAL_STATUS0.checked=false;		
			document.MatriForm.HAVECHILDREN[0].disabled=true;
			document.MatriForm.HAVECHILDREN[1].disabled=true;		
			document.MatriForm.HAVECHILDREN[2].disabled=true;
			document.MatriForm.HAVECHILDREN[3].disabled=true;			
		}	
		else if ( MatriForm.MARITAL_STATUS2.checked)
		{
			document.MatriForm.MARITAL_STATUS0.checked=false;					
			document.MatriForm.HAVECHILDREN[0].disabled=false;
			document.MatriForm.HAVECHILDREN[1].disabled=false;		
			document.MatriForm.HAVECHILDREN[2].disabled=false;			
			document.MatriForm.HAVECHILDREN[3].disabled=false;
		}
		else if ( MatriForm.MARITAL_STATUS3.checked)
		{
			document.MatriForm.MARITAL_STATUS0.checked=false;					
			document.MatriForm.HAVECHILDREN[0].disabled=false;
			document.MatriForm.HAVECHILDREN[1].disabled=false;		
			document.MatriForm.HAVECHILDREN[2].disabled=false;
			document.MatriForm.HAVECHILDREN[3].disabled=false;						
		}		
		else if ( MatriForm.MARITAL_STATUS4.checked)
		{
			document.MatriForm.MARITAL_STATUS0.checked=false;					
			document.MatriForm.HAVECHILDREN[0].disabled=false;
			document.MatriForm.HAVECHILDREN[1].disabled=false;		
			document.MatriForm.HAVECHILDREN[2].disabled=false;
			document.MatriForm.HAVECHILDREN[3].disabled=false;						
		}				
	}	
	function childlivingstany()
	{	
		if ( MatriForm.MARITAL_STATUS0.checked)
		{
			document.MatriForm.MARITAL_STATUS1.checked=false;					
			document.MatriForm.MARITAL_STATUS2.checked=false;					
			document.MatriForm.MARITAL_STATUS3.checked=false;										
			document.MatriForm.MARITAL_STATUS4.checked=false;													
			document.MatriForm.HAVECHILDREN[0].disabled=false;
			document.MatriForm.HAVECHILDREN[1].disabled=false;		
			document.MatriForm.HAVECHILDREN[2].disabled=false;			
			document.MatriForm.HAVECHILDREN[3].disabled=false;
		}				
	}
	function ValidateNo( NumStr, String ) 
	{
 		for( var Idx = 0; Idx < NumStr.length; Idx ++ )
 		{
			 var Char = NumStr.charAt( Idx );
			 var Match = false;

				for( var Idx1 = 0; Idx1 < String.length; Idx1 ++) 
				{
					 if( Char == String.charAt( Idx1 ) ) 
					 Match = true;
				}

				if ( !Match ) 
					return false;
 		}

		return true;
	}

	// Function to validate all the inputs
	function frmvalidate()
	{
		var MatriForm = this.document.MatriForm;
		var FINALAGE = MatriForm.ENDAGE.value - MatriForm.STAGE.value;
		var stAge = 0, endAge = 0;

		if( MatriForm.STAGE.value == "" )
		{
		alert("Enter age range");
		MatriForm.STAGE.focus();
		return false;
		}
		else if( MatriForm.ENDAGE.value == "" )
		{
		alert("Enter age range");
		MatriForm.ENDAGE.focus();
		return false;
		}

		if ( FINALAGE > 20 )
		{
			alert("The difference between a partner's \"From\" and \"To\" age should not exceed 20 years.");
			MatriForm.ENDAGE.focus( );
			return false;
		}	
		
		// Check Age 
		if ( MatriForm.STAGE.value != "" && 
			!ValidateNo( MatriForm.STAGE.value, "0123456789" ) )
		{
			alert("Invalid Age " + MatriForm.STAGE.value);
			MatriForm.STAGE.focus( );
			return false;
		}
		else if ( MatriForm.STAGE.value != "" )
		{
			stAge = parseInt( MatriForm.STAGE.value );
			if ( stAge < 18 || stAge > 99 )
			{
				alert( "Invalid Age " +  MatriForm.STAGE.value + ".  Minimum age allowed is 18 and maximum age is 99" );
				MatriForm.STAGE.focus( );
				return false;
			}
		}
		
		if( MatriForm.ENDAGE.value != "" &&
			!ValidateNo( MatriForm.ENDAGE.value, "0123456789" ) )
		{
			alert("Invalid Age " + MatriForm.ENDAGE.value);
			MatriForm.ENDAGE.focus( );
			return false;
		}
		else if ( MatriForm.ENDAGE.value != "" )
		{
			endAge = parseInt( MatriForm.ENDAGE.value );
			if ( endAge < 18 || endAge > 99 )
			{
				alert( "Invalid Age " +  MatriForm.ENDAGE.value + ".  Minimum age allowed is 18 and maximum age is 99" );
				MatriForm.ENDAGE.focus( );
				return false;
			}

			if ( stAge != 0 && endAge < stAge )
			{
				alert( "Invalid age range. " + stAge + " to " + endAge );
				MatriForm.STAGE.focus( );
				return false;
			}
		}
		
		if ( FINALAGE > 20 )
		{
			alert("The difference between a partner's \"From\" and \"To\" age should not exceed 20 years.");
			MatriForm.ENDAGE.focus( );
			return false;
		}			
		
		if (!MatriForm.MARITAL_STATUS0.checked && !MatriForm.MARITAL_STATUS1.checked && !MatriForm.MARITAL_STATUS2.checked && !MatriForm.MARITAL_STATUS3.checked && !MatriForm.MARITAL_STATUS4.checked)
			{
				alert ("Please select the type of person you are looking For");
				MatriForm.MARITAL_STATUS0.focus();
				return false;
			}
		
		if ( MatriForm.ENDHEIGHT.selectedIndex  < MatriForm.STHEIGHT.selectedIndex )
		{
			alert( "Invalid height range." );
			MatriForm.ENDHEIGHT.focus( );
			return false;
		}

		if ( MatriForm.DAYS[1].checked && !ValidateDate( MatriForm.ST_MONTH, MatriForm.ST_DAY, MatriForm.ST_YEAR ) )
		{
			alert( 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 multiple_save()
{
	if(IsEmpty(document.MatriForm.search_name,'text'))
	{
		alert("Please enter the search name for saving.");
		document.MatriForm.search_name.focus();
		return false;
	}
	else {
		document.MatriForm.but_save.value = 1;
		return true;
	}
}


//Add and Remove options
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(document.getElementById(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=document.getElementById(theSelFrom);
	sel2=document.getElementById(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);
}

//Add and Remove options end
function validate() {

	if (frmvalidate()==true) 
	{
		selall();
		check_div_status();
		js_randid = genNumbers();
		document.MatriForm.randid.value = js_randid;
		document.MatriForm.bversion.value = js_br+"~"+version;

		var domain=document.MatriForm.jsdomain.value;
		document.MatriForm.action="http://"+domain+"/search/"+action_path+".php?t=A&randid="+js_randid;
		document.MatriForm.submit();
		return true;
	}
	else
	{return false;}
}

function savevalidate()
{
	var savesty=document.getElementById('savesearc-off');
	if (frmvalidate()==true) 
	{

		if (savesty.style.display=="block")
		{
			check_div_status();
			if(multiple_save())
			{
				selall();
				js_randid = genNumbers();
				document.MatriForm.randid.value = js_randid;
				document.MatriForm.bversion.value = js_br+"~"+version;

				var domain=document.MatriForm.jsdomain.value;
				document.MatriForm.action="http://"+domain+"/search/"+action_path+".php?t=A&randid="+js_randid;
				document.MatriForm.submit();
				return true;
			}
		}
	}
	else
	{return false;}
}
function check_div_status()
{
	var edu_blk=document.getElementById('edublock-off');
	var loc_blk=document.getElementById('locblock-off');
	var ast_blk=document.getElementById('astblock-off');
	var life_blk=document.getElementById('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";
	}
	document.MatriForm.Divstatus.value=hid_val;
}

function selall()
{
		for(var i = 0;i < document.MatriForm.LANGUAGE.length;i++)
		{document.MatriForm.LANGUAGE.options[i].selected = true;}              

		for(var i = 0;i < document.MatriForm.MOTHERTONGUE1.length;i++)
		{document.MatriForm.MOTHERTONGUE1.options[i].selected = true;}

		//for(var i = 0;i < document.MatriForm.RELIGION1.length;i++)
		//{document.MatriForm.RELIGION1.options[i].selected = true;}
		
		for(var i = 0;i < document.MatriForm.CASTE1.length;i++)
		{document.MatriForm.CASTE1.options[i].selected = true;}
		
		for(var i = 0;i < document.MatriForm.EDUCATION1.length;i++)
		{document.MatriForm.EDUCATION1.options[i].selected = true;}

		for(var i = 0;i < document.MatriForm.OCCUPATION1.length;i++)
		{document.MatriForm.OCCUPATION1.options[i].selected = true;}
	
		for(var i = 0;i < document.MatriForm.CITIZENSHIP1.length;i++)
		{document.MatriForm.CITIZENSHIP1.options[i].selected = true;}

		for(var i = 0;i < document.MatriForm.COUNTRY1.length;i++)
		{document.MatriForm.COUNTRY1.options[i].selected = true;}

		for(var i = 0;i < document.MatriForm.RESIDINGSTATE1.length;i++)
		{document.MatriForm.RESIDINGSTATE1.options[i].selected = true;}
		
		for(var i = 0;i < document.MatriForm.RESIDINGCITY1.length;i++)
		{document.MatriForm.RESIDINGCITY1.options[i].selected = true;}

		//for(var i = 0;i < document.MatriForm.RESIDENTSTATUS1.length;i++)
		//{document.MatriForm.RESIDENTSTATUS1.options[i].selected = true;}

		for(var i = 0;i < document.MatriForm.STAR1.length;i++)
		{document.MatriForm.STAR1.options[i].selected = true;}

}

//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;
	
	var 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=document.getElementById(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=document.getElementById(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)
{
	//alert(theValue);
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
	
	//if(theSel.length>30)
	//{
	//	alert("Maximum you add 30 only");
	//}
	//else
	//{
		if(theSel.id=="COUNTRY1")//country2
		{
			if (theValue==98 || theValue==222)
			{country_updatestate(theValue,'RESIDINGSTATE','states');}//state1
		}
	
		if(theSel.id=="RESIDINGSTATE1")//state2 
		{
		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 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++;
			}

		}			
	}

	//alert(selectedCount);
	
	if (selectedCount>30)
	{alert("You can select maximum 30");}
	else
	{
		var tp_c = theSelTo.length;
		if (theSelTo.length<30)
		{
			for(i=selectedCount-1; i>=0; i--)
			{
				if(tp_c<30) {
					country_addOption(theSelTo, selectedText[i], selectedValues[i]);
				}
				else {
					alert("You can move maximum 30");
					break;

				}
				tp_c++;
			}
			
		}
		else
		{
			alert("You can move maximum 30");
		}
	}
	
	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;
//Removal of States and Cities
if (theSelFrom.id=="COUNTRY1")   //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)
			{
				
					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);
	if(NS4) history.go(0);
}

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

//if (theSelFrom.id=="RESIDINGSTATE1")//state2
//{
	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--)
	{
		//alert(cselectedValues[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);
if(NS4) history.go(0);
}


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)
{
	//alert(j+","+obj+","+aryname)
	var aryname=eval(aryname);
	var obj1=document.getElementById(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=document.getElementById(obj);
	//alert(j.substr(0,2));
	if(j.substr(0,2)==98)
	{
		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 pop_country_state()
{
var country_len=selected_country.length	
var ind_len=selected_ind_states.length;
var usa_len=selected_usa_states.length;

var m=0, retain=m, len=0, opt=0, city_opt=0,cnt_name=0;

if(country_len>0)
{	
		for(j in selected_country)
		{	
			cnt_name=selected_country[j]; //get country id			
			if(cnt_name==98 || cnt_name==222)
			{			
			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++)
					{
						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++)
				{
					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++;
			}
			}
		} 
	}
}
