function leadingZero() {
	frm = document.forms.searchForm;
	frm.submit();
}
function setDefaultClick(p_src, p_default) {
	if (p_src.value == p_default) {
		p_src.value = "";
	}
}
function setDefaultBlur(p_src, p_default) {
	if (p_src.value == "") {
		p_src.value = p_default;
	}
}
function updatePropertyType(p_obj) {
	var frm = p_obj.form;
	for (var i = 0; i < p_obj.options.length; i++ ) {
		var field = p_obj.options[i].value;
		if (field != "") frm[field].value = (i == p_obj.selectedIndex) ? "Y" : "";
	}
}
function quickSearch() {
	var frm = document.forms.frm_quicksearch;
	if (frm.property_id.value == "MLS Number") alert("Please enter an MLS Number.");
	else frm.submit();
}
function quickSearch2() {
	var frm = document.forms.searchForm;
	if (frm.address.value == "Address") frm.address.value = "";
	frm.submit();
}
city_county_loaded = "no";
city_page_load_first_run = "Y";
county_page_load_first_run = "Y";
useall = true;
allfactor = 1;
function checkDataLoad(){
	if (city_county_loaded == "no"){
		setTimeout ("checkDataLoad();", 250);
	}else{
		updateCounties();
		updateCities();
	}
}
function updateCounties(){
	f = document.searchForm;
	RemoveAll(f.county);
	if (useall){
		AddToSelect(f.county,"- County -","");
	}
	for (x=0; x<counties.length; x++){
		use_this_county = 1;
		chosen_state = f.state.options[f.state.selectedIndex].value;
		if(states[x] != chosen_state){
			use_this_county = 0;
		}
		if(use_this_county == 1){		
			AddToSelect(f.county,counties[x],counties[x]);
		}
	}
	f.county.selectedIndex=0;
	if (county_page_load_first_run == "Y"){
		county_page_load_first_run = "N";
		
		if ("" != ''){
			SelectOption(f.county, "", "");
		}else if ("" != ''){
			SelectOption(f.county, "", "");
		}
		
	}else{
		updateCities();
	}
}
function getCountyIndex(countyname){
	chosen_state = f.state.options[f.state.selectedIndex].value;
	for (x=0; x<counties.length; x++){
		if(counties[x] == countyname && states[x] == chosen_state){
			return(x);
		}
	}
}
function updateCities(){
	RemoveAll(f.citylist);
	f.city.value = "";
	AddToSelect(f.citylist, "- City -", "");
	countySelectIndex = f.county.selectedIndex - allfactor;
	if (countySelectIndex < 0){
		chosen_state = f.state.options[f.state.selectedIndex].value;
		chosen_state_index = listfind(state_list, chosen_state, ",");
		if(chosen_state_index > 0){
			for (x=0; x<all_array[chosen_state_index].length; x++){
				AddToSelect(f.citylist, all_array[chosen_state_index][x], all_array[chosen_state_index][x]);
			}
		}else{
			alert("No Cities in this state")
		}
	}else{
		countyIndex = getCountyIndex(f.county.options[f.county.selectedIndex].value)
		for (x=0; x<cities[countyIndex].length; x++){
			AddToSelect(f.citylist, cities[countyIndex][x], cities[countyIndex][x]);
		}
	}
}
var f;
function listfind(thelist, thevalue, delim){
	if (! delim){
		delim = ",";
	}
	l = listlen(thelist, delim);
	listpos = -1;
	
	for (var x = 1; x < l; x++){
		listelement = listgetat(thelist,x,delim);
		if (listelement == thevalue){
			listpos = x;
			break;
		}
	}
	return listpos;
}
window.onload=checkDataLoad;

