/*extern AjaxUpdater, ActiveXObject */
if (typeof Ajax === "undefined") { var Ajax = {}; }
Ajax.READY_STATE_UNINITIALIZED = 0;      // created, but not initialized
Ajax.READY_STATE_LOADING       = 1;      // object created, but send method has not been called.
Ajax.READY_STATE_LOADED        = 2;      // send method has been called, but the status and headers are not yet available.
Ajax.READY_STATE_INTERACTIVE   = 3;      // Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
Ajax.READY_STATE_COMPLETED     = 4;      // All the data has been received, and the complete data is available in the responseBody and responseText properties.

//
// See: http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest
//

Ajax.makeRequest = function( method, url, callback ) {
	this.request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
	this.request.onreadystatechange = callback;
	this.request.open( method, url, true );
	this.request.send( null );
};

Ajax.makePostRequest = function( url, param, callback ) {
	this.request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
	this.request.onreadystatechange = callback;
	this.request.open( 'POST', url, true );
	this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.request.setRequestHeader("Content-length", param.length);
	/*
	On 8/22/07, IE6 on Win2k started hanging on readystate 3
	We found the following thead, post #3 being of interest:
	http://www.nabble.com/XMLHttpRequest-hangs-on-readyState-3-t2093177.html

	Everything seems to be fine removing the following line but perhaps we need
	to be checking which browser and version before doing so.
	*/
	//this.request.setRequestHeader("Connection", "close");
	this.request.send( param );
};

Ajax.checkReadyState = function() {
	if ( this.isReady() ) {
		return this.request.status;
	}
};

Ajax.isReady = function() {
	if ( this.request.readyState === this.READY_STATE_COMPLETED ) {
		AjaxUpdater.isUpdating = false;
		return true;
	}
	return false;
};

Ajax.getRequestStatus = function() {
	// this should only be called when checkReadyState returns true
	if (this.request)
	{
		return this.request.status;
	}
	return -1;
};

Ajax.getRequestStatusText = function() {
	// this should only be called when checkReadyState returns true
	if (this.request)
	{
		return this.request.statusText;
	}
	return null;
};

Ajax.getResponse = function() {
	/*
	started crapping out 8/20/2007, why?
	if ( this.request.getResponseHeader('Content-Type').indexOf('xml') != -1 ) {
		return this.request.responseXML.documentElement;
	}
	*/
	return this.request.responseText;
};

Ajax.getResponseHeaders = function() {
	if (this.request && this.request.getAllResponseHeaders) {
		return this.request.getAllResponseHeaders();
	}
	return null;
};


