//var xmlHttp

function createRequestObject() {
    if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        var xmlhttp = new XMLHttpRequest();
        if (xmlhttp.overrideMimeType)

xmlhttp.overrideMimeType('text/xml');
    }

	

else if (window.ActiveXObject) { // IE
        try {
            var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!xmlhttp) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }

	

return xmlhttp;
}

var xmlHttp = createRequestObject();

function showResult(str) {
   if (str.length==0) { 
      var div = document.getElementById('livesearch');
      div.innerHTML="";
      div.style.border="0px";
      alert('Some error message here');
  } else {
       var url="livesearch.php";
       url=url+"?q="+str;
       url=url+"&sid="+Math.random();
       //first we open the file
       xmlHttp.open("GET",url,true);
       //now we send anything that needs to be sent
       xmlHttp.send(null);
       //The stateChanged function will be called when ever the
       //readyState changes.
       xmlHttp.onreadystatechange=stateChanged; 

  }
}

function stateChanged() { 
    //the file has finished processing when the ready state is 4
  if ((xmlHttp.readyState==4) && (xmlHttp.status== 200)) { 
     var div = document.getElementById('livesearch');
     //now we put the text that was received from the backend file
     //in our content div..
     div.innerHTML=xmlHttp.responseText;
     div.style.border="1px solid #A5ACB2";
  } 
}


