
function ClearCounty()
{
	idx = 0;
	if (document.criteria.county) {
		if (document.criteria.county.selectedIndex != -1) {
			while (idx < document.criteria.county.length) {
				if (document.criteria.county.options[idx].selected) {
					document.criteria.county.options[idx].selected = false;
				}
				idx++;
			}
		}
	}
	return 1;
}

function ClearCountyCode()
{
	idx = 0;
	if (document.criteria.countycode) {
		if (document.criteria.countycode.selectedIndex != -1) {
			while (idx < document.criteria.countycode.length) {
				if (document.criteria.countycode.options[idx].selected) {
					document.criteria.countycode.options[idx].selected = false;
				}
				idx++;
			}
		}
	}
	return 1;
}

function ClearCity()
{
	idx = 0;
	if (document.criteria.city) {
		if (document.criteria.city.selectedIndex != -1) {
			while (idx < document.criteria.city.length) {
				if (document.criteria.city.options[idx].selected) {
					document.criteria.city.options[idx].selected = false;
				}
				idx++;
			}
		}
	}
	return 1;
}

function ClearCityCode()
{
	idx = 0;
	if (document.criteria.citycode) {
		if (document.criteria.citycode.selectedIndex != -1) {
			while (idx < document.criteria.citycode.length) {
				if (document.criteria.citycode.options[idx].selected) {
					document.criteria.citycode.options[idx].selected = false;
				}
				idx++;
			}
		}
	}
	return 1;
}

function ClearArea()
{
	idx = 0;
	if (document.criteria.area) {
		if (document.criteria.area.selectedIndex != -1) {
			while (idx < document.criteria.area.length) {
				if (document.criteria.area.options[idx].selected) {
					document.criteria.area.options[idx].selected = false;
				}
				idx++;
			}
		}
	}
	return 1;
}

function VerifyCityCountySelection( )
{
	if (document.criteria.city && document.criteria.county) {
		if (document.criteria.city.selectedIndex == -1 && document.criteria.county.selectedIndex == -1) {
			alert( "Please choose at least one City or County");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.city) {
		if (document.criteria.city.selectedIndex == -1) {
			alert( "Please choose at least one City");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.county) {
		if (document.criteria.county.selectedIndex == -1) {
			alert( "Please choose at least one County");
			return false;
		} else {
			return true;
		}
	}

	return true;
}

function VerifyCityCountyCodeSelection( )
{
	if (document.criteria.citycode && document.criteria.countycode) {
		if (document.criteria.citycode.selectedIndex == -1 && document.criteria.countycode.selectedIndex == -1) {
			alert( "Please choose at least one City or County");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.citycode) {
		if (document.criteria.citycode.selectedIndex == -1) {
			alert( "Please choose at least one City");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.countycode) {
		if (document.criteria.countycode.selectedIndex == -1) {
			alert( "Please choose at least one County");
			return false;
		} else {
			return true;
		}
	}

	return true;
}

function VerifyCityAreaSelection( )
{
	if (document.criteria.city && document.criteria.area) {
		if (document.criteria.city.selectedIndex == -1 && document.criteria.area.selectedIndex == -1) {
			alert( "Please choose at least one City or Area");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.city) {
		if (document.criteria.city.selectedIndex == -1) {
			alert( "Please choose at least one City");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.area) {
		if (document.criteria.area.selectedIndex == -1) {
			alert( "Please choose at least one Area");
			return false;
		} else {
			return true;
		}
	}

	return true;
}

function VerifyCityCodeAreaSelection( )
{
	if (document.criteria.citycode && document.criteria.area) {
		if (document.criteria.citycode.selectedIndex == -1 && document.criteria.area.selectedIndex == -1) {
			alert( "Please choose at least one City or Area");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.citycode) {
		if (document.criteria.citycode.selectedIndex == -1) {
			alert( "Please choose at least one City");
			return false;
		} else {
			return true;
		}
	}
	if (document.criteria.area) {
		if (document.criteria.area.selectedIndex == -1) {
			alert( "Please choose at least one Area");
			return false;
		} else {
			return true;
		}
	}

	return true;
}

function VerifyZipSelection( )
{

	if (document.criteria.zip) {
		if (document.criteria.zip.selectedIndex == -1) {
			alert( "Please choose at least one Zip Code");
			return false;
		} else {
			return true;
		}
	}

	return true;
}

// Check whether string s is empty.

	function IsEmpty(str) {
		return ((str == null) || (str.length == 0));
	}

	function IsDigit(ch) {
		return ((ch >= "0") && (ch <= "9"));
	}

	// Is the string a valid 5 digit zip code
	function IsZip(str) {
		if (IsEmpty(str)) {
			return false;
		}
		if (str.length != 5) {
			return false;
		}
		for (i=0; i < str.length; i++) {
			if (IsDigit(str.charAt(i))) {
				// Keep Going
			} else {
				return false;
			}
		}
		return true;
	}

	function IfValidZipClearCity() {
		var thelist = document.forms.criteria.citycode;
		var i;

		if (IsZip(document.forms.criteria.zip.value)) {
			for(i=0; i < thelist.length; i++) {
				thelist.options[i].selected=0;
			}
		}
	}
	function IsCitySelected() {
		if (document.criteria.citycode.selectedIndex == -1) {
			return false;
		} else {
			return true;
		}
	}
	function IfCityClearZip() {
		if (IsCitySelected()) {
			document.forms.criteria.zip.value = '';
		}
	}
	function CheckCityZip() {
		if (IsZip(document.criteria.zip.value)) {
			IfValidZipClearCity();
			return true;
		} else {
		    if (IsCitySelected()) {
				// Ok
			} else {
				alert('Please select atleast one area or zip code');
				return false;
			}
		}
		return true;
	}

function handlestreetname(_str)
{
    _str=_str.toUpperCase();
	_str=" " + _str + " ";
	new Array
	streettype =[" WAY " , " WY ", " WALK ", " WALKWAY ", " VIS ", " VISTA ", " TUNL ", " TUNNEL ", " TRL ", " TRAIL ", " TER ", " TERR ", " TERRACE ", " ST ", " STREET ", " RD ", " ROAD ", " RISE ", " RTE ", " RAMP ", " ROUTE ", " PL ", " PLACE ", " PKWY ", " PARKWAY ", " PARK ", " OPAS ", " OVER PASS ", " LOOP ", " LP ", " LN ", " LANE ", " KY ", " KEY ", " HOLW ", " HOLLOW ", " HWY ", " HIGHWAYS ", " HIGHWAY ", " FWY ", " FREEWAYS ", " FREEWAY ", " EXT ", " EXTENSION ", " EXPY ", " EXPRESS FREEWAY ", " DR ", " DRIVE ", " CTO ", " CUT OFF ", " CRES ", " CREST ", " CT ", " COURT ", " CIR ", " CIRCLE ", " BRG ", " BRIDGES ", " BLVD ", " BOULEVARD ", " AVE ", " AVENUE ", " ALY ", " ALLEY ", " ACRD ", " ACCESS ROAD ", " ANNEX ", " ARCADE ", " ANX ", " ARC ", " AV "];

	streetsuffix = [" W ", " WEST ", " SW ", " SOUTHWEST ",  " SE ", " SOUTHEAST ", " S ", " SOUTH ", " NW ", " NORTHWEST ",  " NE ",  " NORTHEAST ",  " N ", " NORTH ", " E ", " EAST "];

	for (var i=0; i < streettype.length; i++)
	{
		newstr = _str.replace(streettype[i], "");
		_str = newstr;
	}
	for (var i=0; i < streetsuffix.length; i++)
	{
		newstr = _str.replace(streetsuffix[i], "");
		_str = newstr;
	}

	newstr = _str.replace(/^\s+/, "").replace(/\s+$/, "");
	document.criteria.addr_street.value=newstr;

}

function VerifyFieldIsNotBlank(theForm, fieldName, message)
{
	var blank = 1;

	for (i = 0; i < theForm.elements.length; i++) {
		if ((theForm.elements[i].name == fieldName) && (theForm.elements[i].value != '')) {
			blank = 0;
		}
	}
	if (blank == 1) {
		alert(message);
		return false;
	} else {
		return true;
	}
}


function RadiusSearchClearRadius()
{
	var idx = 0;

	if (document.criteria.radius) {
		document.criteria.radius.selectedIndex = 0;
	}
	return 1;
}


function RadiusSearchNumberOfSelectedItems(obj)
{
	var i;
	var count = 0;

	for (i=0; i < obj.length; i++) {
		if (obj.options[i].selected) {
			count++;
		}
	}
	return count;
}
	

function RadiusSearchCheckRadiusChange() 
{
	var msg = '';
	if (document.criteria.radius.value > 0) {
		if (RadiusSearchNumberOfSelectedItems(document.criteria.citycode) > 1) {
			msg = 'Please select only one city to perform a radius search.';
		} else if (RadiusSearchNumberOfSelectedItems(document.criteria.countycode)  > 0) {
			msg = 'Unable to perform a radius search based on county.  Please select one city and the radius to perform a radius search.';
		}
		if (msg != '') {
			RadiusSearchClearRadius();
			alert(msg);
			return false;
		}
	}
	return true;
}

function RadiusSearchCheckCityChange()
{
	msg = '';
	if (document.criteria.radius.value > 0) {
		if (RadiusSearchNumberOfSelectedItems(document.criteria.citycode)  > 1) {
			msg = 'Unable to perform a radius search with more than one city selected.  To perform a radius search, please select only one city and the radius.';
			RadiusSearchClearRadius();
			alert(msg);
			return false;
		}
	}
	return true;
}

function RadiusSearchCheckCountyChange()
{
	msg = '';
	if (document.criteria.radius.value > 0) {
		msg = 'Unable to perform a radius search based on county.  To perform a radius search, please select a city and the radius.';
		RadiusSearchClearRadius();
		alert(msg);
		return false;
	}
	return true;
}


