function AjaxRequest(parent) {
	this.httpRequest = this.createHttpRequest();
	this.parent = parent;
}

AjaxRequest.prototype.parent = null;


AjaxRequest.prototype.createHttpRequest = function () {
	if (typeof XMLHttpRequest != "undefined")
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
	{
		var versoes = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
	}
	
	for (var i = 0; i < versoes.length; i++) {
		try {
			return new ActiveXObject(versoes[i]);
		}catch (e) {}
	}
	
	throw new Error("Seu browser nao suporta AJAX");
}

AjaxRequest.prototype.getLoader = function () {
	var html;

	html = "<div style='margin: 0px; width: 90%; position: absolute' align='center'>";
	html = html + "<div style='width: 150px; height: 40px;'>";
	html = html + "<div style='font-weight: bold;' align='center'>Aguarde carregando ...</div>";
	html = html + "<div style='margin-top: 10px; width: 130px;'><img src='http://intra.ast.br/geapoio/includes/ajax/barra_load.gif'></div>";
	html = html + "</div>";
	html = html + "</div>";

	return html;
}
AjaxRequest.prototype.doGet = function (url, completeFunction, showLoading) {
	this.doRequest(url, completeFunction, showLoading, "GET");
}

AjaxRequest.prototype.doPost = function (url, completeFunction, showLoading) {
	this.doRequest(url, completeFunction, showLoading, "POST");
}

AjaxRequest.prototype.doRequest = function (url, completeFunction, showLoading, method) {

	if (completeFunction == null && this.parent != null)
		completeFunction = function (p, t) {
			p.innerHTML = t;
		}

	if (this.parent != null)
		this.parent.innerHTML = "carregando ...";	

	
	this.httpRequest.open(method, url, true);
	
	var p = this.parent;
	var httpRequest = this.httpRequest;
	
	//Recupera as informações
	this.httpRequest.onreadystatechange = function () {
	//alert('onreadystatechange: ' + httpRequest.readyState +  " - " + httpRequest.status);
		//Veridica o status da requisição
		if (httpRequest.readyState == 4) {
			//Verifica se houve erro
			if (httpRequest.status == 200) {
				//Jogando resultado no destino
				completeFunction(p, unescape(httpRequest.responseText));
			}
			else {	//Jogando os erros na div
				alert("<b>Error:</b> " + xml.statusText);
			}
			
		} else if (showLoading) {	
			//loc_dest.innerHTML = this.getLoader();
		}
	 };
	 
	 this.httpRequest.send(null);
}
