/* ---------------------------- */
/* XMLHTTPRequest Enable 		*/
/* ---------------------------- */
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}


function createXMLHttpRequest() {
	var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  return xmlHttp;
}


var http = createXMLHttpRequest();

/* -------------------------- */
/* SEARCH					 */
/* -------------------------- */
function autosuggest() {
var load = document.getElementById('results');
load.innerHTML="<table align=center><tr><td align=center><b>ASSISTANCE IN PROGRESS<b><br><img src='/images/animated_progress_bar.gif'></td></tr></table>";
load.style.display="block";
	
q = document.getElementById('search-q').value;
t = getType();

// Set te random number to add to URL request
nocache = Math.random();
http.open('get', '/lib/search.php?q='+q+'&t='+t+'&nocache = '+nocache);
http.onreadystatechange = autosuggestReply;
http.send(null);
}
function autosuggestReply() {
if(http.readyState == 4){
	
	var response = http.responseText;
	e = document.getElementById('results');
	if(response!=""){
		e.innerHTML=response;
		e.style.display="block";
	} else {
		e.style.display="none";
	}
}
}

function getType()
{	
	var t;
    for (i=0; i<document.searchform.type.length; i++)
    {
    	if (document.searchform.type[i].checked==true)
        {
        	t = document.searchform.type[i].value;
        }
    }
	return t;
}