// AJAX PARA OS METODOS GET E POST
//SINTAXE: ajaxHTML('Id do Objeto','Arquivo com o script','Nome do método em maiúsculas','Variáveis para o método post'),

//Tenta criar o objeto xmlHTTP
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

//Fila de conexões
fila=[]
ifila=0

//Carrega via XMLHTTP a url recebida e coloca seu valor
//no objeto com o id recebido
function ajaxHTML(id, url, method, vars){
	//Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
	if(method == "GET"){
    	if((ifila+1)==fila.length)ajaxRunGET();
	}
	if(method == "POST"){
	   	if((ifila+1)==fila.length)ajaxRunPOST(vars);
	}
}

//Executa a próxima conexão da fila
function ajaxRunGET(){
    //Abre a conexão
    xmlhttp.open("GET",fila[ifila][1],true);

	//Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(fila[ifila][0]).innerHTML=retorno
            //Roda o próximo
            ifila++
            if(ifila<fila.length)setTimeout("ajaxRunGET()",20)
        }
    }
    //Executa
	xmlhttp.send(null)	
}
function ajaxRunPOST(vars){
    //Abre a conexão
    xmlhttp.open("POST",fila[ifila][1],true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	//Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(fila[ifila][0]).innerHTML=retorno
            //Roda o próximo
            ifila++
            if(ifila<fila.length)setTimeout("ajaxRunPOST()",20)
        }
    }
    //Executa
	xmlhttp.send(vars)
}