// JavaScript Document

// chama a função de AJAX

function changeAjax(url, metodo, modo, tagId, parametros)
{
    goAjax( url+"?"+parametros+"&rnd"+ Math.random() , metodo, modo, tagId);
}

// executa a função de ajax


function goAjax(url, metodo, modo, tagRetorno, parametros) {
          	//document.getElementById(tagRetorno).innerHTML='<div align="center" class="div_carregando">Carregando...</div>'
			//document.getElementById(tagRetorno).innerHTML='<img src="../../themes/loading.gif" width="16" height="16" />'

			function createXMLHTTP(){
			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("Seu browser(navegador) não possui alguns recursos(Ajax) nescessários para a utilização deste sistema.\nFaça a atualização do seubrowser(navegador).");
			ajax = null;
			}
			}
			return ajax;
			}
			var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
			"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
			"Microsoft.XMLHTTP"];
			for (var i=0; i < arrSignatures.length; i++) {
			try { var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
			} catch (oError) {
			}
			}
			
			throw new Error("Seu browser(navegador) não possui alguns recursos(Ajax) nescessários para a utilização deste sistema.\nFaça a atualização do seubrowser(navegador).");
			}
			
			var xmlhttp = createXMLHTTP();

			if(metodo == "GET") {
                xmlhttp.open("GET", url, modo);
            } else {        
                xmlhttp.open("POST", url, modo);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    
            
            xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4) {
                    retorno=xmlhttp.responseText
                    document.getElementById(tagRetorno).innerHTML=retorno
                    findScript(retorno)
                }
            }
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
}

