String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function saveListing(lth)
{
	if (document.getElementById("container1"))
		document.getElementById("save_search_panel").style.top = document.getElementById("container1").style.height;
	else
		document.getElementById("save_search_panel").style.top = "150px";

	$('save_listing_lth').value = lth;
	GDownloadUrl("/ajax/add_favorite.php?lth=" + lth, parseSaveResponse);
}

function parseSaveResponse(data, responseCode)
{
	var xml = GXml.parse(data);
	var response = xml.documentElement;
	if (!parseAjaxResponse(response))
	{
		$('immediate_close').value = "true";
		$('save_search_panel').style.display = "block";
	}
}

function saveListingAjax(lth)
{
	var simple = new SimpleAjax("saveListing", "/ajax/add_favorite.php?ajax_response=true&lth=" + lth, parseAjaxResponse);
	simple.sendGet(null);
}

var onPropertyDetails = false;

function parseAjaxResponse(response)
{
	var rv = response.getAttribute("rv");
	
	if(rv == "true" || rv == "1")
	{
		alert("The listing has been added to your saved listings.");
		return true;
	}
	else
	{
		
		if(onPropertyDetails) alert(response.firstChild.nodeValue);
		return false;
	}
}
