var xmlHttp // creates a global variable called xmlHttp

function showHint(ev, str)
{
	var keyPressed = (ev.charCode) ? ev.charCode: ( (ev.keyCode) ? ev.keyCode : ( (ev.which) ? ev.which:0));
	
	if ( keyPressed == 40 || keyPressed == 63233 || keyPressed == 38 || keyPressed == 63232  || keyPressed == 37 || keyPressed == 63234 || keyPressed == 39 || keyPressed == 63235 ) { 
	return;
	}
if (str.length<1) // i.e. if less than 2 characters entered in search field. I have changed this from ==0 in the origianl code
  { 
  return;
  }

xmlHttp=GetXmlHttpObject(); // Calls on the GetXmlHttpObject function to create an XMLHTTP object
if (xmlHttp==null) // Checks if the server supports ajax
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

var url="gethint.php"; // Defines the url (filename) to send to the server
url=url+"?q="+str; // Adds a parameter (q) to the url with the content of the input field
url=url+"&sid="+Math.random(); // Adds a random number to prevent the server from using a cached file
// example of url that will be sent to the server: gethint.php?q=eps&id=1345

xmlHttp.onreadystatechange=stateChanged; // tells the object to execute a function called stateChanged when a change is triggered
xmlHttp.open("GET",url,true); // Opens the XMLHTTP object with the given url
xmlHttp.send(null); // Sends an HTTP request to the server
} 

function stateChanged() // This function executes every time the state of the XMLHTTP object changes. When the state changes to 4 (or to "complete"), the content of the txtHint placeholder is filled with the response text.
{ 
if (xmlHttp.readyState==4)
{ 
var hints = eval(xmlHttp.responseText);
suggest.updateSuggestList( hints );
//document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject() // this function gets the ajax XHR object which depends on the browser type
{
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;
}