// for XMLHttpRequest
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function showHide(element_id,display){
  //firefox leaves scrollbar up if the inner div is large enough to scroll
  //call search without results so it shrinks small enough to lose scrollbar
  if(display == "hidden"){
        loadFragmentInToElement("search.php","searchresults");
  }
//show/hide the layer
if (document.getElementById) {
   // this is the way the standards work
   document.getElementById(element_id).style.visibility = display;
  }
  else if (document.all) {
  // this is the way old msie versions work
   document.all[element_id].style.visibility = display;
  }
  else if (document.layers) {
  // this is the way nn4 works
   document.layers[element_id].visibility = display;
  }
//
}

var time = '';
var hidesearch = true;

function setHideTimer(element_id,amount){
    clearTimeout(time);
    if(hidesearch) { //don't hide it if focus is on search text box
    	time = setTimeout("showHide('"+element_id+"','hidden')", amount);
    }
}

function loadFragmentInToElement(fragment_url, element_id) {
    showHide(element_id,"visible");
    setHideTimer(element_id,4000);

    var element = document.getElementById(element_id);
//    element.innerHTML = '<em>Searching...</em>';
    element.innerHTML = '';
    xmlhttp.open("GET", fragment_url,true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            element.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}


