function CHttpRequest(){
	
	if(typeof(self.__Requests) == "undefined"){
		self.__Requests = new Array();
		self.attachEvent('onunload', __ClearRequestArray);
	}
	
	if(typeof(self.__RequestContexts) == "undefined"){
		self.__RequestContexts = new Array();
		self.attachEvent('onunload', __ClearRequestContextArray);
	}
	
	this.Context = new Object();
	this.AssyncCall = true;
	this.arProperties = new Array();
	this.QueryString = "";
	this.OnResponse = "";
	this.Debug = false;
	this.DebugInNewWindow = false;
	this.GetResponseObject = false;
	this.AutoDisplayErrors = true;
	
	this.AddProperty = function(PropertyName, PropertyValue){
		var arProperty = new Array();
		arProperty["PropertyName"] = PropertyName;
		arProperty["PropertyValue"] = PropertyValue;
		this.arProperties.push(arProperty);
	}

	this.Send = function(){
		var currentRequest = null;
		try {
			currentRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				currentRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return;
			}
		}

		currentRequest.open('POST', "Index.php?hNoMarkup=1&SuppressRedirect=1&XmlHttpRequest=1", this.AssyncCall);
		currentRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

		var savedIndex = null;
		for(var i = 0; i < self.__Requests.length; i++){
			if(self.__Requests[i].readyState == 4){
				self.__Requests[i] = currentRequest;
				self.__RequestContexts[i] = this.Context;
				savedIndex= i;
				break;
			}
		}
		if(savedIndex == null){
			self.__Requests.push(currentRequest);
			self.__RequestContexts.push(this.Context);
			savedIndex = self.__Requests.length - 1;
		}

		if(this.OnResponse != ""){
			// if(self.__RequestContexts["+ savedIndex +"] == undefined){ alert(self.__RequestContexts+' - '+"+ savedIndex +"); }
			// alert(self.__RequestContexts.length+' - '+"+ savedIndex +"); 
			var sErrorCode = "";
			if(this.AutoDisplayErrors){
				sErrorCode = "if(SearchForError(self.__Requests["+ savedIndex +"].responseText)){return false;}";
			}
			currentRequest.onreadystatechange = new Function("if(self.__Requests["+ savedIndex +"].readyState == 4){"+ sErrorCode +""+ this.OnResponse +"(self.__Requests["+ savedIndex +"]"+ ( (this.GetResponseObject) ? "" : ".responseXML.childNodes[0]" ) +", self.__RequestContexts["+ savedIndex +"]);}");
		}
		
		for(var i = 0; i < this.arProperties.length; i++){
			var arProperty = this.arProperties[i];
			this.QueryString += "&"+ arProperty["PropertyName"] +"="+ encodeURIComponent(arProperty["PropertyValue"]);
		}
		
		currentRequest.send(this.QueryString);
		if(this.AutoDisplayErrors && this.AssyncCall == false){
			if(SearchForError(currentRequest.responseText))
				return false;
		}
		if(this.Debug){
			if(this.AssyncCall){
				// TEMP
				if(this.DebugInNewWindow)
					window.open("Index.php?hNoMarkup=1&SuppressRedirect=1&XmlHttpRequest=1&Debug=1"+ this.QueryString, "_blank");
				else
					window.Debug.DumpWindow("Index.php?hNoMarkup=1&SuppressRedirect=1&XmlHttpRequest=1&Debug=1"+ this.QueryString);
			}else{
				var DebugWindow = window.open("about:blank", "_blank");
				DebugWindow.document.write(currentRequest.responseText);
			}
		}
		return currentRequest;
	}
}

function __ClearRequestArray(){
	self.__Requests = null;
}

function __ClearRequestContextArray(){
	self.__RequestContexts = null;
}

function SearchForError(sText){
	if(sText.match("<error>1001</error>")){
		top.CheckGotoLogin();
		return true;
	}
	if(false && (sText.match("Fatal error:") || sText.match("ErrNo") || sText.match("Missing Object") || sText.match("Dump"))){
	
		var bDecode = false;
		if(sText.match("Dump"));
			bDecode = true;
	
		var DebugWindow = window.open("about:blank", "_blank");
		sText = "<b style='font-size: 17px; font-family: Tahoma;'>Auto error:</b><br>"+sText;
		
		if(bDecode){
			try{
				DebugWindow.document.write(decodeURIComponent(sText));
			}catch(e){
				DebugWindow.document.write(sText);
			}
		}else
			DebugWindow.document.write(sText);
		return true;
	}
	return false;
}
