// JavaScript Document

/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

if (xmlHttp) { 
   //document.getElementById('logo').innerHTML="AJAX Object Ready"; 
}

function sendAjax() {
	
	var term = escape(document.getElementById('searchInput').value);
	
	var url = "http://www.cmedev.info/wp-content/themes/CrescentMoon/searchbox.php";
	var params = "term="+term;
	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
	 if (term.length > 2) {	
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	 }
	}
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			document.getElementById('searchBoxResults').innerHTML=xmlHttp.responseText;
		}
	}
	
	xmlHttp.send(params);
}

