//<![CDATA[

// routines for rendering search query into content element

var searchControl;
var options;
var oldterm="";
var HashCheckInterval;

function OnLoad() {
        // create a search control
        searchControl = new GSearchControl();
        options = new GsearcherOptions();
        options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
        // options.setRoot(document.getElementById("search_results"));
        options.setNoResultsString('Uw zoekbewerking heeft geen overeenkomstige documenten opgeleverd');  
        siteSearch = new GwebSearch();
        siteSearch.setSiteRestriction("inghist.nl");
        searchControl.addSearcher(siteSearch, options);
        searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
        searchControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
        // tell the searcher to draw itself and tell it where to attach
        searchControl.draw(document.getElementById("search_results")); 
        // update location for proper history navigation  
        searchControl.setSearchStartingCallback(this, SetLocationHash);     
      }

function submitenter(myfield,e) {		
        var keycode;
        if (window.event) keycode = window.event.keyCode;
          else if (e) keycode = e.which;
	  else return true;		
	if (keycode == 13) {
          searchIt();
	  return false;
        }
	else
	  return true;
      }

function searchIt(term){
        OnLoad();      
        // check for being called outside searchbox
        if (term) {
          if(document.all) {
             //do some specific IE stuff                    
          }
          var user_input = term;
          document.forms['searchform'].elements[0].value = term;
        }
        else {
	  var user_input = document.forms['searchform'].elements[0].value;
        }
        searchControl.execute(user_input);   
        SwitchVisibility('none','block');	             
}  

function SwitchVisibility(swmain,swsearch){       
        // making some space for results
        div_a = document.getElementById("center_block") ;        
        if (div_a) {
	   div_a.style.display = swmain;
           // div_a.textContent="";
        }
        div_b = document.getElementById("main_block") ;
        if (div_b) {
	   div_b.style.display = swmain;
	   // div_b.textContent="";
        }	
        // making google main searchbox visible too
        div_c = document.getElementById("search_results");
        if (div_c) {
	   div_c.style.display = swsearch;
	   // div_c.textContent="";
        }
        //var allPageTags = new Array(); 
        // var allPageTags=document.getElementsByTagName("*");
        // for (i=0; i<allPageTags.length; i++) {
         //  if (allPageTags[i].className=='search_results'){
         //   allPageTags[i].style.display = swsearch;
         // }
       // }    
}

function SetLocationHash(sc, searcher, query) {
        window.location.hash = encodeURI("zoek:"+ query);
}

function initialiseStateFromURL() {
        var zoek = decodeURI(window.location.hash).split(':');
        if (zoek[0] == '#zoek' && oldterm != zoek[1]){
          oldterm = zoek[1]; 
          searchIt(zoek[1]); 
        }
        else if (zoek[0]!="#zoek" && oldterm != "") {
          oldterm = ""; 
          SwitchVisibility('block','none');
        }
}
     
function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) clearInterval(_timer);  
    //GSearch.setOnLoadCallback(OnLoad);
    HashCheckInterval = setInterval("initialiseStateFromURL()", 200);
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;


//]]>
