//Prelimnary storage of xmlHttp Object
var xmlHttp = GetXmlHttpObject();

function process_object() 
{ 
	if ((xmlHttp.readyState==4) || (xmlHttp.readyState==0))
	{ 
		name = encodeURIComponent(document.getElementById("searchbox").value);
		branch = encodeURIComponent(document.getElementById("branch").value);
		department = encodeURIComponent(document.getElementById("department").value);
		docstring = "empdir_retrieve.php?name="+name+"&branch="+branch+"&department="+department;
		xmlHttp.open("GET","empdir_retrieve.php?name="+name+"&branch="+branch+"&department="+department,true);
		xmlHttp.onreadystatechange = responseHandler;
		xmlHttp.send(null); 
	} 
	else
	{
		//Try again after a second
		setTimeout("process_object()",1000);
	}
	
}

function responseHandler()
{
	
	if(xmlHttp.readyState==4)//Did the transaction complete
	{
		if(xmlHttp.status==200)//Did it complete successfully
		{
			document.getElementById("contact_info").innerHTML=xmlHttp.responseText;//display in appropriate container

		}
		else //Oopsy, response code that is not 200 is an error!!
		{
			alert("The server returned the following error: " + xmlHttp.statusText);
		}
	}
}
function GetXmlHttpObject()
{
	var xmlHttp;
	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");
		}
	}
	if(!xmlHttp)
	{
		alert("Error instantiating the xmlHttp object");
	}
	else
	{
		return xmlHttp;
	}
}
