var xmlHttp
document.onclick=check; 
var lscount=0;
var lsactive=false;
function lskeycheck(e)
{
  var keynum = (window.event) ? event.keyCode : e.keyCode;
  if(document.getElementById('livesearchtable') != null)
  {
	switch(keynum)
	   {
	      case 38:
	      if((lscount > 0) && lsactive)
	      {
	      	document.getElementById('lstr'+(lscount)).className="lsbg2";
	      	lscount=lscount-1;
	      	document.getElementById('lstr'+lscount).className="lsbg1";
	      }
	      break; 
	      case 40:
	      if ((lscount < document.getElementById('livesearchtable').rows.length-1) && lsactive){
		      document.getElementById('lstr'+(lscount)).className="lsbg2";
		      lscount=lscount+1;
		      document.getElementById('lstr'+lscount).className="lsbg1";
	      }
	      else if((lsactive==false) && (document.getElementById('livesearchtable').rows.length > 0))
	      {
	      	var i=0;
	      	for(i=0;i<document.getElementById('livesearchtable').rows.length;i++)
	      		document.getElementById('lstr'+i).className="lsbg2";
	      	lsactive=true;
	      	lscount=0;
	      	document.getElementById('lstr'+lscount).className="lsbg1";
	      }
	      break; 
	      case 13:
	      	if (lsactive)
	      	{
	      		$surl='playerstats.php?playerid='+document.getElementById('lsh'+lscount).value
	      		window.location.replace( $surl);
		      return false;
	      	}
	      	else
	      		document.searchform.submit();
	      break; 
	   }
  }
   return true;
}
function lsmover(elem){
	if(lsactive)
	{
		document.getElementById('lstr'+lscount).className="lsbg2";
		lsactive=false;
	}
	elem.className="lsbg1";
}
function lsmout(elem){
	if(lsactive)
	{
		document.getElementById('lstr'+lscount).className="lsbg2";
		lsactive=false;
	}
	elem.className="lsbg2";
}
function check(e){ 
var target = (e && e.target) || (event && event.srcElement);
var obj = document.getElementById('livesearch');
var obj2 = document.getElementById('sho');
var parent = checkParent(target); 
if(parent){obj.style.display='none'} 
if(target==obj2){obj.style.display='block'} 
} 
function checkParent(t){ 
while(t.parentNode){ 
if((t==document.getElementById('livesearch')) || (t==document.getElementById('searchdiv'))){ 
return false 
}
t=t.parentNode 
} 
return true 
}
function showResult(str,e)
{
	var keynum = (window.event) ? event.keyCode : e.keyCode;
	if (!((keynum==38)||(keynum==40)||(keynum==13)))
	{
		lsactive=false;
		document.getElementById("livesearch").
		 style.display="inline";
		if (str.length==0)
		 { 
		 document.getElementById("livesearch").
		 innerHTML="";
		 document.getElementById("livesearch").
		 style.border="0px";
		 return
		 }
		
		xmlHttp=GetXmlHttpObject()
		
		if (xmlHttp==null)
		 {
		 alert ("Browser does not support HTTP Request")
		 return
		 } 
		
		var url="livesearch.php"
		url=url+"?q="+str
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("livesearch").
 innerHTML=xmlHttp.responseText;
 document.getElementById("livesearch").
 style.border="1px solid #A5ACB2";
 } 
}

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;
}
