// SIMPLE AJAX FUNCTIONS


function createCalObject()
{
	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;
}

// Make the XMLHttpRequest object 
var http = createCalObject(); 

function displayQuickSearch() {
	http.open('get', '/rental/quicksearch.html');
   	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
      		var response = http.responseText;

      		if(response) { 
				document.getElementById("ajaxdata").innerHTML = parseScript(response);
      		} 
   		} 
	} 
   	http.send(null); 
}

// For evaluating JS in AJAX CALL
function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
 
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
 
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
 
		// Loop through every script collected and eval it

		for(var i=0; i<scripts.length; i++) {
			if(scripts[i] != ''){
				try {
					eval(scripts[i]);
				}
				catch(ex) {
					// do what you want here when a script fails
				}
			}
		}
		// Return the cleaned source
		return source;
}

