
function retorneResposta2(

    necessitaResposta,
    tipoDadosResposta,
    modoResposta,
    idDestinoResposta,

    exibirCarregando,
    modoRespostaCarregando,
    idDestinoCarregando,
    conteudoCarregando,

    tratarErro,
    modoRespostaErro,
    idDestinoMensagemErro,
    conteudoMensagemErro,

    metodoRequisicao,
    urlRequisicao,
    estadoAssincrono,
    dadosEnviar) {


 
    //alert(modoResposta);
 
 
 
    idDestinoAvisoResposta = modoResposta[4];
    avisoResposta = modoResposta[3];
    focarInput = modoResposta[2];
    limparInput = modoResposta[1];

 
 
    modoResposta = modoResposta[0];



    var xmlHttp;

    xmlHttp = false;



    var tipoErro;

    tipoErro = 0;

    try {
        // Firefox, Opera 8.0+, Safari, Chrome
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            // Versão 6
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                // Versão 5.5
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                tipoErro = 1; // O navegador não suporta AJAX!
            }
        }
    }

    if (!xmlHttp) {
        tipoErro = 1; // O navegador não suporta AJAX!
    }



    if (tratarErro) {

        if (modoRespostaErro == "innerHTML") {

            if (tipoErro != 0) {
                window.document.getElementById(idDestinoMensagemErro).innerHTML = conteudoMensagemErro;
                return false;
            }

        }

        if (modoRespostaErro == "alert") {

            if (tipoErro != 0) {
                window.alert(conteudoMensagemErro);
                return false;
            }

        }

    }



    if (xmlHttp.overrideMimeType) {
        xmlHttp.overrideMimeType('text/xml');
    }



    function receberResposta() {

        if (xmlHttp.readyState < 4) {

            if (exibirCarregando) {

                if (modoRespostaCarregando == "innerHTML") {

                    window.document.getElementById(idDestinoCarregando).innerHTML = conteudoCarregando;

                }

                if (modoResposta == "alert") {

                    window.alert(conteudoCarregando);

                }

            }

        }



        if (xmlHttp.readyState == 4) {

            if (necessitaResposta) {

                var respostaRequisicao = "";

                if (tipoDadosResposta == "texto") {

                    respostaRequisicao = xmlHttp.responseText;

                }

                if (tipoDadosResposta == "xml") {

                    respostaRequisicao = xmlHttp.responseXml;

                }

                //alert("'" + respostaRequisicao + "'");

                if (modoResposta == "innerHTML") {

                    if (respostaRequisicao != "") {

                        window.document.getElementById(idDestinoResposta).innerHTML = "";
                        window.document.getElementById(idDestinoResposta).innerHTML = respostaRequisicao;
                        //alert("'" + window.document.getElementById(idDestinoResposta).innerHTML + "'");

                    } else {

                        return false;

                    }
                }

                if (modoResposta == "alert") {

                    if (respostaRequisicao != "") {
                        window.alert(respostaRequisicao);

                        if (limparInput) {

                            window.document.getElementById(idDestinoResposta).value = "";

                        }

                        if (focarInput) {

                            setTimeout('',250);
                            window.document.getElementById(idDestinoResposta).focus();

                        }

                        //alert(avisoResposta);
                        //alert(idDestinoAvisoResposta);

                        if (avisoResposta) {

                            window.document.getElementById(idDestinoAvisoResposta).value = respostaRequisicao;
                            //alert(window.document.getElementById(idDestinoAvisoResposta).value);

                        }

                    } else {

                        return false;

                    }
                }



            }
        }
    }

    xmlHttp.onreadystatechange = receberResposta;

    xmlHttp.open(metodoRequisicao, urlRequisicao, estadoAssincrono);

    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

    xmlHttp.send(dadosEnviar);

}



/*

// Exemplo de invocação.

necessitaResposta = true; // ou false para receber a resposta.
tipoDadosResposta = "texto"; // ou "xml".

Parâmetros opcionais em caso de modoResposta = "alert".

    limparInput = modoResposta[1];
    focarInput = modoResposta[2];
    avisoResposta = modoResposta[3];
    idDestinoAvisoResposta = modoResposta[4];

modoResposta = ["innerHTML"];   // ou ["alert" [,

     true ou false para limpar o input [,
     true ou false para focar o input [,
     true ou false para dar aviso de resposta, "idDestinoAvisoResposta" id do objeto html ] ] ] ]

idDestinoResposta = "idDestinoResposta"; // id do objeto html.

exibirCarregando = false; // ou true para exibir o carregando.
modoRespostaCarregando = ["innerHTML"]; // ou ["alert"].
idDestinoCarregando = "idDestinoCarregando"; // id do objeto html.
conteudoCarregando = "Conteúdo Carregando..."; // Conteúdo com ou sem HTML.

tratarErro = false; // ou true para tratar erro.
modoRespostaErro = ["innerHTML"]; // ou ["alert"].
idDestinoMensagemErro = "idDestinoMensagemErro"; // id do objeto html.
conteudoMensagemErro = "Conteúdo da Mensagem de Erro."; // Conteúdo com ou sem HTML.

metodoRequisicao = "GET"; // ou "POST". Utilizar apenas GET.
urlRequisicao = "pagina.php?parametros"; // Para GET.
estadoAssincrono = true; // Utilizar apenas true.
dadosEnviar = null; // Utilizar apenas null.

retorneResposta(
    
    necessitaResposta,
    tipoDadosResposta,
    modoResposta,
    idDestinoResposta,

    exibirCarregando,
    modoRespostaCarregando,
    idDestinoCarregando,
    conteudoCarregando,

    tratarErro,
    modoRespostaErro,
    idDestinoMensagemErro,
    conteudoMensagemErro,

    metodoRequisicao,
    urlRequisicao,
    estadoAssincrono,
    dadosEnviar);

*/


