function extraiScript(texto){
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            eval(codigo);
        }
    }
}


function openAjax() {
	var Ajax;
	try {Ajax = new XMLHttpRequest(); // XMLHttpRequest para browsers mais populares, como: Firefox, Safari, dentre outros.
	}
		catch(ee) {
	try {Ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
	}
		catch(e) {
	try {Ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
	}
		catch(e) {Ajax = false;
}
}
}
return Ajax;
}


function carregaAjax(pag,id, div) {
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.

    //** esconde id de resultado **//
	
	document.getElementById(div).innerHTML = '<center><img src="../imagens/carregando.gif" /></center>';
/*	document.getElementById("m").style.display = ''; */




	var randone = "&zz=" + Math.ceil(Math.random() * 100000);
/*	alert(randone);*/
	var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
	var Ajax = openAjax(); // Inicia o Ajax.
/*		Ajax.open("GET", pag+"?id="+id, true); // fazendo a requisição */

        
		Ajax.open("GET", pag+randone, true); // fazendo a requisição
		Ajax.onreadystatechange = function()
			{
				if(Ajax.readyState == 1 && document.getElementById("m") != null) { // Quando estiver carregando, exibe: carregando...
					document.getElementById("m").style.display = '';
			}

/*
			if (xmlhttp.readyState==4){
	            // coloca o valor no objeto requisitado
	            texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
	            document.getElementById(destino).innerHTML=texto;
	            // executa scripts
	            extraiScript(texto);
			}*/


			if(Ajax.readyState == 4) { // Quando estiver tudo pronto.
				if(Ajax.status == 200) {
					var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
					resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
					resultado = unescape(resultado); // Resolve o problema dos acentos
					resultado = resultado.replace('', "");
					exibeResultado.innerHTML = resultado;
					exibeResultado.style.display = '';
					extraiScript(resultado);
//					document.getElementById("m").style.display = 'none';
				} else {
					exibeResultado.innerHTML = "Pagina não encontrada";
				}
			}


}
Ajax.send(null); // submete
}
}

///////////////////////////////////////////////////////////////////////////////////////////////

function LoadAjax(pag,id, div, div2) {
	if(document.getElementById) { // Para os browsers complacentes com o DOM W3C.

    //** esconde id de resultado **//
	
	if (div == div)
	{
		document.getElementById(div).innerHTML = '<div style="margin-left: 30px; margin-top: 30px;"><img src="../imagens/carregando.gif" alt="" /></div>';
		document.getElementById(div2).style.display = '';
	}


	var randone = "&yw=" + Math.ceil(Math.random() * 100000);
/*	alert(randone);*/
	var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
	var Ajax = openAjax(); // Inicia o Ajax.
/*		Ajax.open("GET", pag+"?id="+id, true); // fazendo a requisição */

        
		Ajax.open("GET", pag+randone, true); // fazendo a requisição
		Ajax.onreadystatechange = function()
			{
				if(Ajax.readyState == 1 && document.getElementById(div2) != null) { // Quando estiver carregando, exibe: carregando...
					document.getElementById(div2).style.display = '';
			}


			if (xmlhttp.readyState==4){
            // coloca o valor no objeto requisitado
            texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
            document.getElementById(destino).innerHTML=texto;
            // executa scripts
            extraiScript(texto);
			}

/*
			if(Ajax.readyState == 4) { // Quando estiver tudo pronto.

				if(Ajax.status == 200) {
					var resultado = Ajax.responseText; // Coloca o retornado pelo Ajax nessa variável
					resultado = resultado.replace(/\+/g," "); // Resolve o problema dos acentos (saiba mais aqui: http://www.plugsites.net/leandro/?p=4)
					resultado = unescape(resultado); // Resolve o problema dos acentos
					resultado = resultado.replace('', "");
					exibeResultado.innerHTML = resultado;
					exibeResultado.style.display = '';
					document.getElementById(div2).style.display = 'none';
				} else {
					exibeResultado.innerHTML = "oops";
				}

			} */
	}
	Ajax.send(null); // submete
	}
	}


function replaceAll(str, de, para){
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}


	function WriteLayer(ID,parentID,URL) {
		if (document.layers) {
			var oLayer;
			if(parentID){
			oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
		}else{
			oLayer = document.layers[ID].document;
		}
		oLayer.open();
		oLayer.write(URL);
		oLayer.close();
	}
	else if (parseInt(navigator.appVersion)>=5&&navigator.
		appName=="Netscape") {
		document.getElementById(ID).innerHTML = URL;
	}
		else if (document.all) document.all[ID].innerHTML = URL
	}