function filterCities(type, city_id, area)
{
	var location_cb = document.getElementById(city_id);

	if (!type || typeof location_cb == "undefined")
		return;


	ajax = new CAjax();
	ajax.m_cb = location_cb;
	ajax.onload = function()
	{
		// Clear all option except for first
		for (m=this.m_cb.options.length-1; m >= 1; m--) 
			this.m_cb.options[m]=null;

		var root = this.m_firstNode;
		var num = root.getNumChildren();
		for (i = 0; i < num; i++)
		{
			var city = root.getChildNode(i);
			if (city.m_name == "city")
			{
				//document.write(model.m_text);
				this.m_cb.options[this.m_cb.options.length] = new Option(unescape(city.m_text), unescape(city.m_text));
			}
		}
	};

	var url = "/xml_search_filter.php?function=cities&type=" + type;
	if (typeof area != "undefined")
		url += "&area=" + area;
	ajax.exec(url);
}

function filterTypes(type, type_id, area)
{
	var type_cb = document.getElementById(type_id);

	if (!type || typeof type_cb == "undefined")
		return;


	ajax = new CAjax();
	ajax.m_cb = type_cb;
	ajax.onload = function()
	{
		// Clear all option except for first
		for (m=this.m_cb.options.length-1; m >= 1; m--) 
			this.m_cb.options[m]=null;

		var root = this.m_firstNode;
		var num = root.getNumChildren();
		for (i = 0; i < num; i++)
		{
			var ptype = root.getChildNode(i);
			if (ptype.m_name == "property_type")
			{
				this.m_cb.options[this.m_cb.options.length] = new Option(unescape(ptype.m_text), unescape(ptype.m_text));
			}
		}
	};

	var url = "/xml_search_filter.php?function=types&type=" + type;
	if (typeof area != "undefined")
		url += "&area=" + area;
	ajax.exec(url);
}

function populateMap(url_vars)
{
	ajax = new CAjax();
	ajax.onload = function()
	{
		var root = this.m_firstNode;
		var num = root.getNumChildren();
		for (i = 0; i < num; i++)
		{
			var property = root.getChildNode(i);
			if (property.m_name == "property")
			{
				var price = property.getChildNodeValByName("price");
				var number_bedrooms = property.getChildNodeValByName("number_bedrooms");
				var total_bathrooms = property.getChildNodeValByName("total_bathrooms");
				var total_sqft = property.getChildNodeValByName("total_sqft");
				var lot_size = property.getChildNodeValByName("lot_size");
				var mls_number = property.getChildNodeValByName("mls_number");
				var street = property.getChildNodeValByName("street");
				var zip = property.getChildNodeValByName("zip");
				var image = property.getChildNodeValByName("image");

				var buf = "<h3>"+unescape(price)+"</h3>";
				buf += "<img align='left' src='" + unescape(image) + "' style='width:50px;height:50px; padding-right: 3px;'>";
				buf += unescape(number_bedrooms) + " BR / " + unescape(total_bathrooms) + " BA<br />";
				buf += "Size: " + unescape(total_sqft) + "<br />";
				buf += "Lot: " + unescape(lot_size) + "<br />";
				buf += "<a href='/property-details/" + unescape(mls_number) + "' style='color: black;'>View Details</a>";

				showAddress(unescape(street) + " " + unescape(zip), buf);
			}
		}
	};

	var url = "/xml_mapsearch.php?" + url_vars;
	ajax.exec(url);
}

/*
 * This function is used to clear additional values from any of the search forms
 */
function searchClearAdditional()
{
	if (document.getElementById('id_area'))
		document.getElementById('id_area').value = '';

	if (document.getElementById('id_agent'))
		document.getElementById('id_agent').value = '';

	document.propertysearch.submit();
}
