

function ClearList(myList) {
	if (myList.length == null) {
		return;
	}
	if (myList.length == 0) {
		return;
	}
	ctr = 0;
	while (ctr < myList.length) {
		myList.options[ctr] = null;
	}
}

function FillList (myList,myValues){
	ClearList(myList);
	var ctr=0;
	for (vals in myValues) {
  		//alert("The value of item '" + aa );
  		myList.options[ctr] = new Option(vals,vals);
  		ctr++;
	}
	return;
}


/*
* This will only be ran at the start
*/
function ChangeLocation(myValues) {
	//FillList(document.listings_form.country_loc);
	var myForm = document.listings_form;
	var myList = document.listings_form.country_loc;
	ClearList(myForm.country_state);
	ClearList(myForm.country_city);
	ClearList(myForm.country_town);
	FillList(myList,myValues);
}



/*
*	function for changing the list of states in a region
*/
function ChangeState() {
	var myForm = document.listings_form;
	var listValueFrom = myForm.country_loc;
	var myRegion = listValueFrom.options[listValueFrom.selectedIndex].value;
	var myValues = country[myRegion];
	var myList = myForm.country_state;
	ClearList(myForm.country_city);
	ClearList(myForm.country_town);
	FillList(myList,myValues);
	ChangeSearchLoc(myRegion);
}

/*
*	function for changing the list of cities
*/
function ChangeCity() {
	var myForm = document.listings_form;

	//Get the value of the region
	var listValueFrom = myForm.country_loc;
	var myRegion = listValueFrom.options[listValueFrom.selectedIndex].value;

	//Get the value of the state
	listValueFrom = myForm.country_state;
	var myState= listValueFrom.options[listValueFrom.selectedIndex].value;

	var myValues = country[myRegion][myState];
	var myList = myForm.country_city;

	ClearList(myForm.country_town);
	FillList(myList,myValues);
	ChangeSearchLoc(myState);
}

/*
*	function for changing the list of cities
*/
function ChangeTown() {
	var myForm = document.listings_form;

	//Get the value of the region
	var listValueFrom = myForm.country_loc;
	var myRegion = listValueFrom.options[listValueFrom.selectedIndex].value;

	//Get the value of the state
	listValueFrom = myForm.country_state;
	var myState= listValueFrom.options[listValueFrom.selectedIndex].value;

	//Get the value of the city
	listValueFrom = myForm.country_city;
	var myCity= listValueFrom.options[listValueFrom.selectedIndex].value;

	//alert(myRegion + " " + myState + " " + myCity);
	//return;

	var myValues = country[myRegion][myState][myCity];
	var myList = myForm.country_town;

	FillList(myList,myValues);
	ChangeSearchLoc(myCity);
}

function GetTownVal() {
	var myForm = document.listings_form;

	var listValueFrom = myForm.country_town;
	var myTown = listValueFrom.options[listValueFrom.selectedIndex].value;
	ChangeSearchLoc(myTown);
}

/*
*	function for changing the location to search
*/
function ChangeSearchLoc(newValue) {
	var myForm = document.listings_form;
	myForm.search_location.value = newValue;

}