
function dhtmlLoadScript(url)
{
	if (document.getElementById && document.getElementById('please_wait')) {
		document.getElementById('please_wait').style.visibility = 'visible';
	}
	
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

function changeState()
{
	enableDisableSearch();
	document.searchFrm.county.value = 0;
	document.searchFrm.city.value = 0;
	dhtmlLoadScript('locations.js.php?state='+document.searchFrm.state.value);
	
}

function changeCounty()
{
	enableDisableSearch();
	document.searchFrm.city.value = 0;
	dhtmlLoadScript('locations.js.php?state='+document.searchFrm.state.value+'&county='+document.searchFrm.county.value);
}

function changeCity()
{
	enableDisableSearch();
	dhtmlLoadScript('locations.js.php?state='+document.searchFrm.state.value+'&county='+document.searchFrm.county.value+'&city='+document.searchFrm.city.value);
}

function changeGeocode()
{
	dhtmlLoadScript('locations.js.php?geocode='+document.searchFrm.geocode.value);
}

function enableDisableSearch()
{
	if ((document.searchFrm.state.value != '' && document.searchFrm.keywords.value != '') || document.searchFrm.zip_code.value != '' || document.searchFrm.city.value != ''){
		document.getElementById('search_submit_id').disabled = false;
		document.getElementById('search_submit_id').src = 'pics/search.gif';
		//enable search;
	}else{
		document.getElementById('search_submit_id').disabled = true;
		document.getElementById('search_submit_id').src = 'pics/search_faded.gif';
	}
}

function enableQueryField()
{
	if (document.searchFrm2.state.value != ''){
		_getElement('search').className = 'input_inactive';
		_getElement('search').disabled = false;
		_getElement('search2').className = 'input_inactive';
		_getElement('search2').disabled = false;
	}else {
		_getElement('search').className = 'input_disabled';
		_getElement('search').disabled = true;
		_getElement('search2').className = 'input_disabled';
		_getElement('search2').disabled = true;
	}
	if (!enableQueryField.arguments[0]){
		document.searchFrm2.county.value = '';
		document.searchFrm2.city.value = '';
		document.searchFrm2.geocode.value = '';
	}
}

var lastGeocode = '';

function assignGeocode(geocode,city,county)
{
	//if (lastGeocode == geocode) {
	//	return;
	//}
	
	document.searchFrm2.geocode.value = geocode;
	_getElement('row'+geocode).className = 'results_rowb';
	_getElement('row'+lastGeocode).className = 'results_row';
	lastGeocode = geocode;
	
	document.searchFrm2.city.value = city;
	document.searchFrm2.county.value = county;
	document.searchFrm2.county.focus();
	document.searchFrm2.county.select();
}

function getkey(e,fld)
{
	var key;
	if (window.event)
		 key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		key = null;
	if (key == 13){
		
		if (fld.form.name == 'searchFrm2'){
			var not_multiple = checkMultiple();	
			if (not_multiple)
				fld.form.submit();	
			else
				show_multiple_message = true;	
		}else
			fld.form.submit();	
	}else
		return true;
}


function clearZipFrm()
{
	frm = document.searchFrm;
	frm.address1.value = '';
	frm.address2.value = '';
	frm.city.value = '';
	frm.state.value = '';
	frm.zip_code.value = '';
	frm.plus4.value = '';
	
	
	return;
}

function clearLocationFrm()
{
	frm = document.searchFrm2;
	frm.state.value = '';
	enableQueryField();
	searchRequest(getSelectedValue(frm.state),frm.city.value,frm.county.value);
	return;
}
