/*
 * Code pilfered from the AJAX Hello World to improve browser compatibility
 *    http://www.dynamicajax.com/fr/AJAX_Hello_World-271_290_322.html
 *    
 *    Tested on IE6, IE7, Firefox, Konqueror, and Safari
 *    Should work on Opera... it's usually about on par with Firefox
 *
 * This is a SIMPLE as CAKE Ajax API Script.    
 * 
 */

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		//Display your error message here. 
		//and inform the user they might want to upgrade
		//their browser.
		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
	}
}

var receiveReq = getXmlHttpRequestObject();

function ajax_call(URLRequest,output) {
  ajax_results = document.getElementById(output);
  
  // URLRequest = URL+'?search_str='+searchstr;

	//If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//Setup the connection as a GET call
		//True explicity sets the request to asyncronous (default).
		receiveReq.open("GET", URLRequest, true);
		//Set the function that will be called when the XmlHttpRequest objects state changes.
		receiveReq.onreadystatechange = function() {
    	//Check to see if the XmlHttpRequests state is finished.
	    if (receiveReq.readyState == 4) {
		     //Set the contents of our span element to the result of the asyncronous call.
       		 ajax_results.innerHTML = receiveReq.responseText;
	    }
    } 
		//Make the actual request.
		receiveReq.send(null);
	}			
}

function load_page(page) {
	var URL = page;
	side = document.getElementById("sidebar");
	side.style.visibility = "visible";
	ajax_call(URL,"sidebar");
}

function do_search() {
	var searchstring = document.getElementById("datasearch").value;
	var URL = "loaddata.php?q=" + searchstring;
	ajax_call(URL,"search_content");
}

