
function create_XmlHTTPRequest() {
	var xmlHttp;
	try {
		xmlHttp = new ActiveXObject("MSXML2.xmlHTTP")
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.xmlHTTP")
		} catch (ex) {
			xmlHttp = false
		}
	}
	if (!xmlHttp) {
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (ex2) {
			xmlHttp = false;
		}
	}
	return xmlHttp;
}


function xmlHTTPHelper() {

	this.errorMessage = "";
	this.url = "";
	this.postData = "";
	this.requestType = "GET";
	this.contentLength = -1;

	var xmlHttp = create_XmlHTTPRequest();
	
	function test() {
		this.url = this.postData;
	}

	function setProperties(url, postData, requestType) {
		this.url = url;
		this.postData = postData;
		this.requestType = requestType;
	}
	
	function getResponse()
	{
		this.errorMessage = null;

		if (!xmlHttp)
			return null;
		
		xmlHttp.open(this.requestType.toUpperCase(), this.url, false);
		
		if (this.contentLength > -1)
			xmlHttp.setRequestHeader("Content-Length", this.contentLength);

		xmlHttp.setRequestHeader("Pragma", "no-cache");
		xmlHttp.setRequestHeader("Cache-Control", "no-cache");
		xmlHttp.send(this.postData);
		
		this.contentLength = -1;
		
		try {
			var x = xmlHttp.responseText;
			return x;
		} catch (e) {
			this.errorMessage = e;
			return null;
		}
	}
	
	function getResponseXml() {
		this.errorMessage = null;

		if (!xmlHttp)
			return null;
		
		xmlHttp.open(this.requestType.toUpperCase(), this.url, false);
		
		if (this.contentLength > -1)
			xmlHttp.setRequestHeader("Content-Length", this.contentLength);

		xmlHttp.setRequestHeader("Pragma", "no-cache");
		xmlHttp.setRequestHeader("Cache-Control", "no-cache");
		xmlHttp.send(this.postData);
		
		this.contentLength = -1;
		
		try {
			var x = xmlHttp.responseXML;
			return x;
		} catch (e) {
			this.errorMessage = e;
			return null;
		}
	}


	function sendADOStream(filename) {
		var adoStream;
		try {
			adoStream = new ActiveXObject("ADODB.Stream");
		} catch (e) {
			this.errorMessage = e;
			return null;
		}
		
		adoStream.Mode = 3; // read write
		adoStream.Type = 1; // adTypeBinary
		adoStream.Open();
		adoStream.LoadFromFile(filename);

		if (adoStream.Size > 1048576) {
			this.errorMessage = "The file is too large";
			adoStream = null;
			return;
		}

		this.contentLength = adoStream.Size;
		this.postData = adoStream.Read(adoStream.Size);
		var x = this.getResponse();
		adoStream = null;
		this.postData = "";
		return x;

	}


	this.test = test;
	this.getResponse = getResponse;
	this.setProperties = setProperties;
	this.sendADOStream = sendADOStream;
	this.getResponseXml = getResponseXml;

}
