
function retorneResposta(necessitaResposta, tipoDadosResposta, modoResposta, idDestinoResposta, exibirCarregando, idDestinoCarregando, conteudoCarregando, tratarErro, idDestinoMensagemErro, metodoRequisicao, urlRequisicao, estadoAssincrono, dadosEnviar) {

	//alert(modoResposta);
	idDestinoAvisoResposta = modoResposta[4];
	avisoResposta = modoResposta[3];
	focarInput = modoResposta[2];
	limparInput = modoResposta[1];
	modoResposta = modoResposta[0];
	//alert(avisoResposta);
	//alert(idDestinoAvisoResposta);

	var xmlHttp;

	var tipoErro;

	tipoErro = 0;
	xmlHttp = false;

	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.overrideMimeType) {
		xmlHttp.overrideMimeType('text/xml');
	}

	if (!xmlHttp) {
		tipoErro = 1; // O navegador não suporta AJAX!
	}

	if (tratarErro) {
		if (modoResposta == "innerHTML") {
			window.document.getElementById(idDestinoMensagemErro).innerHTML = tipoErro;
			return false;
		}
		if (modoResposta == "alert") {
			if (tipoErro != 0) {
				window.alert(tipoErro);
				if (limparInput) {
					window.document.getElementById(idDestinoMensagemErro).value = "";
				}
				if (focarInput) {
					setTimeout('',250);
					window.document.getElementById(idDestinoMensagemErro).focus();
				}
				return false;
			}
		}
	}

	function receberResposta() {
		if (xmlHttp.readyState < 4) {
			if (exibirCarregando) {
				var respostaRequisicao = conteudoCarregando;
				if (modoResposta == "innerHTML") {
					if (respostaRequisicao != "") {
						window.document.getElementById(idDestinoCarregando).innerHTML = respostaRequisicao;
					} else {
						return false;
					}
				}
				if (modoResposta == "alert") {
					if (respostaRequisicao != "") {
						window.alert(respostaRequisicao);
						if (limparInput) {
							window.document.getElementById(idDestinoCarregando).value = "";
						}
						if (focarInput) {
							setTimeout('',250);
							window.document.getElementById(idDestinoCarregando).focus();
						}
					} else {
						return false;
					}
				}
			}
		}
		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"
modoResposta = ["innerHTML"]; // ou "alert".
idDestinoResposta = "idDestinoResposta";
exibirCarregando = false; // ou true para exibir o carregando.
idDestinoCarregando = "idDestinoCarregando";
conteudoCarregando = "Conteúdo Carregando..."; // Conteúdo com ou sem HTML.
tratarErro = false; // ou true para tratar erro.
idDestinoMensagemErro = "idDestinoMensagemErro";
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, idDestinoCarregando, conteudoCarregando, tratarErro, idDestinoMensagemErro, metodoRequisicao, urlRequisicao, estadoAssincrono, dadosEnviar);
*/

