function updateText(textBox, defaultVal) {
	if(textBox.value == defaultVal) { 
		textBox.value = ''; 
	} 
}

function updateTextEmpty(textBox, defaultVal) {
	if (textBox.value == '') { 
		textBox.value = defaultVal; 
	}
}

function submitHomeForm(form) {
	if(form.browseAddress.value == 'city and state or zip') {
		alert('Please enter a city and state or zip');
		return false;
	}
	else {
		if(form.browseMinPrice.value == 'min price')
			form.browseMinPrice.value = '';
		if(form.browseMaxPrice.value == 'max price')
			form.browseMaxPrice.value = '';
		
		return true;
	}
}

/*
 *  Toggles the "view all cities" checkbox, and the city check box
 *
 */
 function toggleCheckBox(frm, obj, target)
 {
 	// The search form is passed into this function
 	var searchForm = frm;
 	// Get a handle on the "view all cities" checkbox
 	var viewAllCB = document.getElementById('all_cities_check_box');
 	
 	if (obj.checked && target == "city")
 	{
 		// if a single city is checked, see if ALL others are checked, and if so,
        // check the "view all" checkbox accordingly
 		if (boolCitiesAllChecked(searchForm))
		{
			if (!viewAllCB.checked)
	 		{
	 			viewAllCB.click();
	 		}
		}
 	} 
 	else if (!obj.checked && target == "city")
 	{
 		if (viewAllCB.checked)
 		{
 			viewAllCB.click();
 		}
 	}
 	else if (obj.checked && target == "all_cities")
 	{
 		// check ALL of the cities
 		//alert('all cities button checked');
 		if (!boolCitiesAllChecked(frm))
 		{
 			checkEachCity(searchForm);
 		} 		
 	}
 	else if (!obj.checked && target == "all_cities")
 	{
 		//alert('all cities button unchecked');
 	}
 }
 
 /** 
  * Gets all checkboxes in the search form
  * @param the search form
  * @return Boolean false if any single city is unchecked.
  */
function boolCitiesAllChecked(frm)
{
	var eLength = frm.elements.length;	
	var citiesAllChecked = true;
	
	for (var i=0; i<eLength; i++)
    {
        var type = frm.elements[i].type;
        if (type=="checkbox" && !frm.elements[i].checked)
        {
        	if (frm.elements[i].name != "browseAddress_0")
        	{
        		citiesAllChecked = false;
        	}        	        
        }
    }
    return citiesAllChecked		
}

 /** 
  * Checks each city checkbox in the search form
  * @param the search form
  */
function checkEachCity(frm)
{
	var eLength = frm.elements.length;	
	for (var i=0; i<eLength; i++)
    {
        var type = frm.elements[i].type;
        if (type=="checkbox" && !frm.elements[i].checked)
        {
        	frm.elements[i].click();        	        
        }
    }
}

/**
 * Submits the search form
 * @param the search form to be submitted
 *
 */
function doSearch(frm)
{
	var boolReturn = false;
	if (frm.region.options[frm.region.options.selectedIndex].value != "*")
	{
		boolReturn = true;
	}
	return boolReturn;
}