// JavaScript Document
// adapted from code found here: http://www.edoceo.com/intmain/20060513-using-ajax.php
xmlHTTP = false;

function createXmlHttpRequestObject(){
	xmlHTTP = false;
	//stores a reference to the object
	//var xmlHttp;
	//for IE only
	if(window.ActiveXObject){
		try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			xmlHttp = false;
		}
	}else{ //for firefox and other non-ie browsers
		try{
			xmlHttp = new XMLHttpRequest();
		}catch(e){
			xmlHttp = false;
		}
	}
	//if we caught an error and the xmlhttp object is false
	if(xmlHttp)
		return xmlHttp;
	else
		alert('xmlHttp object create error.');
	// we can alert or write to the document something that says it didn't work at this point, but that's useless
}

function doAJAXRequest(url,post,type){
	var xmlHTTP = createXmlHttpRequestObject();
	
	/* make sure that we got an xmlHTTP pointer defined somewhere */
	if(!xmlHTTP){
		alert('AJAX not available!');
		return false;
	}
	
	if (post){
		/* we are making an ajax request via post variables */
		if (!type)
			type="application/x-www-form-urlencoded";
		/* assuming an xml response since we are sending xml */
		if ((type=="text/xml") && (xmlHTTP.overrideMimeType))
			xmlHTTP.overrideMimeType("text/xml");
		xmlHTTP.open("POST", url, false);
		xmlHTTP.setRequestHeader("Content-type", ""+type);
		xmlHTTP.setRequestHeader('Content-length', post.length);
		xmlHTTP.setRequestHeader("Connection", "close");
		xmlHTTP.send(post);
	}else{
		xmlHTTP.open('GET', url, false);
		xmlHTTP.send(null);
	}
	/* if we were asking for xml, return xml. otherwise, return text */
	if (type=='text/xml')
		return xmlHTTP.responseXML;
	return xmlHTTP.responseText;
}