// GET SEARCH RESULTS //
function addWindowEvent(strEvent, oFunction, bCapture){
	if(window.addEventListener){
		window.addEventListener(strEvent, oFunction, bCapture);
	}
	else if(window.attachEvent){
		window.attachEvent(("on" + strEvent), oFunction)
	}
}

var t = null;
addWindowEvent("load", function(){								  
	if (document.getElementById("filter")) {
			document.getElementById("filter").onkeyup = function() {
				if (t) {
					window.clearTimeout(t);
				}
				t = window.setTimeout("liveSearch('"+document.getElementById("filter").value+"')",200);
			}
	}
}, false);




function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
	catch (e) {
      try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
	  catch (E) { xmlhttp = false; }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try { xmlhttp = new XMLHttpRequest(); } 
	catch (e) {xmlhttp = false;}
  }
  return xmlhttp;
}
var http = getHTTPObject();



function liveSearch(thevalue) {
	
	if (thevalue == "") {	
	searchresults = "false"
	}else {
	searchresults = "true"
	}
	
	theid =  document.getElementById("filterid").value
	thearea = document.getElementById("filterarea").value 
	
		http.open("GET", "?area="+thearea+"&id="+theid+"&ajax=true&searchresults="+searchresults+"&filter=" + thevalue, true);		
		
		http.onreadystatechange = function handleHttpResponse() {
			
		  if (http.readyState == 4) {
			document.getElementById('searchresultsid').innerHTML = http.responseText;
		  }
			}		
		http.send(null);
			
}
