/*
	2008.11.06	gricke
				<ajaxDataSend=nothing> Pass name value instead of just name
	2008.09.19	gricke
				<loadingMessageAndDiv> 2nd loading image function - pass image and div to right, any stying done via css
				
	2007.10.08	gricke
				<typeof(functionCompleteRun)> Better check if function is not defined in old scripts
				
	2007.10.02	gricke
				<functionCompleteRun>
					If passed, run the function after AJAX instead of just writting the HTTP results out to the screen (additional processing)
	2007.09.12	gricke
				<divToWrite> Pass the div tag ID to write the results so these functions can 
				be used multiple times with different calls
				
	NOTES
		***
		When switching from ajax.js to ajaxMultiple.js, just need to add the divToWrite var - rest can be blank			
*/
function xmlhttpPost(strURL,divToWrite,dataSend,functionCompleteRun) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			if(typeof(functionCompleteRun) == 'undefined'){
            	returnHttpReqResults(self.xmlHttpReq.responseText,divToWrite);
			}else{
				eval(functionCompleteRun + '(\'' + escape(self.xmlHttpReq.responseText) + '\');');
			}
        }
    }
	if(typeof(dataSend) == 'undefined'){
		dataSend = 'ajaxDataSend=nothing';
	}
    self.xmlHttpReq.send(dataSend);	//must send something or get "length required" in FF
}
function returnHttpReqResults(results,divToWrite){
	var HTMLDisp = '';
	if (document.getElementById(divToWrite)){
		var httpReqResultsHtml = document.getElementById(divToWrite);
		HTMLDisp = HTMLDisp + results;
		httpReqResultsHtml.innerHTML = HTMLDisp; 
	}
}
function loadingMessage(loadingImage,padImage){
	document.getElementById('httpReqResults').innerHTML = "<img src=\"" + loadingImage + "\" style=\"padding:" + padImage + "px;\" style=\"\" /> Loading...";
}
function loadingMessageAndDiv(loadingImage,divToWrite){
	document.getElementById(divToWrite).innerHTML = "<img id=\"loadingImage\" src=\"" + loadingImage + "\" />";
}
