//####################################################################################
//Funçoes de AJAX
var oHTTPRequest;
var ajaxRetorno;

function createXMLHTTP()
{
	var ajax;
	try
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
		catch(ex)
		{
			try
			{
				ajax = new XMLHttpRequest();
			}
			catch(exc)
			{
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
	}
	return ajax;
}
  
 function Ajax(paginaDestino, parametros, funcao)
 {
	if(funcao == undefined) funcao = "retornoAjax()";
 	oHTTPRequest = createXMLHTTP();
	ajaxRetorno = "";

	if(oHTTPRequest!=null)
	{
		oHTTPRequest.open("POST", paginaDestino, true);
		// para solicitacoes utilizando o metodo post deve ser acrescentado este cabecalho HTTP
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.send(parametros);
		// a funcao abaixo e executada sempre que o estado do objeto muda (onreadystatechange)
		try{
			oHTTPRequest.onreadystatechange=eval(funcao);
		}
		catch(err){
			
		}
	}
	else
		alert("O Ajax não pode ser acionado e a sua operação não foi executada. Procure usar outro navegador de internet.");

	return ajaxRetorno;
}

function retornoAjax()
{
	if(oHTTPRequest.readyState==4)
		ajaxRetorno = oHTTPRequest.responseText;
}

//FIM FUNções de AJAX
//####################################################################################
