var win;
var mainWindow;
var listValueArray=new Array();
var listTextArray= new Array();

var x
var y

window.onerror=suppressErrors

function suppressErrors(){
	return true;
}
function xxdoGeocode() {
 
         
	var serverName = "geocode.access.mapquest.com";
	var serverPort = "80";
	var serverPath = "mq";

	var geoExec = new MQExec(serverName, serverPath, serverPort, myPxyServer ,
                                 myPxyPath , myPxyPort );

	//geocode the address from the form
	var address = new MQAddress();
    var gaCollection = new MQLocationCollection("MQGeoAddress");
    //populate the address object with the information from the form
    var streetEntered=trim(document.getElementById("txtNewStreet").value)
    var cityEntered=trim(document.getElementById("txtNewCity").value)
    var stateEntered=trim(document.getElementById("txtNewState").value)
    var zipEntered=trim(document.getElementById("txtNewZip").value)
  

    address.setStreet(streetEntered);
    address.setCity(cityEntered);
    address.setState(stateEntered);
    address.setPostalCode(zipEntered);

	addressEntered=streetEntered + " " + cityEntered + ", " + stateEntered + " "  + zipEntered

	geoExec.geocode(address, gaCollection);
	var geoAddr = gaCollection.get(0);

	//Put the result on the map with a custom icon
	origin = gaCollection.get(0).getMQLatLng();
	resultCode=geoAddr.getResultCode();
	//alert(origin.getLatitude());
	
	var streetFound=geoAddr.getStreet()
	var cityFound=geoAddr.getCity()
	var stateFound=geoAddr.getState()
	var zipFound=geoAddr.getPostalCode()
	zipFound=zipFound.substr(0,5)

	addressFound=streetFound + " " + cityFound + ", " + stateFound + " "  + zipFound
	
	if(addressFound.toUpperCase() != addressEntered.toUpperCase()){

		//alert (addressFound.toUpperCase().length + "\n"  + addressEntered.toUpperCase().length)


		var confirmMessage="We did not find the address exactly as you entered it, but found this similar one:\n\n" + addressFound + ".\n\nWould you like to use the address we found?"
		if (confirm(confirmMessage)){
			document.getElementById("txtNewStreet").value=streetFound;
    			document.getElementById("txtNewCity").value=cityFound;
			document.getElementById("txtNewState").value=stateFound;
    			document.getElementById("txtNewZip").value=zipFound;
		} else {
			//doReverseGeocode(document.getElementById("txtLatitude").value,document.getElementById("txtLongitude").value)
			document.getElementById("txtNewStreet").value=lastReturnedStreet;
			document.getElementById("txtNewCity").value=lastReturnedCity;
			document.getElementById("txtNewState").value=lastReturnedState;
			document.getElementById("txtNewZip").value=lastReturnedZip;
			//document.getElementById("btnRecenter").disabled=true;
			return "cancelled";
		}

	} else {
			document.getElementById("txtNewStreet").value=streetFound;
    			document.getElementById("txtNewCity").value=cityFound;
			document.getElementById("txtNewState").value=stateFound;
    			document.getElementById("txtNewZip").value=zipFound;
	}
	

	lastReturnedStreet=streetFound;
	lastReturnedCity=cityFound;
	lastReturnedState=stateFound;
	lastReturnedZip=zipFound;

	enableOrDisableRecenterButton(1);
	// + ' ' + geoAddr.getCity());

	return origin + "|" + resultCode
	//alert(origin)
}





function show_coords(event)
  {
  x=event.clientX
  y=event.clientY
  }

function showOrHideElement(showOrHide,theText,whichElement){
  
	document.getElementById(whichElement).innerHTML=theText

	if(whichElement.indexOf("divAltCityName")==0  ){
		document.getElementById(whichElement).style.top =y-68
		document.getElementById(whichElement).style.left =x-50
		//document.getElementById(whichElement).style.visibility="visible"
		//var t=setTimeout("document.getElementById(whichElement).style.visibility='hidden'",3000);
		//return;

	}


	if(showOrHide=="show"){
		//document.getElementById(whichElement).style.display="";
		document.getElementById(whichElement).style.visibility="visible"
		if(document.getElementById(whichElement).style.backgroundColor=="white"){
			if(whichElement.indexOf("divAltCityName")<0){
				document.getElementById(whichElement).style.backgroundColor="beige"
			}
		} else {
			document.getElementById(whichElement).style.backgroundColor="white"
		}

	} else {
		document.getElementById(whichElement).style.visibility="hidden"
		//document.getElementById(whichElement).style.display="none";
	}

 
}

function resetIfBlank(whichBox){
		if (whichBox.value==""){
			whichBox.value="[enter a value]";
			whichBox.style.color="red";
		} else {
			whichBox.style.color="green";
		}

}
function setLimitText(theText){
	//alert(theText)
	document.getElementById("spanRecordLimit1").firstChild.nodeValue=theText;
	document.getElementById("spanRecordLimit2").firstChild.nodeValue=theText;
	document.getElementById("spanRecordLimit3").firstChild.nodeValue=theText;


}
function openOrCloseAdvancedSettings(theElement){
	if (document.getElementById("divAdvancedSettings").style.display=="none"){

		document.getElementById("divBasicSettings").style.display="none"
		document.getElementById("divAdvancedSettings").style.display="block"
		theElement.innerHTML="Click Here for Basic Searching (Shortcut Buttons)"
		document.getElementById("divClickMessage").style.display="none"
		document.getElementById("divSubmit").style.display="block"

		document.getElementById("lstSelectedCriteria").style.display="";

	} else {
		document.getElementById("divAdvancedSettings").style.display="none"
		document.getElementById("divBasicSettings").style.display="block"
		document.getElementById("divSubmit").style.display="none"

		theElement.innerHTML="Click Here for Advanced Searching";
		document.getElementById("lstSelectedCriteria").style.display="none";
		
	}
	return;

	if (document.getElementById("tblExtraStuff").style.display=="none"){
		document.getElementById("tblExtraStuff").style.display="block"
	} else {
		document.getElementById("tblExtraStuff").style.display="none"
	}




}

function enableOrDisableTopMostSpan(status){

		if(!document.getElementById("spanTopMost")){return}
		document.getElementById("spanTopMost").disabled=!status
		document.getElementById("lstAvailableElementsForSorting1").disabled=!status;
		document.getElementById("optSortOrder1").disabled=!status;
		document.getElementById("optSortOrder2").disabled=!status;
		document.getElementById("chkSortPercentage1").disabled=!status;
		if(status){

			document.getElementById("spanTopMost").style.color="green";
			document.getElementById("optSortOrder1").style.color="green";
			document.getElementById("optSortOrder2").style.color="green";
			document.getElementById("highesttolowest").style.color="green";
			document.getElementById("lstAvailableElementsForSorting1").style.color="green";



			//document.getElementById("lstRecordLimit").disabled=!status
			//document.getElementById("lstAvailableElementsForSorting1").style.display=""
			//document.getElementById("spanTopMost").disabled=!status

		} else {


			document.getElementById("spanTopMost").style.color="gray";
			document.getElementById("optSortOrder1").style.color="gray";
			document.getElementById("optSortOrder2").style.color="gray";
			document.getElementById("spanSorting").style.color="gray";
			document.getElementById("highesttolowest").style.color="gray";
			document.getElementById("lstAvailableElementsForSorting1").style.color="gray";


		}

}
 
function login_validation()
{
//	var log=document.login_frm_page;
	var log=document.loginpage;

	//var login_name=document.login_frm_page.login_name.value;

	if (document.loginpage.login_name){
		var login_name=document.loginpage.login_name.value;
	}



// validation for empty fields	
		
	if(checkBlank(log.login_name,"Email ID")==false){
		return false;
    }
	if(!isEmail(login_name))
	{
		alert("Enter valid Email Id");
		document.loginpage.login_name.focus();
		document.loginpage.login_name.value="";
		return false;
	}
	/*if(isEmail(log.login_name)){
		alert ("Hello");
		return false;
    }
	*/
	if(checkBlank(log.login_password,"Password")==false){

		return false;
    }
		
	
	log.flg.value="yes";//Flag for conformation whether form is submit or not used in memberlogin.php

	//	alert(log.login_password.value);
 	log.submit();

	//I moved this to above the previous line on 11/19/2006.  Might have been a mistake:  
	//log.flg.value="yes";//Flag for conformation whether form is submit or not used in memberlogin.php

	//alert("eeeee")

	return true;

}
function forgotpassword(){
	//window.open('http://www.cnn.com','','height=250,width=450,resizable=no');

	window.open('../neighborhoodFinder/forgotpassword.php','','height=250,width=450,resizable=no');
}

function openWindow(whichURL){
	//alert(whichURL)
	if (mainWindow != null){
		if (!mainWindow .closed){
			mainWindow .close();
		}
	}
	mainWindow=window.open(whichURL,'mainWin','width=600,height=500;left=50');
}


function cForm(form,action){

        //win=window.open('','myWin','toolbars=0');
	if (win != null){
		if (!win.closed){
			win.close();
		}
	}
	win=window.open('','resultsWin');
	form.target='resultsWin';
	//form.action='getRadiusDemographics.php'
	form.action=action;

	//alert(action)
	//alert(action)
	win.focus();
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


function hideOrShowEditLink (whichTab){
	if(whichTab!=-1){
		document.getElementById("linkShowStep").style.display="";
		document.getElementById("linkShowStep").href="javascript:showStep(" + whichTab + ")";
	} else {
		document.getElementById("linkShowStep").style.display="none";

	}
}

function storeListEntries(){

	var elementList=document.getElementById("lstAvailableElementsForSelection")
	for(var i=0;i<elementList.length;i++){
		listValueArray[i]=elementList.options[i].value
		listTextArray[i]=elementList.options[i].innerHTML
	}

}

function selectGeneral(){
	showRelevantListOptions("general","AvailableElementsForSelection");
	showRelevantListOptions("general","AvailableElementsForCriteria");
}

function selectAllCategories(){
	showRelevantListOptions("all","AvailableElementsForSelection");
	showRelevantListOptions("all","AvailableElementsForCriteria");
}



function showRelevantListOptions(whichCategory,whichList){
	//alert(whichCategory)
	//alert(whichList)

	var elementList=document.getElementById("lst" + whichList)
	//alert(elementList.id)
	elementList.length=0;
	var listCount=0
	for(i=0;i<listValueArray.length;i++){
		var listValue=listValueArray[i].toLowerCase();

		switch(whichCategory){
			case "all":
				elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
				listCount+=1;
				break;
			case "general":
				if(listValue.indexOf("area")>=0 || listValue.indexOf("density")>=0 ||  listValue.indexOf("totalpop")>=0 || listValue.indexOf("malepop")>=0 || listValue.indexOf("femalepop")>=0 || listValue.indexOf("populationbetween")>=0 ){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;

			case "housing":

				if(listValue.indexOf("hous")>=0 && listValue.indexOf("income")<0){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
			case "education":

				if(listValue.indexOf("education")>=0){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
			case "race":
				if(listValue.indexOf("race")>=0 || listValue.indexOf("black")>=0 || listValue.indexOf("white")>=0 || listValue.indexOf("asian")>=0 || listValue.indexOf("native")>=0 || listValue.indexOf("latino")>=0 || listValue.indexOf("pacific") >=0 ){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
			case "marital":
				if(listValue.indexOf("marital")>=0){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
			case "income":
				if(listValue.indexOf("income")>=0){
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
			case "laborforce":
				if(listValue.indexOf("labor")>=0 || listValue.indexOf("work")>=0) {
					elementList.options[listCount] = new Option(listTextArray[i],listValueArray[i]);
					listCount+=1;
				}
				break;
				
		}
	}

}



function enableOrDisableClearButton(whichOne){
	if(whichOne=="town"){
		document.getElementById("btnClearTowns").disabled= (document.getElementById("lstPlace").selectedIndex<0);
	} else {
		document.getElementById("btnClearCounties").disabled=(document.getElementById("lstCounty").selectedIndex<0);

	}

}



function verifyAndSubmit(){
	if(document.theForm.lstState.selectedIndex==0){
		alert ("You must select a state before proceeding.")
		showStep(0)
		//openOrCloseSection('SelectLocation','Open')
		return;
	}
	if(1==2 && document.theForm.lstSelectedElements.length==0){
		alert ("You must select at least one data element before proceeding.")
		showStep(2)
		//openOrCloseSection('SelectDataElements','Open')
		return;
	}

	/////cForm(document.theForm,"resultsNewLayout.php");
	
	
	document.theForm.submit();
	document.getElementById("tab2").disabled=false;

	showStep(2);

}

function openSection(whichSection){

	if(whichSection!="all"){
		document.getElementById("tbl" + whichSection).style.display="";
		document.getElementById("lnkHide" + whichSection).style.display="";
	} else {
		document.getElementById("tblSelectLocation").style.display="";
		//document.getElementById("lnkHideSelectLocation").style.display="";

		document.getElementById("tblSelectDataElements").style.display="";
		//document.getElementById("lnkHideSelectDataElements").style.display="";

		document.getElementById("tblSelectCriteria").style.display="";
		//document.getElementById("lnkHideSelectCriteria").style.display="";

		document.getElementById("tblSelectSortAndLimit").style.display="";
		//document.getElementById("lnkHideSelectSortAndLimit").style.display="";
		//document.getElementById("btnViewHideAllSettings").value=

		document.getElementById("btnViewHideAllSettings").value="Hide Your Search Settings"
		document.getElementById("btnViewHideAllSettings").onClick="closeSection('all')";
	}

}
function openOrCloseSection(whichSection,whichAction){

	if(whichAction=="Open"){
		display="";
	} else {
		display="none";
	}
	if(whichSection!="all"){

		document.getElementById("tbl" + whichSection).style.display=display;
		document.getElementById("lnkHide" + whichSection).style.display=display;
	} else {
		if(document.getElementById("btnViewHideAllSettings").value=="View Your Search Settings"){
			display="";
			document.getElementById("btnViewHideAllSettings").value="Hide Your Search Settings"
		} else {
			display="none"
			document.getElementById("btnViewHideAllSettings").value="View Your Search Settings"
		}
		document.getElementById("tblSelectLocation").style.display=display;
		//document.getElementById("lnkHideSelectLocation").style.display=display;

		document.getElementById("tblSelectDataElements").style.display=display;
		//document.getElementById("lnkHideSelectDataElements").style.display=display;

		document.getElementById("tblSelectCriteria").style.display=display;
		//document.getElementById("lnkHideSelectCriteria").style.display=display;

		document.getElementById("tblSelectSortAndLimit").style.display=display;
		//document.getElementById("lnkHideSelectSortAndLimit").style.display=display;

		//document.getElementById("btnViewHideAllSettings").onClick="openOSection('all')";

	}




}

function clearSelectedTowns(){
	for(var i=0;i<document.getElementById("lstPlace").length;i++){
		if (document.getElementById("lstPlace").options[i].selected){
			document.getElementById("lstPlace").options[i].selected=false;
		}
	}
	enableOrDisableClearButton()
}

function clearSelectedCounties(){
	for(var i=0;i<document.getElementById("lstCounty").length;i++){
		if (document.getElementById("lstCounty").options[i].selected){
			document.getElementById("lstCounty").options[i].selected=false;
		}
	}
	enableOrDisableClearButton()
	refreshPlaceList()
}


function hideOrShowOrderRadios(whichList){
	
	document.getElementById("spanSortOrders").style.display="none";
	for(var j=1;j<whichList.length;j++){
		if (whichList.options[j].selected){
			document.getElementById("spanSortOrders").style.display="";
			break;
		}
	}

	
}
function hideOrShowPercentageCheckBox(whichList){
	
	id=Right(whichList.id,1)

	if(isNumeric(id)){ //meaning that we are working with the sortby listboxes
		var checkBox="chkSortPercentage" + id;
		var label="lblSortPercentage" + id;
		document.getElementById(checkBox).style.visibility="visible";
		document.getElementById(label).style.visibility="visible";


	} else { //meaning that we are working with the filter listbox
		document.getElementById("chkFilterPercentage").style.visibility="visible";
		document.getElementById("lblFilterPercentage").style.visibility="visible";
		var checkBox="chkFilterPercentage";
		var label="lblFilterPercentage";
	}
	switch(whichList.value){
		case "":
		case "medianHouseholdIncome":
		case "medianHouseholdIncomeAdjusted":
		case "numberOfHousingUnits":
		case "numberOfHouseholds":
		case "totalPopulation":
		case "landArea":
		case "populationDensity":
			document.getElementById(checkBox).style.visibility="hidden";
			document.getElementById(label).style.visibility="hidden";
			document.getElementById(checkBox).checked=false;
			break;
	}
}

function enableOrDisablePercentageLabel(theCheckbox,theLabel){
	
	document.getElementById(theLabel).disabled=(!theCheckbox.checked)
	document.getElementById(theLabel).className="disabled"+(!theCheckbox.checked);
}

function refreshPlaceList(){


	document.getElementById("lstPlace").length=0;
	var countyList=""

	myElements = "# of elements: " + document.theForm.elements.length + " \n " ;
	for (i = 0; i < document.theForm.elements.length; i++) {
		myElements += document.theForm.elements[i].name + "; "
	}
	//alert(myElements);
	if (document.theForm.lstState != null) {
		//alert(document.theForm.lstState.value);
		stateList=document.theForm.lstState.value;
		var stateArray=stateList.split(":");
		theState=stateArray[0].toUpperCase();
		//alert(stateList);
	}	
	else {
		//alert(document.theForm.lstState);
		stateList = "";
		theState = 0;
	}	
	
	if (document.theForm.lstCounty != null) {
		theCounty=document.theForm.lstCounty.value;
		for (i=0;i<document.theForm.lstCounty.length;i++){
			if(document.theForm.lstCounty[i].selected){
				countyList+=document.theForm.lstCounty[i].value + ","
			}
		}
	}	
	else {
		theCounty = "";
	}	

	if(countyList>""){
		countyList+="-10";
	}


	if(theState=="0"){
	//	document.getElementById("showOthers").style.display="none";
	//	document.getElementById("btnClearTowns").style.display="none";
	}


	//var newLoc="getPlacesForState.php?state=" + theState + "&countyList=" + countyList + "&selectedPlace=<?=$selectedPlaces?>";

	var newLoc="getPlacesForState.php?state=" + theState + "&countyList=" + countyList

	//alert(newLoc)
 
	//alert(newLoc)
	document.getElementById("iFrameGetPlaces").src=newLoc;
	//alert("ron")

}


function selectSorts(sorts){
	sortArray=sorts.split("|");
	//for(var i=0;i<=1;i++){
		//alert(sortArray[i]);
		//var sortList=document.getElementById("lstAvailableElementsForSorting" + (i+1))
		var sortList=document.getElementById("lstAvailableElementsForSorting1")


		//alert(sortList.length);
		for (var j=0;j<sortList.length;j++){
			if(sortList.options[j].value==sortArray[0]){
				sortList.selectedIndex=j;
				break;
			}
		}
	//}
}
function recordListItemTextAndValue(){

	//alert("e")
	//return;
	document.theForm.txtCriteriaListItemText.value=""

	for (var i=0;i<document.getElementById("lstSelectedCriteria").length;i++){
		document.theForm.txtCriteriaListItemText.value+=document.getElementById("lstSelectedCriteria").options[i].innerHTML + "|" + document.getElementById("lstSelectedCriteria").options[i].value + ",";
	}
	//alert("f")
	document.theForm.txtSortListItemText.value=""

	for (var i=0;i<document.getElementById("lstAvailableElementsForSorting1").length;i++){
		if(i==document.getElementById("lstAvailableElementsForSorting1").selectedIndex){
			document.theForm.txtSortListItemText.value+=document.getElementById("lstAvailableElementsForSorting1").options[i].innerHTML + "|" + document.getElementById("lstAvailableElementsForSorting1").options[i].value + ",";
		}
	}
	//alert("g")
	//alert(document.theForm.txtSortListItemText.value)

	return;
	document.theForm.txtElementsListItemText.value=""
	//for (var i=0;i<document.getElementById("lstSelectedElements").length;i++){
	//	document.theForm.txtElementsListItemText.value+=document.getElementById("lstSelectedElements").options[i].innerHTML + "|" + document.getElementById("lstSelectedElements").options[i].value + ",";
	//}


}


function isNumeric(sText) {
   var ValidChars = "0123456789.";
   var Char;

   if (sText.length==0){return false}
   for (i = 0; i < sText.length; i++) {
       Char = sText.charAt(i);
	if (Char=="." && charSeen){
		return false;
	}
	if (Char=="."){
		var charSeen=true;
	}

       if (ValidChars.indexOf(Char) == -1) {
         return false;
       }
   }
   return true;
}



function hideOrShowFilterSection(){
	document.getElementById("spanFilterSection").style.display="";
}


function enableOrDisableRemoveAllButtons(){

//////	document.getElementById("btnRemoveAllCriteria").disabled=(document.getElementById("lstSelectedCriteria").length==0);
	//document.getElementById("btnRemoveAllSelectedElements").disabled=(document.getElementById("lstSelectedElements").length==0);


}
function enableOrDisableNewCriterion(whichElement){
	document.getElementById("spanCriterionInstructions").style.display="";

	if(document.getElementById("spanBetweenValues").style.display==""){
		if ( isNumeric(trim(document.getElementById("txtLowerBound").value)) && isNumeric(trim(document.getElementById("txtUpperBound").value))){
			document.theForm.btnAddCriterion.disabled=false;
			document.theForm.btnAddCriterion.style.color="black"

		} else {
			document.theForm.btnAddCriterion.disabled=true;
			document.theForm.btnAddCriterion.style.color="gray"

		}
	}
	if(document.getElementById("spanSingleValue").style.display==""){
	//if(whichElement.id=="txtSingleValue"){
		if (isNumeric(trim(document.getElementById("txtSingleValue").value))){
			document.theForm.btnAddCriterion.disabled=false;
		} else {
			document.theForm.btnAddCriterion.disabled=true;
		}
	}
	//alert(whichElement.id)
	if(whichElement.id=="lstAvailableElementsForCriteria"){

	}

	if (1==2 && document.theForm.btnAddCriterion.disabled){
		document.theForm.btnAddCriterion.style.visibility="hidden";
	} else {
		document.theForm.btnAddCriterion.style.visibility="visible";
		//document.theForm.btnAddCriterion.disabled=false;

	}


}


function displayAppropriateFilterInputs(whichOperator){
	//alert(whichOperator)
	document.getElementById("spanSingleValue").style.display="none";
	document.getElementById("spanBetweenValues").style.display="none";

	if (whichOperator==" between "){
		document.getElementById("spanBetweenValues").style.display="";
		enableOrDisableNewCriterion(document.getElementById("txtLowerBound"))
	} else {
		document.getElementById("spanSingleValue").style.display="";
		enableOrDisableNewCriterion(document.getElementById("txtSingleValue"))


	}

}

function addToCriteria(theList){

	var criteriaText=theList.options[theList.selectedIndex].innerHTML.replace("...","");
	var criteriaValue=theList.options[theList.selectedIndex].value;

	document.getElementById("spanCriteria").style.display='inline';
	document.getElementById("spanCriteria").firstChild.nodeValue=criteriaText;
	document.getElementById("txtCriteriaValue").value=criteriaValue;
}

function putValueInTextBox(theObject){
	return;
	if (document.theForm.txtSelectedItem.value==theObject.selectedIndex){
		document.theForm.btnAdd.click();
	}
	document.theForm.txtSelectedItem.value=theObject.selectedIndex;
}
function highlightAddButton(whichList){



 

	if(whichList=="lstSelectedElements"){




		for (var i=0;i<document.getElementById("lstAvailableElementsForSelection").length;i++){
			if (document.getElementById("lstAvailableElementsForSelection")[i].selected==true){
				document.getElementById("btnAdd").disabled=false;
				break;
			}
			document.getElementById("btnAdd").disabled =true;
		}

		for (var i=0;i<document.getElementById("lstSelectedElements").length;i++){
			if (document.getElementById("lstSelectedElements")[i].selected==true){
				document.getElementById("btnRemoveSelectedElement").disabled=false;
				break;
			}
			document.getElementById("btnRemoveSelectedElement").disabled =true;
		}
	} else {

		for (var i=0;i<document.getElementById("lstAvailableElementsForCriteria").length;i++){
			if (document.getElementById("lstAvailableElementsForCriteria")[i].selected==true){
				document.getElementById("btnAddCriterion").disabled=false;
				break;
			}
			document.getElementById("btnAddCriterion").disabled =true;
		}

		for (var i=0;i<document.getElementById("lstSelectedCriteria").length;i++){
			if (document.getElementById("lstSelectedCriteria")[i].selected==true){
				document.getElementById("btnRemoveCriterion").disabled=false;
				break;
			}
			document.getElementById("btnRemoveCriterion").disabled =true;
		}

	}


	if (1==2 && document.getElementById("btnAdd").disabled){
		document.getElementById("btnAdd").style.visibility="hidden";
	} else {
		//document.getElementById("btnAdd").style.visibility="visible";
	}



}

function subscribe(){
	//alert("hello");	
	document.frmSubscribe.submit()
}

function addCriterion(){


		var theText=document.getElementById("lstAvailableElementsForCriteria").options[document.getElementById("lstAvailableElementsForCriteria").selectedIndex].innerHTML;
		var theValue=document.getElementById("lstAvailableElementsForCriteria").options[document.getElementById("lstAvailableElementsForCriteria").selectedIndex].value;


		newOption = document.createElement('option');
		if (theText.indexOf("Between the Ages of...")>0){

			var fromAgeText=document.getElementById("lstFromAge2").options[document.getElementById("lstFromAge2").selectedIndex].innerHTML
			var toAgeText=document.getElementById("lstToAge2").options[document.getElementById("lstToAge2").selectedIndex].innerHTML

			var fromAgeValue=document.getElementById("lstFromAge2").value;
			var toAgeValue=document.getElementById("lstToAge2").value;

			theText=theText.replace("..."," ") + fromAgeText + " and " + toAgeText;
			theValue=theValue + ":" + fromAgeValue + ":" + toAgeValue;
		}

		if (theText.indexOf("Income Between...")>0){

			var fromIncomeText=document.getElementById("lstFromIncome2").options[document.getElementById("lstFromIncome2").selectedIndex].innerHTML
			var toIncomeText=document.getElementById("lstToIncome2").options[document.getElementById("lstToIncome2").selectedIndex].innerHTML

			var fromIncomeValue=document.getElementById("lstFromIncome2").value;
			var toIncomeValue=document.getElementById("lstToIncome2").value;

			theText=theText.replace("..."," ") + fromIncomeText + " and " + toIncomeText;
			theValue=theValue + ":" + fromIncomeValue + ":" + toIncomeValue;
		}


		if (theText.indexOf("Commute Time Between...")>0){

			//var fromIncomeText=document.getElementById("lstFromIncome2").options[document.getElementById("lstFromIncome2").selectedIndex].innerHTML
			//var toIncomeText=document.getElementById("lstToIncome2").options[document.getElementById("lstToIncome2").selectedIndex].innerHTML

			//var fromIncomeValue=document.getElementById("lstFromIncome2").value;
			//var toIncomeValue=document.getElementById("lstToIncome2").value;

			//theText=theText.replace("..."," ") + fromIncomeText + " and " + toIncomeText;
			//theValue=theValue + ":" + fromIncomeValue + ":" + toIncomeValue;




			var fromCommuteTimeValue=document.getElementById("lstFromCommuteTime2").options[document.getElementById("lstFromCommuteTime2").selectedIndex].value
			var toCommuteTimeValue=document.getElementById("lstToCommuteTime2").options[document.getElementById("lstToCommuteTime2").selectedIndex].value

			var fromCommuteTimeText=document.getElementById("lstFromCommuteTime2").options[document.getElementById("lstFromCommuteTime2").selectedIndex].innerHTML
			var toCommuteTimeText=document.getElementById("lstToCommuteTime2").options[document.getElementById("lstToCommuteTime2").selectedIndex].innerHTML
			fromCommuteTimeText=fromCommuteTimeText.replace("Minutes"," ")
			fromCommuteTimeText=fromCommuteTimeText.replace("Minute"," ")

			theText=theText.replace("..."," ") + trim(fromCommuteTimeText) + " and " + toCommuteTimeText;
			theValue=theValue + ":" + fromCommuteTimeValue + ":" + toCommuteTimeValue;
			newOption.value=theValue;







		}



		if (theText.indexOf("Built Between...")>0){

			var fromBuildYearText=document.getElementById("lstFromBuildYear2").options[document.getElementById("lstFromBuildYear2").selectedIndex].innerHTML
			var toBuildYearText=document.getElementById("lstToBuildYear2").options[document.getElementById("lstToBuildYear2").selectedIndex].innerHTML

			var fromBuildYearValue=document.getElementById("lstFromBuildYear2").value;
			var toBuildYearValue=document.getElementById("lstToBuildYear2").value;

			theText=theText.replace("..."," ") + fromBuildYearText + " and " + toBuildYearText;
			theValue=theValue + ":" + fromBuildYearValue + ":" + toBuildYearValue;
		}

		if (theText.indexOf("Marital Status of...")>0){

			var maritalStatusText=document.getElementById("lstMaritalStatus2").options[document.getElementById("lstMaritalStatus2").selectedIndex].innerHTML

			var maritalStatusValue=document.getElementById("lstMaritalStatus2").value;



			switch(maritalStatusText){
				case "Never Married":
					theText=theText.replace("With Marital Status of","Who");
					break;
				case "Married Now":
				case "Married w/Spouse Present":
				case "Married w/Spouse Absent":
				case "Separated":
				case "Widowed":
				case "Divorced":
					theText=theText.replace("With Marital Status of","Who are");
					break;

			}
			theText=theText.replace("..."," ") + maritalStatusText;

			theValue=theValue + ":" + maritalStatusValue+ ":" + maritalStatusValue;
		}


		if (theText.indexOf("Education Level of...")>0){


			var educationLevelValue=document.getElementById("lstEducationLevel2").options[document.getElementById("lstEducationLevel2").selectedIndex].value
			var educationLevelText=document.getElementById("lstEducationLevel2").options[document.getElementById("lstEducationLevel2").selectedIndex].innerHTML
			//alert(educationLevelValue);
			document.getElementById("lstEducationLevel2").focus();
			var atLeast="";
			if (document.getElementById("chkEducationAtLeast2").checked){
				atLeast="at Least ";
				theValue=theValue + ":" + educationLevelValue + ":Doctorate_degree" ;
			} else {
				atLeast=" ";
				if (educationLevelValue=="Some_college_less_than_1_year"){
					theValue=theValue + ":Some_college_less_than_1_year:Some_college_1_more_years_no_degree";
				} else {
					theValue=theValue + ":" + educationLevelValue + ":" + educationLevelValue ;
				}
			}
			theText=theText.replace("..."," ") + atLeast + educationLevelText;
			theValue=theValue;


		}

		var textForSortList=theText;
		var valueForSortList=theValue;
		// alert(theValue)

		theText+=" " + document.getElementById("lstCriteria").options[document.getElementById("lstCriteria").selectedIndex].innerHTML + " ";
		if(document.getElementById("lstCriteria").value!=" between "){
			theText+=document.getElementById("txtSingleValue").value;
			theValue+= document.getElementById("lstCriteria").value  + document.getElementById("txtSingleValue").value;

		} else {
			theText+=document.getElementById("txtLowerBound").value + " and " + document.getElementById("txtUpperBound").value;
			//theValue+="| between " + document.getElementById("txtLowerBound").value + " and " + document.getElementById("txtUpperBound").value;
			theValue+=" between " + document.getElementById("txtLowerBound").value + " and " + document.getElementById("txtUpperBound").value;


		}
		if( (!document.getElementById("lblFilterPercentage").disabled) &&  document.getElementById("lblFilterPercentage").style.visibility=="visible" &&  document.getElementById("chkFilterPercentage").checked  ){
			theText+="%";
			theValue+="%";
			//alert(theValue);
			if(1==2 && theValue.indexOf(" between ")>0){
				var betweenPart=(theValue.split(" between ")[1]);
				//alert("bp:" + betweenPart)
				betweenPart=betweenPart.replace(" and ","% and ")
				//alert("bpa:" + betweenPart)
				theValue=theValue.split(" between ")[0] + " between " + betweenPart;
				//alert(theValue)

				var betweenPart=(theText.split(" is between ")[1]);
				//alert("bp:" + betweenPart)
				betweenPart=betweenPart.replace(" and ","% and ")
				//alert("bpat:" + betweenPart)
				theText=theText.split(" between ")[0] + " between " + betweenPart;
				//alert(theText)

 
			}



		}
		newOption.innerHTML=theText;
		newOption.value=theValue;
//			var radioFieldB = document.createElement("<option>werwer</option>");
//			document.getElementById("lstSelectedCriteria").appendChild(radioFieldB);
		newOption.setAttribute("onmouseover","showOrHideElement('show','" + theText + "','criterionOptionDiv')");
		newOption.setAttribute("onmouseout","showOrHideElement('hide','" + theText + "','criterionOptionDiv')");

		document.getElementById("lstSelectedCriteria").appendChild(newOption);



		if(theValue.indexOf(":")>0){
			addItemToSortLists(textForSortList,valueForSortList);
			if (1==2 && !alreadyInSortList(valueForSortList)){
				newOption = document.createElement('option');
				newOption.innerHTML=textForSortList;
				newOption.value=valueForSortList;
				
				document.getElementById("lstAvailableElementsForSorting1").appendChild(newOption);
				//document.getElementById("lstAvailableElementsForSorting2").appendChild(newOption);

			}

		}


		document.getElementById("btnRemoveAllCriteria").disabled=false;

	///	document.getElementById("btnAddCriterion").disabled=true;
	

		//this was added because the sorting dropdown lists were bleeding through to the other tabs during the adding of items
		
		//////allSteps=document.getElementById('main').getElementsByTagName('div');
		
		/////allSteps[4].style.display='none';



}


function showSelectValue(e) { 
	if (e.target.id!= 'select') { 
		alert( e.target.value)
	} 
} 
function attachTest() { 
	document.getElementById('lstSelectedCriteria').addEventlistener('mouseover',showSelectValue,false); 
}
 
function addCriteria(whichItems){
	if(whichItems==""){return};
	var itemArray=whichItems.split(",")
	for (var i=0;i<itemArray.length;i++){
		newOption = document.createElement('option');
		var textAndValue=itemArray[i];
		var itemText=textAndValue.split("|")[0];
		var itemValue=textAndValue.split("|")[1];
		if(itemText>""){
			newOption.innerHTML=itemText
			newOption.value=itemValue;
			//var radioFieldB = document.createElement("<option>werwer</option>");
			//document.getElementById("lstSelectedCriteria").appendChild(radioFieldB);
			document.getElementById("lstSelectedCriteria").appendChild(newOption);
		}
	}



}

function alreadyInSortList(whichAlias){

	for (var j=0;j<document.getElementById("lstAvailableElementsForSorting1").length;j++){
			if(whichAlias==document.getElementById("lstAvailableElementsForSorting1").options[j].value){

				return true;

			}
	}
	return false;


}

function initialCap(theString) {
	var newWord=""
	theString=theString.toLowerCase();
	wordArray=theString.split(" ");
	for (var i=0;i<wordArray.length;i++){
		var word=wordArray[i]
		if (word=="se" || word=="ne" || word=="sw" || word=="nw"){
			word=word.toUpperCase()
		}
		
		newWord+=word.substr(0, 1).toUpperCase() + word.substr(1) + " "

	} 
	newWord=trim(newWord)
	//alert(newWord)
   	return newWord	
}


function addPostedListElements(whichItems,whichList){
	if(whichItems==""){return};
	var itemArray=whichItems.split(",")

	for (var i=0;i<itemArray.length;i++){
		newOption = document.createElement('option');
		var textAndValue=itemArray[i];
		var itemText=textAndValue.split("|")[0];
		var itemValue=textAndValue.split("|")[1];
		if(itemText>""){
			newOption.innerHTML=itemText
			newOption.value=itemValue;
			document.getElementById(whichList).appendChild(newOption);
			//alert("xxx")
			var alias=itemValue.split(" ")[0];

			if (itemValue.indexOf(" ")>0){
				itemValue=itemValue.split(" ")[0];
				itemText=itemText.split(" is ")[0];
			}
			//alert(itemText)
			//alert(itemValue)
			addItemToSortLists(itemText,itemValue)
			if (1==2 && !alreadyInSortList(alias)){
				for(j=1;j<=2;j++){

					newOption = document.createElement('option');
					newOption.innerHTML=itemText
					newOption.value=alias;
					//alert(j)
					document.getElementById("lstAvailableElementsForSorting" + j).appendChild(newOption);
				}
			}


		}
	}


}


function xaddPostedListElements(whichItems,whichList){
	if(whichItems==""){return};
	var itemArray=whichItems.split(",")



	for (var i=0;i<itemArray.length;i++){




		var textAndValue=itemArray[i];
		var itemText=textAndValue.split("|")[0];
		var itemValue=textAndValue.split("|")[1];
		var alias=itemValue.split(" ")[0];

		if (1==2){
		for (var j=0;j<document.getElementById("lstAvailableElementsForSorting1").length;j++){

			var alreadyInList=0;
			if(alias==document.getElementById("lstAvailableElementsForSorting1").options[j].value){

				alreadyInList=1;
				break;
			}
		}
		}
		if(itemText>"" ){

			newOption = document.createElement('option');
			newOption.innerHTML=itemText;
			newOption.value=itemValue;
			document.getElementById(whichList).appendChild(newOption);

			for(j=1;j<=2;j++){
				newOption = document.createElement('option');
				newOption.innerHTML=itemText
				newOption.value=itemValue;
				//alert("d")
				document.getElementById("lstAvailableElementsForSorting" + j).appendChild(newOption);
			}
			//document.getElementById("lstAvailableElementsForSorting2").appendChild(newOption);
			//document.getElementById("lstAvailableElementsForSorting3").appendChild(newOption);

		}
	}


}


function addElement(){
	var theText=document.getElementById("lstAvailableElementsForSelection").options[document.getElementById("lstAvailableElementsForSelection").selectedIndex].innerHTML;
	var theValue=document.getElementById("lstAvailableElementsForSelection").options[document.getElementById("lstAvailableElementsForSelection").selectedIndex].value;

	newOption = document.createElement('option');
	if (theText.indexOf("Between the Ages of...")>0){
		var fromAge=document.getElementById("lstFromAge1").options[document.getElementById("lstFromAge1").selectedIndex].innerHTML
		var toAge=document.getElementById("lstToAge1").options[document.getElementById("lstToAge1").selectedIndex].innerHTML
		newOption.innerHTML=theText.replace("..."," ") + fromAge + " and " + toAge;
		theValue=theValue + ":" + fromAge + ":" + toAge;
		newOption.value=theValue;
	} else	if (theText.indexOf("Income Between...")>0){
		var fromIncomeText=document.getElementById("lstFromIncome1").options[document.getElementById("lstFromIncome1").selectedIndex].innerHTML
		var toIncomeText=document.getElementById("lstToIncome1").options[document.getElementById("lstToIncome1").selectedIndex].innerHTML
		var fromIncomeValue=document.getElementById("lstFromIncome1").options[document.getElementById("lstFromIncome1").selectedIndex].value
		var toIncomeValue=document.getElementById("lstToIncome1").options[document.getElementById("lstToIncome1").selectedIndex].value

		newOption.innerHTML=theText.replace("..."," ") + fromIncomeText + " and " + toIncomeText ;
		theValue=theValue + ":" + fromIncomeValue + ":" + toIncomeValue;
		newOption.value=theValue;
	} else	if (theText.indexOf("Built Between...")>0){
		var fromBuildYear=document.getElementById("lstFromBuildYear1").options[document.getElementById("lstFromBuildYear1").selectedIndex].value
		var toBuildYear=document.getElementById("lstToBuildYear1").options[document.getElementById("lstToBuildYear1").selectedIndex].value
		newOption.innerHTML=theText.replace("..."," ") + fromBuildYear + " and " + toBuildYear;
		theValue=theValue + ":" + fromBuildYear + ":" + toBuildYear;
		newOption.value=theValue;
	} else	if (theText.indexOf("Commute Time Between...")>0){
		var fromCommuteTimeValue=document.getElementById("lstFromCommuteTime1").options[document.getElementById("lstFromCommuteTime1").selectedIndex].value
		var toCommuteTimeValue=document.getElementById("lstToCommuteTime1").options[document.getElementById("lstToCommuteTime1").selectedIndex].value

		var fromCommuteTimeText=document.getElementById("lstFromCommuteTime1").options[document.getElementById("lstFromCommuteTime1").selectedIndex].innerHTML
		var toCommuteTimeText=document.getElementById("lstToCommuteTime1").options[document.getElementById("lstToCommuteTime1").selectedIndex].innerHTML
		fromCommuteTimeText=fromCommuteTimeText.replace("Minutes","")
		fromCommuteTimeText=fromCommuteTimeText.replace("Minute","")

		newOption.innerHTML=theText.replace("..."," ") + fromCommuteTimeText+ " and " + toCommuteTimeText;
		theValue=theValue + ":" + fromCommuteTimeValue + ":" + toCommuteTimeValue;
		newOption.value=theValue;

	} else	if (theText.indexOf("Marital Status of...")>0){
		var maritalStatusValue=document.getElementById("lstMaritalStatus1").options[document.getElementById("lstMaritalStatus1").selectedIndex].value;
		var maritalStatusText=document.getElementById("lstMaritalStatus1").options[document.getElementById("lstMaritalStatus1").selectedIndex].innerHTML;

		if(maritalStatusText!="Other"){
			theText=theText.replace("With Marital Status of...","Who are ") + maritalStatusText
			theText=theText.replace("are Never","Never");
		} else {
			//var otherText="Other"
			theText=theText.replace("..."," ") + "'Other'";
		}

		//newOption.innerHTML=theText.replace("..."," ") + maritalStatusText
		newOption.innerHTML=theText;

		theValue=theValue + ":" + maritalStatusValue + ":" + maritalStatusValue;
		newOption.value=theValue;
	} else	if (theText.indexOf("Education Level of...")>0){
		var educationLevelValue=document.getElementById("lstEducationLevel1").options[document.getElementById("lstEducationLevel1").selectedIndex].value
		var educationLevelText=document.getElementById("lstAvailableElementsForSelection").options[document.getElementById("lstAvailableElementsForSelection").selectedIndex].innerHTML
		educationLevelText+=document.getElementById("lstEducationLevel1").options[document.getElementById("lstEducationLevel1").selectedIndex].innerHTML


		document.getElementById("lstEducationLevel1").focus();
		var atLeast="";
		educationLevelText=educationLevelText.replace("a Maximum Education Level of...","")
		educationLevelText=educationLevelText.replace("With Thru","Educated Thru");
		educationLevelText=educationLevelText.replace("High School Grad","a High School Diploma");
		educationLevelText=educationLevelText.replace("Associate's","an Associate's");
		educationLevelText=educationLevelText.replace("Bachelor's","a Bachelor's");
		educationLevelText=educationLevelText.replace("Master's","a Master's");
		educationLevelText=educationLevelText.replace("Professional School","a Professional School");
		educationLevelText=educationLevelText.replace("Doctorate School","a Doctorate School");
		if (document.getElementById("chkEducationAtLeast1").checked){

			theValue=theValue + ":" + educationLevelValue + ":Doctorate_degree" ;
			educationLevelText=educationLevelText.replace("Thru","Thru at Least");
			educationLevelText=educationLevelText.replace("a High School Diploma","at Least a High School Diploma");

			educationLevelText=educationLevelText.replace("Some College (No Degree)","at Least Some College");

			if (educationLevelValue=="No_schooling_completed"){
				educationLevelText=educationLevelText.replace("No School","Some School")
			}
			if (educationLevelText.indexOf("Degree")>0){
				educationLevelText=educationLevelText.replace("With a","With at Least a");
				educationLevelText=educationLevelText.replace("With an","With at Least an");

			}


		} else {


			if (educationLevelValue=="Some_college_less_than_1_year"){
				theValue=theValue + ":Some_college_less_than_1_year:Some_college_1_more_years_no_degree";
			} else {
				theValue=theValue + ":" + educationLevelValue + ":" + educationLevelValue ;
			}
		}

		//newOption.innerHTML=theText.replace("..."," ") + atLeast  + educationLevelText;
		newOption.innerHTML=educationLevelText;


		newOption.value=theValue;

	} else {
		newOption.innerHTML=theText;
		newOption.value=theValue;
	}
	//document.getElementById("lstSelectedElements").appendChild(newOption);
	//document.getElementById("btnRemoveAllSelectedElements").disabled=false;

	if(theValue.indexOf(":")>0){
		theText=newOption.innerHTML
		theValue=newOption.value
		addItemToSortLists(theText,theValue)


	}

	//this was added because the sorting dropdown lists were bleeding through to the other tabs during the adding of items
	allSteps=document.getElementById('main').getElementsByTagName('div');
	allSteps[4].style.display='none';


}

function addItemToSortLists(whichText,whichValue){

		if (!alreadyInSortList(whichValue)){

			newOption = document.createElement('option');
			newOption.innerHTML=whichText;
			newOption.value=whichValue;
			document.getElementById("lstAvailableElementsForSorting1").appendChild(newOption);
			newOption = document.createElement('option');
			newOption.innerHTML=whichText;
			newOption.value=whichValue;
			//document.getElementById("lstAvailableElementsForSorting2").appendChild(newOption);
		}


}


function remove(whatToRemove,whichList){
 	var elSel =document.getElementById(whichList);
	if(whatToRemove=="all"){
		elSel.options.length=0
		return; 
	}
	var i;
	if(elSel.length>0){
		for (i = elSel.length - 1; i>=0; i--) {
			if (elSel.options[i].selected) {
				if(elSel.options[i].text>""){
				      elSel.remove(i);
				}
			}
		}
	}
	if(1==2){
		 if(document.getElementById("lstSelectedElements").length==0){
			document.getElementById("btnRemoveAllSelectedElements").disabled =true;
			document.getElementById("btnRemoveSelectedElement").disabled =true;
		 }
	}

	if(document.getElementById("lstSelectedCriteria").length==0){
		document.getElementById("btnRemoveAllCriteria").disabled =true;
		document.getElementById("btnRemoveCriterion").disabled =true;

	}
	//alert("v")



}







function hideCriteriaSpan(){
	var elementList=document.getElementById("lstAvailableElementsForCriteria")
 
	
	if(document.getElementById("lstAvailableElementsForCriteria").selectedIndex==-1){
		document.getElementById("divAdvancedContainer").style.display="none";
		//document.getElementById("lstAvailableElementsForCriteria").blur()

	} else {
		document.getElementById("divAdvancedContainer").style.display="";
	}
}

function showOrHideExtraStuff(theSection,theOptionText){
	if(document.getElementById("spanAgeRanges" + theSection)){
		if (theOptionText.indexOf("Between the Ages of...")>0){
	 		document.getElementById("spanAgeRanges" + theSection).style.display="";
 			//document.getElementById("spanAgeRanges" + theSection).style.visibility="visible";
			document.getElementById("lstFromAge" + theSection).focus();

		} else {
			document.getElementById("spanAgeRanges" + theSection).style.display="none";
		}
	}
	if(document.getElementById("spanIncomeRanges" + theSection)){
		if (theOptionText.indexOf("Income Between...")>0){
	 		document.getElementById("spanIncomeRanges" + theSection).style.display="";
			document.getElementById("lstFromIncome" + theSection).focus();
		} else {
			document.getElementById("spanIncomeRanges" + theSection).style.display="none";
		}
	}
	if(document.getElementById("spanBuildYearRanges" + theSection)){
		if (theOptionText.indexOf("Built Between...")>0){
		
	 		document.getElementById("spanBuildYearRanges" + theSection).style.display="";
	 		//document.getElementById("spanAgeRanges" + theSection).style.visibility="hidden";
			document.getElementById("lstFromBuildYear" + theSection).focus();
		} else {
			document.getElementById("spanBuildYearRanges" + theSection).style.display="none";
		}
	}
	if(document.getElementById("spanEducationLevels" + theSection)){
		if (theOptionText.indexOf("a Maximum Education Level of...")>0){
			document.getElementById("spanEducationLevels" + theSection).style.display="";
			document.getElementById("lstEducationLevel" + theSection).focus();
		} else {
			document.getElementById("spanEducationLevels" + theSection).style.display="none";
		}
	}
	if(document.getElementById("spanMaritalStati" + theSection)){
		if (theOptionText.indexOf("Marital Status of...")>0){
			document.getElementById("spanMaritalStati" + theSection).style.display="";
			document.getElementById("lstMaritalStatus" + theSection).focus();
		} else {
			document.getElementById("spanMaritalStati" + theSection).style.display="none";
		}
	}
	if(document.getElementById("spanCommuteTimeRanges" + theSection)){
		if (theOptionText.indexOf("Commute Time Between...")>0){
			document.getElementById("spanCommuteTimeRanges" + theSection).style.display="";
			document.getElementById("lstFromCommuteTime" + theSection).focus();
		} else {
			document.getElementById("spanCommuteTimeRanges" + theSection).style.display="none";
		}
	}

}

function enableOrDisableGoButton(){
	if(document.theForm.lstState.selectedIndex==0){
		document.theForm.goButton.disabled=true;
	} else {
		document.theForm.goButton.disabled=false;
	}
}

function setStateToSample(){
	document.getElementById("lstState").selectedIndex=21; //maryland
	handleStateListChanges('')
}
function refreshCountyList(selectedCounty){

	if (document.theForm.lstState != null) {
		var whichList=document.theForm.lstState;
		document.theForm.lstCounty.length=0;

		var countyArray=whichList.value.split(",")
		//document.theForm.lstCounty.options[0] = new Option("--Any County--",0);

		for (i=0;i<countyArray.length-1;i++){
			var countyIdAndName=countyArray[i].split("|");
			var countyId=countyIdAndName[0];
			if (countyId.indexOf(":")>0){
				countyId=countyId.split(":")[1];
			}
			var countyName=countyIdAndName[1];
			document.theForm.lstCounty.options[i] = new Option(countyName,countyId);
			if (selectedCounty==countyId){
				document.theForm.lstCounty.options[i].selected=true;
			}
		}

		if(document.theForm.lstState.selectedIndex==0){
//			document.getElementById('showOthers').style.display='none';
		} else {
			// 8/7/2008 took this out, since we are now showing the county and town list boxes whether the state is selected or not:
 			//document.getElementById('showOthers').style.display='';

		}
	}
}