var Success = false;
var count = 0;
var firstthru = true;
var loading;

function searchMessage(whichDiv)
{
	if (count < 3 && (!(firstthru)))
	{
		document.getElementById(whichDiv).innerHTML = document.getElementById(whichDiv).innerHTML + ".";
		count ++;
	}
	else
	{
		document.getElementById(whichDiv).innerHTML = "PERFORMING SEARCH";
		count = 0;
		firstthru = false;
	}
}
function closeDiv(whichDiv)
{
	$(whichDiv).animate({height: 'toggle', opacity: 'hide'}, "slow", "easeout" );
}
function CheckSearch(location,type,minprice,maxprice,bedrooms,bathrooms, gocounty) 
{
		Success = false;	
		if (type == 'foreclosure')
			type = "*&Foreclosure=Yes";
		document.getElementById("submit").value = "Searching...";
		var myurl = '/HomesCom/Include/AjaxSearchChecker.cfm';
		
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
		alert ("Browser does not support HTTP Request")
		return
		}
		
		var modurl = myurl + "?";
		
		modurl = modurl + "location=" + location + "&type=" + type + "&minprice=" + minprice + "&maxprice=" + maxprice;
		modurl = modurl + "&bedrooms=" + bedrooms + "&bathrooms=" + bathrooms + "&gocounty=" + gocounty;
		
		modurl = modurl + "&rand=" + parseInt(Math.random()*99999999);
		
		//alert(modurl);
			xmlHttp.onreadystatechange = xmlGetInfoSearch;
	
		xmlHttp.open("GET", modurl, true);
		
		
		xmlHttp.send(null);
		
	
		return Success;
	
}
			
function xmlGetInfoSearch() {
		
		if (xmlHttp.readyState == 4) {
		//alert("1");
			//if (xmlHttp.status == 200)
			//{
				//alert("2");
		//alert("!");
				if ( xmlHttp.responseText.length ) {
					var aResp = xmlHttp.responseText.split("||");
					//alert(aResp[0]);
					document.getElementById("Messages").innerHTML = aResp[0];
					clearInterval(loading);
					firstthru = true;
					count = 0;
					var toGo = aResp[1].replace(/^\s+|\s+$/g, '');
					//alert(toGo);	
					
					if (toGo == "GO")
					{	
						
						Success = true;
						document.getElementById('Messages').style.display = 'none';

						document.location = $.trim(aResp[2]);
						document.getElementById("submit").value = "Search Now";
					}
					else
					{
						$("div.smartMsg").animate({opacity: 'show'}, "slow", "easein" );
						document.getElementById('Messages').style.zIndex = 100;
						document.getElementById("submit").value = "Search Now";
					}

				}
			//}
		}
	}
	
function GetXmlHttpObject()
{ 
		var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
		objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
		return objXMLHttp
}