// JavaScript Document
function ajaxHelper (onLoadHandler) {
	this.xmlhttp = null;
	this.get = loadXMLDoc; // Faz a chamada a URL fornecida e coloca o resultado em "result"
	this.result = ""; 
	this.isResultOk = false; // Atributo que diz se o resultado foi Ok ou não
	this.onLoad = onLoadHandler; // Obrigatório ser fornecido. Trata o resultado a cada mudança de estado até o final.
	this.isLoaded = doOnStateChanges; //Trata internamente as mudanças de estado e diz quando o resultado está pronto
}

function loadXMLDoc(url) {
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else 
		if (window.ActiveXObject) {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=this.onLoad;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Seu navegador não suporta XMLHTTP, tente atualizá-lo.")
	}
	
//	return xmlhttp;
}


function doOnStateChanges()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
		// if "OK" 
  	//  alert("Status: "+xmlhttp.status + " Mensagem: "+xmlhttp.statusText);
		if (xmlhttp.status==200){
			this.result = xmlhttp.responseText;
			this.isResultOk = true;
		} 
		else {
			this.result = xmlhttp.statusText;
			this.isResultOk = false;
		}
		return true;
	}
	return false;
}


