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.
	document.getElementById(div).innerHTML = '...';
	var randone = "&zz=" + Math.ceil(Math.random() * 100000);
	var exibeResultado = document.getElementById(div); // div que exibirá o resultado.
	var Ajax = openAjax(); // Inicia o Ajax.
		Ajax.open("GET", pag+randone, true); // fazendo a requisição
		Ajax.onreadystatechange = function()
			{
				if(Ajax.readyState == 1 && document.getElementById(div) != null) { // Quando estiver carregando, exibe: carregando...
					document.getElementById(div).style.display = '';
			}
			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);
				} else {
					exibeResultado.innerHTML = "oops";
				}
			}
	};
	Ajax.send(null); // submete
	}
}



function chamabox(dt) {
	carregaAjax('gboxintra.php?idata='+dt, 0, 'gbox');
}

function chamabox2(dt) {
	carregaAjax('gboxintra2.php?idata='+dt, 0, 'gbox');
}

function picta(id) {
	document.getElementById('vfull').innerHTML='<img src="gimage.php?IDI='+id+'&TD=F" />';
}
