var xmlHttp=createXmlHttpRequestObject(); 

function createXmlHttpRequestObject() 
{	
	var xmlHttp;
	
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) 
		{
			xmlHttp=false;
		}
	}
	else
	{
		try 
		{
			xmlHttp=new XMLHttpRequest();
		}
		catch(e) 
		{
			xmlHttp=false;
		}
	}

	if(!xmlHttp) alert("Error creating the XMLHttpRequest object.");
	else return xmlHttp;
}

function LiveSearch()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		name=document.getElementById("livesearch_pole").value;
		xmlHttp.open("GET", "livesearch.php?name=" + name, true);  
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
}

function handleServerResponse() 
{
	if(xmlHttp.readyState==4) 
	{
		if(xmlHttp.status==200) 
		{
			xmlResponse=trim11(xmlHttp.responseText);
			if(xmlResponse!='')
			{
				document.getElementById("livesearch_container").style.display='block';
				document.getElementById("livesearch_container").innerHTML=xmlResponse;
			}
			else
			{
				document.getElementById("livesearch_container").style.display='none';
			}
			
			setTimeout('LiveSearch()', 1000);
		} 
		else 
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function trim11(str) 
{
	str=str.replace(/^\s+/, '');
	for(var i=str.length-1;i >= 0;i--) 
	{
		if(/\S/.test(str.charAt(i))) 
		{
			str = str.substring(0, i + 1);
			break;
		}
	}
	
	return str;
}
