//objeto XMLHttpRequest ou XMLHTTP, dependendo do navegador.
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

//Obter conteudo
function carrega(n){
    //Exibe o texto carregando no div conteúdo
    var conteudo=document.getElementById("exibe_conteudo")
    conteudo.innerHTML='carregando...'

    //Guarda a página escolhida na variável atual
    atual=n

    //Abre a url
    xmlhttp.open("GET", "/portal/util/asp/function/function.asp?conteudo="+n,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText;

            //Desfaz o urlencode
            texto=texto.replace(/\+/g," ");
            texto=unescape(texto);

            //Exibe o texto no div conteúdo
            var conteudo=document.getElementById("exibe_conteudo");
			conteudo.style.display = "block";

			//document.getElementById("mascara").style.display = "block";

            conteudo.innerHTML=texto;
        }
    }
    xmlhttp.send(null)
}


function createXMLHTTP(){
	var ajax;
	try{
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e){
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(ex){
			try{
				ajax = new XMLHttpRequest();
			}
			catch(exc){
				alert("Esse browser não possui recursos para uso do Ajax");
				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("MSXML não está instalado no seu sistema.");
}

function executarChamadaAjax(url) {
	var ajax = createXMLHTTP();
    
	//Inicia a preparação e executa a chamada AJAX síncrona
	ajax.open("GET", url, false);
    ajax.send(null);
	//lê o conteúdo retornado e faz o tratamento adequado
	var texto = ajax.responseText; 
	texto = texto.replace(/\+/g," ");
	texto = unescape(texto);
	texto = texto.replace(/\\n/g,"\n");
	
	return(texto); //retorna o conteúdo
}

