// XMLHttpRequest object for browsers that don't have it
// Follows draft http://www.w3.org/TR/XMLHttpRequest/
// JS - 04/18/2006

var ELEMENT_NODE                  = 1;
var ATTRIBUTE_NODE                = 2;
var TEXT_NODE                     = 3;
var CDATA_SECTION_NODE            = 4;
var ENTITY_REFERENCE_NODE         = 5;
var ENTITY_NODE                   = 6;
var PROCESSING_INSTRUCTION_NODE   = 7;
var COMMENT_NODE                  = 8;
var DOCUMENT_NODE                 = 9;
var DOCUMENT_TYPE_NODE            = 10;
var DOCUMENT_FRAGMENT_NODE        = 11;
var NOTATION_NODE                 = 12;

if(typeof XMLHttpRequest == 'undefined')
{
	var XMLHttpRequest=function()
	{
		var globalrequesto=null;
		this.requestobject=null;
		if(typeof ActiveXObject != 'undefined')
		{
			try{
				this.requestobject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				throw e;
			}
		}else{
			throw null;
		}
		this.isasync = false;
		globalrequesto=this;

		this.onreadystatechange = null;
		this.readyState=0;
		this.responseText = "";
		this.responseXML = null;
		this.status=0;
		this.statusText="";
		
		this.open = function(request_type, request_address, async, xusername, xpassword) {
			if(!async){async=false;}
			if(!xusername){xusername=null;}
			if(!xpassword){xpassword=null;}
			
			if(this.readyState==4)
			{
				this.onreadystatechange = null;
				this.readyState=0;
				this.responseText = "";
				this.responseXML = null;
				this.status=0;
				this.statusText="";
				this.requestobject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			this.isasync=async;
			this.requestobject.open(request_type, request_address, async, xusername, xpassword);
			if(this.isasync)
			{
				this.requestobject.onreadystatechange=this.callbackfn;
			}
			this.readyState=1;
		}
		
		this.setRequestHeader = function(headerproperty, propertyvalue) {
			try{
				this.requestobject.setRequestHeader(headerproperty, propertyvalue);
			}catch(e){
				throw(e);
			}
		}
		
		this.send = function(whatdata){
			if(this.readyState!=1)
			{
				//11==INVALID_STATE_ERR
				throw(11);
			}
			var iterations=0;
			this.requestobject.send(whatdata);
			if(!this.isasync)
			{
				this.responseText=this.requestobject.responseText;
				this.responseXML=this.requestobject.responseXML;
				this.readyState=this.requestobject.readyState;
				this.readyState=4;
			}else{
				this.readyState=2;
			}
		}
		
		this.callbackfn = function(){
			globalrequesto.readyState=globalrequesto.requestobject.readyState;
			if(globalrequesto.readyState==3)
			{
				try{
					globalrequesto.responseText=globalrequesto.requestobject.responseText;
				}catch(e){
					globalrequesto.responseText="";
				}
				try{
					globalrequesto.status=globalrequesto.requestobject.status;
				}catch(e){
					globalrequesto.status=0;
				}
				try{
					globalrequesto.statusText=globalrequesto.requestobject.statusText;
				}catch(e){
					globalrequesto.statusText="";
				}
			}
			if(globalrequesto.readyState==4)
			{
				globalrequesto.responseText=globalrequesto.requestobject.responseText;
				globalrequesto.responseXML=globalrequesto.requestobject.responseXML;
				globalrequesto.status=globalrequesto.requestobject.status;
				globalrequesto.statusText=globalrequesto.requestobject.statusText;
			}
			globalrequesto.onreadystatechange();
		}
		
		this.getAllResponseHeaders = function(){
			if(this.readyState==3 || this.readyState==4)
			{
				return this.requestobject.getAllResponseHeaders();
			}else{
				return null;
			}
		}
		
		this.getResponseHeader = function(headerlabel){
			if(this.readyState==3 || this.readyState==4)
			{
				return this.requestobject.getResponseHeader(headerlabel);
			}else{
				return "";
			}
		}
		
		this.abort = function(){
			return this.requestobject.abort();
		}
	}
}
