if(document.getElementById) {
	hasDOM=true;
}
else {
	hasDOM=false;
}
stateChanged=false;
iState = uState = 1;
iState1 = uState1 = 0;
function set_visibility(id,flag){
	var style;
	if(hasDOM ) {
		domObj=document.getElementById(id);
		style=flag?"block":"none";
		domObj.style.display=style;
	}
}

function objHandler(objName, index, numDivs, anchorText,visibility) {
	this.numDivs=numDivs;
	this.index=index;
	this.anchorText=anchorText;
	this.name=objName;
	this.visible=visibility;
	//Methods
	this.writeHandler=function(){
		if (!hasDOM) return;
		document.write('<div id="moreDiv' + this.index + 'h" style="width:100%;background-color:#FEE7CF;cursor:hand" onclick="javascript:' + this.name + '.showOptions();return false;">' +
		'<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td height="25" style="border:1px solid #FEE7CF">'+
		'<a href="#" onclick="javascript: ' + this.name + '.showOptions();return false;"><img src="../images/plus.gif" width="9" height="9" border="0" align="absmiddle"></a> <a href="#" class="aBlueSmall" style="text-decoration:none" onclick="javascript:' + this.name + '.showOptions();return false;">'  +
		this.anchorText + '</a></td></tr></table></div>');
	}
	this.writeHideHandler=function(){
		if (!hasDOM) return;
		document.write('<div style="background-color:#FEE7CF;cursor:hand;width:100%;" onclick="javascript:' + this.name + '.hideOptions();return false;">' +
		'<table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td height="25" style="border:1px solid #FEE7CF">' +
		'<a href="#" onclick="javascript:	' + this.name +'.hideOptions();return false;"><img ' +
	'src="../images/minus.gif" border="0" height="9" width="9" align="absmiddle"></a> ' +
	 '<a href="#" onclick="javascript: ' + this.name +'.hideOptions();return false;" class="aBlueSmall" style="text-decoration:none"><b>Fewer options</b></a></td></tr></table></div>');
	}
	this.writeHandledDiv=function(n) {
		if (!hasDOM) return;
		if(this.visible) {
			v='block';
		}
		else {
			v='none';
		}
		document.write('<div style="display:' + v + ';background-color:#FFF9F3;width:100%;" id="moreDiv' + this.index + n + '">');
	}
	this.writeEndDiv=function() {
		if (!hasDOM) return;
		document.write('</div>');
	}
	this.showOptions=function(){
		if (!hasDOM) return;
		var i;
		if(document.getElementById("moreDiv" + this.index + "h")) {
			set_visibility("moreDiv" + this.index + "h",0);
		}
		for(i=1;i<=this.numDivs;i++) {
			set_visibility("moreDiv"+this.index+i,1);
		}
		this.visible=true;
	}
	this.hideOptions=function(){
	
		if (!hasDOM) return;
		var i;
		if(document.getElementById("moreDiv" + this.index + "h")) {
			set_visibility("moreDiv" + this.index + "h",1);
		}
		for(i=1;i<=this.numDivs;i++) {
			set_visibility("moreDiv"+this.index+i,0);
		}
		this.visible=false;
	}
}
function add_seloptions(src,dst,fname) {
	var i,flag=false;
	srcObj=eval("document.forms[0]."+src);
	dstObj=eval("document.forms[0]."+dst);
	for(i=0;i<srcObj.options.length;i++) {
		if(srcObj.options[i].selected) {
			if(srcObj.options[i].text !="") {
				if(fname=='country' && srcObj.options[i].text == 'India') iState1=1;
				if(fname=='country' && srcObj.options[i].text == 'USA') uState1=1;
				dstObj.options[dstObj.options.length]=new Option(srcObj.options[i].text,srcObj.options[i].value);
				flag=true;
			}
		}
	}
	if(!flag && srcObj.options.length !=0) {
		alert("Please select " + fname + " to add !!")
	}
	else {
		if(dstObj.options[0].text=='Doesn\'t Matter') {
			dstObj.options[0]=null;
		}
		for(i=srcObj.options.length-1;i>=0;i--) {
			if(srcObj.options[i].selected) {
				srcObj.options[i]=null;
			}
		}
	}
	if(iState1 || uState1) {
		update_states();
	}
	
}
function remove_seloptions(src,dst,fname) {
	var i,flag=false;
	srcObj=eval("document.forms[0]."+src);
	dstObj=eval("document.forms[0]."+dst);
	for(i=0;i<srcObj.options.length;i++) {
		if(srcObj.options[i].selected) {
			if(srcObj.options[i].text !="Doesn't Matter") {
				if(fname=='country' && srcObj.options[i].text == 'India') iState1=2;
				if(fname=='country' && srcObj.options[i].text == 'USA') uState1=2;
				dstObj.options[dstObj.options.length]=new Option(srcObj.options[i].text,srcObj.options[i].value);
				flag=true;
			}
		}
	}
	if(!flag && (srcObj.options.length>1 || (srcObj.options.length==1 && srcObj.options[0].text !="Doesn't Matter"))) {
		alert("Please select " + fname + " to remove !!")
	}
	else {
		for(i=srcObj.options.length-1;i>=0;i--) {
			if(srcObj.options[i].selected) {
				srcObj.options[i]=null;
			}
		}
		if(srcObj.options.length==0) {
			srcObj.options[0]=new Option("Doesn't Matter", "");
		}
	}
	if(iState1 || uState1) {
		update_states();
	}
}

states=["India:Andaman &amp; Nicobar", "India:Andhra Pradesh", "India:Arunachal Pradesh", "India:Assam",
	 "India:Bihar", "India:Chandigarh", "India:Chhattisgarh", "India:Dadra &amp; Nagar", "India:Daman &amp; Diu",
	 "India:Delhi", "India:Goa", "India:Gujarat", "India:Haryana", "India:Himachal Pradesh",
	 "India:Jammu &amp; Kashmir", "India:Jharkhand", "India:Karnataka", "India:Kerala", "India:Lakshadweep",
	 "India:Madhya Pradesh", "India:Maharashtra", "India:Manipur", "India:Meghalaya", "India:Mizoram",
	 "India:Nagaland", "India:Orissa", "India:Pondicherry", "India:Punjab", "India:Rajasthan",
	 "India:Sikkim", "India:Tamil Nadu", "India:Tripura", "India:Uttar Pradesh", "India:Uttaranchal",
	 "India:West Bengal", "", "USA:Alabama", "USA:Alaska", "USA:Arizona", "USA:Arkansas", "USA:California",
	 "USA:Colorado", "USA:Connecticut", "USA:Delaware", "USA:District of Columbia", "USA:Florida",
	 "USA:Georgia", "USA:Hawaii", "USA:Idaho", "USA:Illinois", "USA:Indiana", "USA:Iowa", "USA:Kansas", "USA:Kentucky",
	 "USA:Louisiana", "USA:Maine", "USA:Maryland", "USA:Massachusetts", "USA:Michigan", "USA:Minnesota",
	 "USA:Mississippi", "USA:Missouri", "USA:Montana", "USA:Nebraska", "USA:Nevada", "USA:New Hampshire",
	 "USA:New Jersey", "USA:New Mexico", "USA:New York", "USA:North Carolina", "USA:North Dakota",
	 "USA:Ohio", "USA:Oklahoma", "USA:Oregon", "USA:Pennsylvania", "USA:Peurto Rico", "USA:Rhode Island",
	 "USA:South Carolina", "USA:South Dakota", "USA:Tennessee", "USA:Texas", "USA:Utah", "USA:Vermont",
	 "USA:Virginia", "USA:Washington", "USA:West Virginia", "USA:Wisconsin", "USA:Wyoming"];

function addStates(obj,tag) {
	var i;
	//Add all
	for(i=0;i<states.length;i++) {
		if(tag=="") {
			obj.options[obj.options.length]=new Option(states[i]);
		}
		else {
			n=states[i].indexOf(":");
			tag1=states[i].substr(0,n);
			if(tag==tag1) {
				obj.options[obj.options.length]=new Option(states[i]);
			}
		}	
	}
}

function removeStates(obj,tag) {
	var i;
	for(i=obj.options.length-1;i>=0;i--) {
		if(tag=="") {
			obj.options[i]=null;
		}
		else {
			n=obj.options[i].text.indexOf(":");
			tag1=obj.options[i].text.substr(0,n);
			if(tag==tag1 || obj.options[i].text=='') {
				obj.options[i]=null;
			}
		}	
	}
}

function update_states(){
	var i,n;
	//if(!ob5.visible) return;
	if(uState1==1 || iState1==1) {
		if(!stateChanged) {
			//add
			if(uState1==1) {
				txtCountry='India';
				iState=0;uState=1;
				//div_ob3.hideOptions();
			}
			else {
				txtCountry='USA';
				iState=1;uState=0;
			}
			//Remove txtcountry from left and right
			removeStates(document.forms[0].st1,txtCountry);
			removeStates(document.forms[0].st2,txtCountry);
			if(document.forms[0].st2.options.length==0) {
				document.forms[0].st2.options[0]=new Option("Doesn't Matter", "");
			}
			stateChanged=true;
		}
		else {
			if(iState==0 && iState1==1) {
				//Add indian states to the left box
				addStates(document.forms[0].st1,"India");
				iState=1;
				//div_ob3.showOptions();
			}
			else if(uState==0 && uState1==1) {
				//Add USA states to the left box
				addStates(document.forms[0].st1,"USA");
				uState=1;
			}
		}
	} 
	else if(uState1==2 || iState1==2) {
		if(iState1==2) {
			removeStates(document.forms[0].st1,"India");
			removeStates(document.forms[0].st2,"India");
			iState=0;
			//div_ob3.hideOptions();
		}
		else if(uState1==2) {
			removeStates(document.forms[0].st1,"USA");
			removeStates(document.forms[0].st2,"USA");
			uState=0;
		}
		if(document.forms[0].st2.options.length==0) {
			document.forms[0].st2.options[0]=new Option("Doesn't Matter", "");
		}
		if(iState==0 && uState==0) {
			removeStates(document.forms[0].st1,"");
			addStates(document.forms[0].st1,"");
			//div_ob3.showOptions();
			stateChanged=false;
		}
	} 
	iState1=0;
	uState1=0;
}

var div_ob1 = new objHandler("div_ob1",1,4,"<b>More options</b> (Have children, complexion, body type and horoscope)",false);
var div_ob2 = new objHandler("div_ob2",2,1,"<b>More options</b> (Family values and Manglik)",false);
var div_ob3 = new objHandler("div_ob3",3,1,"",true);
var div_ob4 = new objHandler("div_ob4",4,1,"<b>More options</b> (Smoke and drink)",false);
var div_ob5 = new objHandler("div_ob5",5,1,"<b>More options</b> (State and residency status)",false);
var div_ob6 = new objHandler("div_ob6",6,1,"<b>More options</b> (Occupation)",false);
