// JavaScript Document

//		AJAX
//		É acionado pela função (Executa)
//		Parâmetros:
//		url -> Página que ira chamar, pode ser passado algo por queryString.
//		idj -> id da div cujo resultado do processamento da página irá aparecer.

var Ajax = false;
var id;

function Executa(url,idj) {
		id= idj;
		document.getElementById(id).innerHTML="<br><Br><br><br><center><img src='img/loading.gif'></center>";
		AjaxRequest();
		Ajax.open('GET', url, true);
		Ajax.onreadystatechange = processaResposta;
		Ajax.send(null);
}

function ExecutaMiniLoading(url,idj) {
		id= idj;
		document.getElementById(id).innerHTML="<center><img src='img/loading_p.gif'></center>";
		AjaxRequest();
		Ajax.open('GET', url, true);
		Ajax.onreadystatechange = processaResposta;
		Ajax.send(null);
}


function AjaxRequest() {
	Ajax = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		Ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			Ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				Ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}		
}

function processaResposta() {
	if (Ajax.readyState == 4) {
		if(Ajax.status==200) {
			divConteudo(id,Ajax.responseText);
			trocaTudo();
			return false;					
		} 
	}
}

function divConteudo(idd,cont){
	if(idd!=''){
		document.getElementById(idd).innerHTML= cont;	
		return true;
	} else {
		return false;	
		}
}