var xmlHttp

document.onclick = removeDropDown;

function removeAutocomplete(){
	document.getElementById('searchField').setAttribute("autocomplete", "off");	
}

function activateDropDown(term, e){
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if (KeyID == 40 || KeyID == 38) {
		var currentLi = 0;
		var maxList = 0;
		for (var i=1; i<11; i++){
			if (document.getElementById('searchListResult'+i) != null ) maxList++;
		}
		for (var i=1; i<=maxList; i++){
			if (document.getElementById('searchListResult'+i).className == 'on') currentLi = i;
		}
		if (KeyID == 40) nextLi = currentLi + 1;
		if (KeyID == 38) nextLi = currentLi - 1;
		if (nextLi > maxList) nextLi = 1;
		if (nextLi < 1) nextLi = maxList;
		if (currentLi >= 1 && currentLi <= maxList) document.getElementById('searchListResult'+ currentLi).className='';
		document.getElementById('searchListResult'+ nextLi).className='on';
		document.getElementById('searchField').value = document.getElementById('searchListLink'+ nextLi).name;
	}else{
		findSearches(term);
	}
}

function removeDropDown(){
	document.getElementById("searchDropDown").innerHTML = "";	
}

function findSearches(term)
{
if (term.length==0)
  { 
  document.getElementById("searchDropDown").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url= "http://www.drainageonline.co.uk/scripts/searchResults.asp";
url=url+"?term="+term;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("searchDropDown").innerHTML=xmlHttp.responseText;
}
}

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;
}
