// JavaScript Document
<!--//<![CDATA[
//metodo 			- POST ou GET
//pagina 			- endereço do Ajax
//dados 			- informações extras necessárias para rodar a página
//divId 			- div que mostrará o resultado do Ajax
//divCarregando 	- div que traz uma imagem carregando
//Invisivel 		- 0 - Não fazer a div ficar invisível / 1 - Div fica invisível, depois visível, quando preenchida pelos dados

function chamarAjax(metodo,pagina,dados,divId,divCarregando,Invisivel) {

	//Declarar ajax como null
	var ajax = null;
	
	//Verifica se o objeto existe de forma nativa
	if (window.XMLHttpRequest){
		//Cria objeto
		ajax = new XMLHttpRequest();
	} 
	else 
	{
		//Se não existir de forma nativa
		//Verifica se existe nativamente, o ActiveXObject
		if (window.ActiveXObject) {
			//Então cria um objeto ActiveXObject; considerando que seja IE 5.5+
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			
			//Se não considera IE 5.5-
			if (!ajax) {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	
	if (ajax) {

		ajax.open(metodo,pagina,true)
		
		ajax.onreadystatechange = function () 
		{
			//carregandoInternas
			if (ajax.readyState == 1) {
				//deixar a div invisível, se o status invisível estiver marcado
				if (Invisivel == 1){
					document.getElementById(divId).className = "naovisivel";
					};
				//Checar se foi enviada div de Carregando
				if (divCarregando != ''){
					document.getElementById(divCarregando).className = "visivel";
					};
			}; //fim readystate 1

			if (ajax.readyState == 4) {
				//Verifica se os dados estão ok
				if (ajax.status == 200) {
					var escreve_html = ajax.responseText;
					if (escreve_html != '') {
						//Checar se foi enviada a div de Carregando
						if (divCarregando != ''){
							document.getElementById(divCarregando).className = "naovisivel";
							};
						//escrever o html e deixar a div visível
						document.getElementById(divId).innerHTML = escreve_html;
						if (Invisivel == 1){
							document.getElementById(divId).className = "visivel";
							};
						};

				};
			}; //fim readystate 4

		}; //fim da função onreadystatechange

		//ajax.send(null);
		ajax.send(dados);
	};
};
//]]>-->

