var xmlHttp, t, lineHeight, theOutput, lastString;
var theQuery, discModel, discBrand, discType, discWeight, discColor, discCondition
var hintActive = false;

function showHint(str1)
{
	//query has changed, proceed (prevents 'search' on non alphanumeric/char keys like alt, ctrl, etc)
	if (str1!=lastString)
	{
		lastString = str1;
		if (str1.length >= CONFIG_strLength)
		{//Show 'Searching...' message
			//show 'searching' div
			document.getElementById('searchDIV').style.display='';
		}
		
		//after an x millisecond delay, process search (a lil easier on the server)
		if (t) {clearTimeout(t);}		
		t=setTimeout("showHint2(1,'" + escape(str1) + "')",CONFIG_delay);
	}
}

function showHint2(changeType, str)
{
	//show 'searching' div
	document.getElementById('searchDIV').style.display='';
	
	discModel 		= document.getElementById('discmodel').value;
	discBrand 		= document.getElementById('discbrand').value;
	discType  		= document.getElementById('disctype').value;
	discWeight		= document.getElementById('discweight').value;
	discColor 		= document.getElementById('disccolor').value;
	discCondition	= document.getElementById('disccondition').value;
	
	theQuery = '&model=' + discModel;
	theQuery = theQuery + '&brand=' + discBrand;
	theQuery = theQuery + '&type=' + discType;
	theQuery = theQuery + '&weight=' + discWeight;
	theQuery = theQuery + '&color=' + discColor;
	theQuery = theQuery + '&condition=' + discCondition;
	theQuery = theQuery + '&sort=' + searchSort;
	theQuery = theQuery + '&user=' + searchUser;	
	
	if (changeType==1)
	{theQuery = theQuery + '&q=' + str;}
	else
	{theQuery = theQuery + '&q=' + document.getElementById('searchusername').value;}

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{alert ("Your browser does not support AJAX!"); return;} 
	var url=CONFIG_XMLPath + "?strLength=" + CONFIG_strLength + theQuery;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{//get the amount of items, adjust div height accordingly, and populate it.
		theOutput = xmlHttp.responseText
				
		//hide 'searching' div
		document.getElementById('searchDIV').style.display='none';
		
		document.getElementById("mainSearch").innerHTML=theOutput;
	}
}
	
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	  catch (e)
		{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
	  }
	return xmlHttp;
}
