var xmlhttp;
var timeout = 1000;
var ajaxSearchHandle;
var SearchBoxId = "search";
//var siteUrl = "http://localhost/cmb/";
var siteUrl = "/";
var SearchUrl = siteUrl + "php/phonesearch2.inc.php";

function OnKeyUp_handler()
{
	
	if(ajaxSearchHandle!=null)
	{
		window.clearTimeout(ajaxSearchHandle);
		ajaxSearchHandle  = null;
	}
	if(document.getElementById(SearchBoxId).value.length > 1)
	{
		ajaxSearchHandle = window.setTimeout(DoSearch,timeout);
	}
}

function DoSearch()
{
	
	var searchString = document.getElementById(SearchBoxId).value;
	
	showResult(searchString);
}


function showResult(str)
{
//alert(str);
if (str.length==0)
  {
  document.getElementById("phonedata").innerHTML="";
  document.getElementById("phonedata").style.border="0px";
  return;
  }
xmlhttp=GetXmlHttpObject()
if (xmlhttp==null)
  {
  alert ("Your browser does not support XML HTTP Request");
  return;
  }
var url=SearchUrl;
url=url+"?search="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("phonedata").innerHTML=xmlhttp.responseText;
  document.getElementById("phonedata").style.border="1px solid #000";
  document.getElementById("phonedata").style.height="auto";
  document.getElementById("phonedata").style.width="500px";
  }
  else
  {
//	alert(xmlhttp.readyState);
	document.getElementById("phonedata").innerHTML="<p>Loading...</p>";
	document.getElementById("phonedata").style.border="1px dotted #000";
	document.getElementById("phonedata").style.height="100px";
  document.getElementById("phonedata").style.width="500px";
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}