// Variaveis globais
var obj;
var id;
var funcao;
var dados;
fila  = [];
ifila = 0;

<!--------------------------------------------------------------------------------------->
// Funcoes do xmlhttprequest
<!--------------------------------------------------------------------------------------->

function CreateObjXMLHttpRequest() { // Cria o objeto

    obj = null;

    // Procura por um objeto nativo W3C (Mozilla/Safari/Konqueror/Opera)
    if (window.XMLHttpRequest){

        obj = new XMLHttpRequest(); // Cria o objeto nativo
        obj_type = "XMLHttpRequest";

    } else if (window.ActiveXObject) { // Senao procura por uma versao ActiveX (IE)

        // Array com tipos de objeto ActiveX
        var msxmls = new Array('Msxml2.XMLHTTP.5.0',
                               'Msxml2.XMLHTTP.4.0',
                               'Msxml2.XMLHTTP.3.0',
                               'Msxml2.XMLHTTP',
                               'Microsoft.XMLHTTP');

        // Percorre array com versoes do ActiveX e tenta criar o objeto
        for (var i = 0; i < msxmls.length; i++) {
            try {
                obj = new ActiveXObject(msxmls[i]); // Tenta criar o objeto nativo
                obj_type = msxmls[i];
                break;
            } catch(e) {
                obj = false;
            }
        }
    } else { // Nenhum objeto suportado pelo browser
        obj = false;
    }
    return obj;
}

function GetContent() {

    if(obj) { // Verifica se objeto ainda existe
        if(obj.readyState == 4) { // Se requisicao terminada (readyState = 4)
            if(obj.status == 200) { // Se status retornado "ok" (status = 200)
                eval(funcao+'();'); // Chama funcao respectiva
            } else {  // Se status diferente de "ok"
                alert('Erro! "'+ obj.statusText +'" (erro '+ obj.status +')'); //Exibe mensagem com o erro
            }

            // Proxima requisicao da fila
            ifila++;
            if (ifila < fila.length) {
                setTimeout("SendRequest()",20);
            }
        }
    } else {
        return false;
    }
}

function Requisition(var_id,arquivo,var_funcao,dados) {
    obj = CreateObjXMLHttpRequest(); // Cria uma instancia do objeto

    id = var_id;
    funcao = var_funcao;

    // Encadeia variaveis enviadas pela requisicao
    if (dados) {
        var mensagem = '';
        for (var i = 0; i < dados.length; i++) {
            if(i > 0) {
                mensagem += '&';
            }
            mensagem += 'dado'+i+'='+dados[i];
        }
    } else {
        mensagem = null;
    }

    // Adiciona a fila
    fila[fila.length] = [id, arquivo, funcao, mensagem];

    // Se fila sem conexoes pendentes, executa
    if ((ifila + 1) == fila.length) {
        SendRequest();
    }

}

function SendRequest()
{
    id       = fila[ifila][0];
    arquivo  = fila[ifila][1];
    funcao   = fila[ifila][2];
    mensagem = fila[ifila][3];

    obj = CreateObjXMLHttpRequest(); // Cria uma instancia do objeto
    obj.onreadystatechange = GetContent; // Define a funcao chamada na mudanca de status do objeto
    obj.open('POST',arquivo, true) // Metodo prepara objeto pra requisicao
    obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
    obj.send(mensagem); // Envia requisicao
}

// url_encode version 1.0
function url_encode(str) {
    var hex_chars = "0123456789ABCDEF";
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
    var n, strCode, hex1, hex2, strEncode = "";

    for(n = 0; n < str.length; n++) {
        if (noEncode.test(str.charAt(n))) {
            strEncode += str.charAt(n);
        } else {
            strCode = str.charCodeAt(n);
            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
            hex2 = hex_chars.charAt(strCode % 16);
            strEncode += "%" + (hex1 + hex2);
        }
    }
    return strEncode;
}

// url_decode version 1.0
function url_decode(str) {
    var n, strCode, strDecode = "";

    for (n = 0; n < str.length; n++) {
        if (str.charAt(n) == "%") {
            strCode = str.charAt(n + 1) + str.charAt(n + 2);
            strDecode += String.fromCharCode(parseInt(strCode, 16));
            n += 2;
        } else {
            strDecode += str.charAt(n);
        }
    }
    return strDecode;
}

<!--------------------------------------------------------------------------------------->
// Funcoes do sistema
<!--------------------------------------------------------------------------------------->

function InserirPagina_envia() {
    document.getElementById(id).innerHTML = obj.responseText;
}

function InserirPagina_recebe() {
    document.getElementById(id).innerHTML = url_decode(obj.responseText);
}

<!--------------------------------------------------------------------------------------->
// Chamadas as funcoes
<!--------------------------------------------------------------------------------------->

function denuncia_passo_4(){
document.getElementById('denuncia_4').style.display='';
document.getElementById('denuncia_3').style.display='none';
}




function InserirDenuncia(id,tipo,texto) { 
    // Monta array dos dados enviados pela requisicao
    var dados = new Array(id, tipo,texto);

	// Chama requisicao	
    Requisition(id='',url='inserir_denuncia.php',funcao='',dados);
    // Atualiza avaliacao
	 cont = setTimeout("denuncia_passo_4()", 1000);


}

function AbrirAjax() {
var Ajax;
try {Ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers mais populares, como: Firefox, Safari, dentre outros.
}catch(ee) {
try {Ajax = new ActiveXObject(" Msxml2.XMLHTTP"); // Para o IE da MS
}catch(e) {
try {Ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
}catch(e) {Ajax = false;
}
}
}
return Ajax;
}




function ajaxFiltro(id,texto,retorna) { 

div=parent.document.getElementById("div_msg_filtro");
anuncio=document.getElementById(id);

var ajax = AbrirAjax();
    ajax.open("GET","filtro.php?texto="+texto,true); // Aqui você optita entre ASP ou PHP
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            if(ajax.status == 200) {
                var imprimir = ajax.responseText;
				if (imprimir!=''){
					div.style.display='';
					anuncio.style.backgroundColor='#F8E5E5';
					div.innerHTML=imprimir;
				}else{
					anuncio.style.backgroundColor='';
					div.style.display='none';
					}
            } else {
				anuncio.style.backgroundColor='';
               div.style.display='none';
            }
        }
    }
    ajax.send(null);
    setTimeout("LerArquivo();",1000);
}



function abreCatXml(id,filtro) { 

div=document.getElementById("div_cat");
div.innerHTML="<br><br><center><img src='images/load_cat.gif' align='absmiddle'> Carregando...</center><br><br><br><br><br><br><br><br>";

var ajax = AbrirAjax();
    ajax.open("GET","ajax/abre_cat_xml.php?id="+id+"&filtro="+filtro,true); // Aqui você optita entre ASP ou PHP
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            if(ajax.status == 200) {
                var imprimir = ajax.responseText;
				if (imprimir!=''){
					div.style.display='';
					div.innerHTML=imprimir;
				}else{
					div.style.display='none';
					}
            } else {
               div.style.display='none';
            }
        }
    }
    ajax.send(null);
    setTimeout("LerArquivo();",1000);
}


function ajaxPergunta(texto,id,nome,email){


div=document.getElementById("div_pergunta");


div.innerHTML="Enviando...";

var ajax = AbrirAjax();
    ajax.open("GET","envia_pergunta.php?texto="+texto+"&id="+id+"&nome="+nome+"&email="+email,true); // Aqui você optita entre ASP ou PHP
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            if(ajax.status == 200) {
                var imprimir = ajax.responseText;
					div.innerHTML=imprimir+"<br><br>";
            } else {
				div.innerHTML="erro";
            }
        }
    }
    ajax.send(null);
    setTimeout("LerArquivo();",1000);
}



function ajaxLocalidade(valor,tipo,selected,autoabrir){

if (tipo==1){
	div=document.getElementById("estados");
	if (autoabrir){
		document.getElementById("cidades").innerHTML="";
		document.getElementById("bairros").innerHTML="";
	}
	nome="Estado";
	path="estado";
}
else if (tipo==2){
	div=document.getElementById("cidades");
	if (autoabrir)
		document.getElementById("bairros").innerHTML="";
	nome="Cidade";
	path="cidade";
}
else if (tipo==3){
	div=document.getElementById("bairros");
	nome="Bairro";
	path="bairro";
}

div.innerHTML="<img src='images/load_cat.gif' height=15> Aguarde...";

var ajax = AbrirAjax();
    ajax.open("GET","ajax/localidade.php?valor="+valor+"&tipo="+tipo+"&selected="+selected,true); // Aqui você optita entre ASP ou PHP
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            if(ajax.status == 200) {
                var imprimir = ajax.responseText;
				if (imprimir!='')
					div.innerHTML="&nbsp; "+nome+": "+imprimir;
				else{
					div.innerHTML="&nbsp; "+nome+": <input name='"+path+"' type=text value='"+selected+"'>";
					
					if (autoabrir==1){
						if (tipo==1){
							document.getElementById("cidades").innerHTML="&nbsp; Cidade: <input name='cidade' type=text value=''>";
							document.getElementById("bairros").innerHTML="&nbsp; Bairro: <input name='bairro' type=text value=''>";
						}
						if (tipo==2)
							document.getElementById("bairros").innerHTML="&nbsp; Bairro: <input name='bairro' type=text value=''>";
					}
				}
            } else {
				div.innerHTML="erro";
            }
        }
    }
    ajax.send(null);
    setTimeout("LerArquivo();",1000);
}