function xmlHttpRequest() {
	var xmlhttp = false;
    if(window.XMLHttpRequest) {
		try {
	        var xmlhttp = new XMLHttpRequest();
		}
		catch(e) {}
    } else if(window.ActiveXObject) {
		var types = [
			"Microsoft.XMLHTTP",
			"MSXML2.XMLHTTP.5.0",
			"MSXML2.XMLHTTP.4.0",
			"MSXML2.XMLHTTP.3.0",
			"MSXML2.XMLHTTP"
		];
		
		for (var i = 0; i < types.length; i++) {
			try {
				xmlhttp = new ActiveXObject(types[i]);
				if(xmlhttp) {
					break;
				}
			}
			catch(e) {}
		}
    }

	this.connect = function(file, vars, method, fnDone) {
		if(!xmlhttp && String(typeof(XMLHttpRequest)) == "undefined") { return false; }
		if(file) {
			var path = window.location.protocol + "//" + window.location.host + "/" + file;
		}
		else {
			alert("file target is not configured");
			return false;
		}
		method = method.toUpperCase();
		
		switch(method) {
			case "POST" :
				xmlhttp.open("post", file, true);
				xmlhttp.setRequestHeader("Content-Type", "text/xml"); 
				xmlhttp.setRequestHeader("encoding", "UTF-8");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
				xmlhttp.setRequestHeader("Content-length", vars.length); 
				xmlhttp.setRequestHeader("Connection", "close");
			case "GET" :
				if(vars) { path += "?" + vars; }
				xmlhttp.open("get", path, true);
				xmlhttp.setRequestHeader("encoding", "UTF-8");
			break;
		}

		xmlhttp.onreadystatechange = function() {
			try {
				switch(xmlhttp.readyState) {
					case 0: // nothing to do
					case 1: // no request made yet
					case 2: // server talk established
					case 3: // downloading
						showLoading();
					break;
					case 4:
						// success
						switch (xmlhttp.status) {
							case 200:
								fnDone(xmlhttp);
							break;
							default:
							alert("Status: " + xmlhttp.status + " - " + xmlhttp.statusText.replace(/\+/g," "));
						}
						hideLoading();
					break;
				}
			}
			catch(e) {}
		};
		xmlhttp.send(vars);
	};

	this.px2int = function(pValue) {
		try {
			if(String(pValue).indexOf("px") != -1) {
				var intReturn = pValue.substring(0, (pValue.length - 2));
				intReturn = parseInt(intReturn);
				return intReturn;
			}
			else {
				return 0;
			}
		}
		catch(e) {
			var dsMessage = document.getElementById("dsMessage");
			var msg = "";
			for(var it in e) {
				msg += it + ": " + e[it] + "\n";
			}
			dsMessage.innerHTML = msg;
		}
	};

	this.getStyle = function(el,styleProp) {
		try {
			if(String(typeof(el)) != "object") {
				var x = document.getElementById(el);
			}
			else {
				var x = el;	
			}
			if (x.currentStyle) {
				var y = x.currentStyle[styleProp];
				if(styleProp == "height") {
					y = x.scrollHeight + "px";
				}
			}
			else if (window.getComputedStyle) {
				var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
			}
			return y;
		}
		catch(e) {}
	};

	this.getSize = function() {
		try {
			var myWidth = 0, myHeight = 0;
			if(typeof(window.innerWidth) == "number") {
				//Non-IE
				myWidth = window.innerWidth;
				myHeight = window.innerHeight;
			}
			else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				myWidth = document.documentElement.clientWidth;
				myHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
			return {"width": myWidth, "height": myHeight};
		}
		catch(e) {}
	};

	this.showLoading = function() {
		try {
			var bodyElement = document.getElementsByTagName("body")[0];
			var xmlHttpRequestLoaderBar = document.getElementById("xmlHttpRequestLoaderBar");

			if(!xmlHttpRequestLoaderBar) {
				var loader = document.createElement("div");
				loader.setAttribute("id", "xmlHttpRequestLoaderBar");
				var text = document.createTextNode("Carregando...");
				loader.appendChild(text);
				bodyElement.appendChild(loader);
				xmlHttpRequestLoaderBar = document.getElementById("xmlHttpRequestLoaderBar");
			}

			var Width = px2int(getStyle(xmlHttpRequestLoaderBar, "width"));
			var Height = px2int(getStyle(xmlHttpRequestLoaderBar, "height"));

			var windowSize = getSize();
			var xMidle = (windowSize.width / 2) - (Width / 2);
			var yMidle = (windowSize.height / 2) - (Height / 2);
			xmlHttpRequestLoaderBar.style.left = xMidle + "px";
			xmlHttpRequestLoaderBar.style.top = yMidle + "px";
			xmlHttpRequestLoaderBar.style.display = "block";

			xmlHttpRequestLoaderBar.innerHTML = "Conectando...";
			window.setTimeout(
				function() {
					xmlHttpRequestLoaderBar.innerHTML = "Aguarde, verificando...";
				}, 3000
			);
			window.setTimeout(
				function() {
					xmlHttpRequestLoaderBar.innerHTML = "Sua conexÃ£o esta lenta...";
				}, 6000
			);
		}
		catch(e) {}
	};
		
	this.hideLoading = function() {
		try {
			var xmlHttpRequestLoaderBar = document.getElementById("xmlHttpRequestLoaderBar");
			xmlHttpRequestLoaderBar.style.display = "none";
		}
		catch(e) {}
	};

	return this;
}
