/**
 * @param theText	dom text object
 * @param eraseVal	value if matched will be erased
 * @return	NULL
 */
function clearBoxValueIf(theText, eraseVal) {
	if (theText.value == eraseVal) {
		theText.value = "";
	}
}

/**
 * @param theText	dom text object
 * @param insertVal	value to be inserted if empty
 * @return NULL
 */
function insertDefaultValue(theText, insertVal) {
	if (theText.value == "") {
		theText.value = insertVal;
	}
}

/**
 * @param theForm dom Form Object
 * @return NULL
 */
function submitSelectedForm(theForm, disAllowText){
	if(document.getElementsByName("location")[0].value == disAllowText
	|| document.getElementsByName("location")[0].value == "")
	{
		alert('Please Enter ' + disAllowText);
		document.getElementsByName("location")[0].focus();
		return false;
	}else if(document.getElementsByName("listing_status")[0].value == "Agents")
		theForm.action = document.getElementsByName("action2")[0].value;
	else
		theForm.action = document.getElementsByName("action1")[0].value;
	return true;
}

function get_location_message(selectedval, locationText){
	//related with get_location_message && insertSearchDefaultValue
	if(locationText == "Address, City & State, or Zip" 
	|| locationText == "Name, City, or Neighborhood" 
	|| locationText == "City, State, or Zip"
	|| locationText == "")
	{
		if(selectedval=="For-Sale"){
			$('#location').val("Address, City & State, or Zip");
		}else if(selectedval=="Agents"){
			$('#location').val("Name, City, or Neighborhood");
		}else if(selectedval=="Foreclosures"){
			$('#location').val("City, State, or Zip");
		}
	}
}

function clearSearchBoxValueIf(theText) {
	//related with get_location_message && insertSearchDefaultValue
	if (theText.value == "Address, City & State, or Zip" 
		|| theText.value == "Name, City, or Neighborhood" 
		|| theText.value == "City, State, or Zip") {
		theText.value = "";
	}
}

function insertSearchDefaultValue(theText, selected){
	//related with get_location_message && clearSearchBoxValueIf
	if (theText.value == "") {
		get_location_message(selected, theText.value);
	}
}

function submitSearchSelectedForm(theForm, locationText){
	if(locationText == "Address, City & State, or Zip" 
	|| locationText == "Name, City, or Neighborhood" 
	|| locationText == "City, State, or Zip"
	|| locationText == "")
	{
		alert('Please Enter ' + locationText);
		$('#location').focus();
		return false;
	}else if($('#search-type').val() == "Agents")
		theForm.action = $('#action2').val();
	else
		theForm.action = $('#action1').val();
	return true;
}
