/*
 * 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    
 * 
 */

//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 do_search() {
  var LFROM = "en";
  if (typeof LTO == 'undefined' ) { arg2 = 'es'; }
  var URL="search_script.php"; //relative URL
  
  searchstr = document.getElementById("search_str").value;
  searchresults = document.getElementById("search_results");
  
  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.
       		 searchresults.innerHTML = receiveReq.responseText;
	    }
    } 
		//Make the actual request.
		receiveReq.send(null);
	}			
}
