sortitems = 1;  // Automatically sort items within lists? (1 or 0)

function additem(fbox,tbox) {
	move(fbox,tbox);
	removeitembyname(tbox,"None Selected")
	if (sortitems) SortD(tbox);
}

function additembyname(tbox, theName) {
	if (tbox.options.length == 0) {
			var no = new Option();
			no.value = theName;
			no.text = theName;
			tbox.options[0] = no;
			tbox.length++;
	}
	BumpUp(tbox);
}

function removeitembyname(fbox, theName) {
	for(var i=0; i<fbox.options.length; i++) {
	
		if(fbox.options[i].value == theName) {
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		   }
	}
	BumpUp(fbox);
}

function removeitem(fbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			
			
			// var no = new Option();
			// no.value = fbox.options[i].value;
			// no.text = fbox.options[i].text;
			// tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		   }
	}
	BumpUp(fbox);
	additembyname (fbox,"None Selected")
}

// pc 12/05/06 i added this function to clear away the selected squirtbox when index.cfm loads
function flushIndex(fbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].value != "") {
		
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		   }
	}
	BumpUp(fbox);
	additembyname (fbox,"None Selected")
}

function move(fbox,tbox) {
	for(var i=0; i<fbox.options.length; i++) {
		if(fbox.options[i].selected && fbox.options[i].value != "") {
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;

			// check that this entry doesn't already exist.  If it doesn't, then add it

			var len = tbox.length;
			var found = false;
			for(var count = 0; count < len; count++) {
				if (tbox.options[count] != null) {
					if (no.text == tbox.options[count].text) {
					found = true;
					break;
					}
				}
			}


			if (found != true) {
				tbox.options[tbox.options.length] = no;
				len++;
			}
			// tbox.options[tbox.options.length] = no;
			// fbox.options[i].value = "";
			// fbox.options[i].text = "";
		   }
	}
	// BumpUp(fbox);
	if (sortitems) SortD(tbox);
}


function BumpUp(box)  {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].value == "")  {
for(var j=i; j<box.options.length-1; j++)  {
box.options[j].value = box.options[j+1].value;
box.options[j].text = box.options[j+1].text;
}
var ln = i;
break;
   }
}
if(ln < box.options.length)  {
box.options.length -= 1;
BumpUp(box);
   }
}

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
temp = temp_opts[x].value;
temp_opts[x].value = temp_opts[y].value;
temp_opts[y].value = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}

// This works with the body onLoad function 
//This function when invoked checks hidden field 'areaGuids' to see if it has any values
//if values are present the are inserted into the areaGuids field
//this is to maintain state when using the back button. -tb
function fillSelectedBox(){

if (document.frmProperty.areaGuids.value != ""){
var theStringSelected = document.frmProperty.areaGuids.value


var locationArraySelected = new Array();
var regionArraySelected = new Array();

locationArraySelected = theStringSelected.split(",");
//alert(locationArraySelected.length)
//alert(locationArraySelected)
var counter = 0;
	for (i=0;i < locationArraySelected.length;i=i+2) {
		var aString = locationArraySelected[i];
		var aString2 = locationArraySelected[i+1];
	 			var newopt = new Option( decodeURI(aString2), decodeURI(aString) ) ;
			document.frmProperty.areaGuids.options[counter] = newopt;
			counter++;
	 		
		}

	}

}
//this function takes the values in a selectedVersion field and adds them 
//to a hidden field so that they can be submitted and 
//readded to the selected Version field when using the back button  -tb
function fillTempList(){
	var tList = ""
	if (document.frmProperty.version != ''){
		a = document.frmProperty.selectedVersion.options.length
		for (var i=0; i<a; i++){
			if ((i+1) != a){
				optionValue = document.frmProperty.selectedVersion.options[i].value;
				optionText = document.frmProperty.selectedVersion.options[i].text;
				tList = tList + optionValue + "," 
			}
	else{
		optionValue = document.frmProperty.selectedVersion.options[i].value;
		optionText = document.frmProperty.selectedVersion.options[i].text;
		tList = tList + optionValue + ","}
	}
	
	tList = tList.substring(0,tList.length-1) 
	document.frmProperty.areaGuids.value = tList
	//alert(document.frmProperty.areaGuids.value)
	}
}

function changeChoice(tmpVal){
document.frmProperty.choices.value = tmpVal
}

//reloads page with new state parameter
function changeState(){
if (stateAbrev = document.frmProperty.state.options[document.frmProperty.state.selectedIndex].value != "" ){
stateAbrev = document.frmProperty.state.options[document.frmProperty.state.selectedIndex].value
location.href="/index.cfm?state=" + stateAbrev + "&newSearch=Y"
}

}



function changeShow(){
document.frmProperty.show.checked = false
}

//changes the index value for the county dropdown and reloads the map with the correct county
function changeIndexValue(newIndex){ 
//document.images.region.src = "/images/maps/" + stateAbrev + "/" + (newIndex) + ".gif"
document.frmProperty.county.options[newIndex].selected = document.frmProperty.county.options[newIndex]
refreshLocations()
document.frmProperty.location[0].checked = true
changeType(2)

}

//change form action to go to advance search page
function changeAction(newAct){

document.frmProperty.action = newAct
fillTempList()
document.frmProperty.submit();
}




