// AJAX XMLHTTP METHOD
// ---------------------------------------------------------------------------------------------------------------------------------------
function ajaxObject(URL,StatusDiv){

	var that = this;
	this.updating = false;
	this.abort = function(){
		if (that.updating) {
			that.updating = false;
			that.AJAX.abort();
			that.AJAX = null;
		}
	}
	this.update = function(Method,Mode,Vars,Div){
		// METHOD - GET OR POST
		// VARS - QUERYSTRING OR POST VARS
		// MODE - Return mode TXT or XML
		// DIV - DIV object by ID for tracking output
		if (that.updating){
			return false;
		}
		that.AJAX = null;
		// IE7, Mozilla, Safari, etc: Use native object
		if (window.XMLHttpRequest){
			that.AJAX = new XMLHttpRequest();
		 // IE5.X and IE6.X
		}else if (window.ActiveXObject){
			try{
				that.AJAX = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
					that.AJAX = new ActiveXObject("Microsoft.XMLHTTP");
				}catch (e){}
			}
		}
		if (that.AJAX == null) {		 		 		 			
			return false;		 		 		 			  
		}else{
			that.AJAX.onreadystatechange = function(){
				if (that.AJAX.readyState == 0) {
					that.procMsg("Initalizing");
				}
				if (that.AJAX.readyState == 1) {
					that.procMsg("Loading");
				}
				if (that.AJAX.readyState == 2) {
					that.procMsg("Loaded");
				}
				if (that.AJAX.readyState == 3) {
					that.procMsg("Interactive");
				}
				if (that.AJAX.readyState == 4) {
					that.procMsg("");
					that.procData(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
					that.updating = false;
					that.AJAX = null;
				}
			}
		}		 		 		 		 		 		 		 		 
		that.updating = new Date();
		if (Method == "POST"){
			var uri = URL + '?' + that.updating.getTime();
			that.AJAX.open("POST", uri, true);
			if (Mode == "XML"){
				that.AJAX.setRequestHeader("Content-Type", "text/xml");
			}else{
				that.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			// SET CONTENT LENGTH FOR IE AND FIREFOX
			// DO NOT SET FOR - GOOGLE CHROME - SAFARI
			//that.AJAX.setRequestHeader("Content-Length", Vars.length);
			that.AJAX.send(Vars);
			this.setTimer();
		}else{
			var uri = URL + '?' + Vars + '&timestamp=' + (that.updating.getTime()); 
			that.AJAX.open("GET", uri, true);
			that.AJAX.send(null);
			this.setTimer();
		}
	}
	this.setTimer = function(){
		this.timeoutAJAX = setTimeout("this.AJAXStatus",3000);
	}
	this.AJAXStatus = function(){
		if (that.AJAX.readyState != 4){
			that.procMsg("Connection Aborted");
			this.abort();
		}
		clearTimeout(this.timeoutAJAX);
	}
	this.procData = function(responseText,responseStatus,responseXML){
		if (responseStatus == 200){
			eval(responseText);
		}else{
			if (responseStatus == "404"){
				this.procMsg("Page not found: " + responseStatus);
			}else if (responseStatus == "500"){
				this.procMsg("Internal Server Error: " + responseStatus);
			}else{
				this.procMsg("Undefined Error: " + responseStatus);
			}
		}
	}
	this.procMsg = function(strMsg){
		if (StatusDiv){
			divStatus = findObj(StatusDiv);
			if (divStatus){
				if (strMsg){
					if (divStatus.style.display = "none"){
						divStatus.style.display = "";
					}
					divStatus.innerHTML = strMsg;
				}else{
					divStatus.style.display = "none";
				}
			}
		}
	}
}
