var req;
var elemento;
var index=0;
function loadNoticia(valor)
{
    req = null;
    elemento="corpo"+valor;
        // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", 'Noticias/busca.php?id='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", 'Noticias/busca.php?id='+valor, true);
            req.send();
        }
    }

}
function processReqChange()
{
	
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
            // procura pela div id="atualiza" e insere o conteudo
            // retornado nela, como texto HTML
           	document.getElementById(elemento).innerHTML = req.responseText;  
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}
/**
fun?ao para abrir a noticia
acessa o busca.php
*/
function abreNoticia(numero)
{
	if (document.getElementById("corpo"+numero).innerHTML=="")
	{
		loadNoticia(numero);
	}
	else
		document.getElementById("corpo"+numero).innerHTML="";	
	
}
/**
fun?ao para imprimir a not?cia
acessa o busca.php
*/
function imprimeNoticia(id,idioma)
{
	var win2 = new Window('dialog2'+index, {className: "dialog", title: "Not&iacute;cia", top:150, left:150, width:500, height:300, zIndex:1000, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "Noticias/busca.php?id="+id+"&idioma="+idioma})
	win2.show();
	index++;	
}

function imprimeForadoLance(id,idioma)
{
	var win2 = new Window('dialog2'+index, {className: "dialog", title: "", top:150, left:150, width:500, height:300, zIndex:1000, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "Foradolance/busca.php?id="+id+"&idioma="+idioma})
	win2.show();
	index++;	
}

function imprimeFiquedeOlho(id,idioma)
{
	var win2 = new Window('dialog2'+index, {className: "dialog", title: "", top:150, left:150, width:500, height:300, zIndex:1000, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "FiquedeOlho/busca.php?id="+id+"&idioma="+idioma})
	win2.show();
	index++;	
}

function imprimeComunicado(id,idioma)
{
	var win2 = new Window('dialog2'+index, {className: "dialog", title: "", top:150, left:150, width:500, height:300, zIndex:1000, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "Comunicado/busca.php?id="+id+"&idioma="+idioma})
	win2.show();
	index++;	
}

function imprimeNota(id,idioma)
{
	var win2 = new Window('dialog2'+index, {className: "dialog", title: "", top:150, left:150, width:500, height:300, zIndex:1000, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "Notas/busca.php?id="+id+"&idioma="+idioma})
	win2.show();
	index++;	
}
/**
fun?ao para ser utilizada com o fale conosco
acessa o faleConosco.php
*/
function enviar()
{	
	var obrigado=document.getElementById("obrigado").value;
	
	var alerta=document.getElementById("alerta").value;
    var nome=document.getElementById("nome").value;
    var email=document.getElementById("email").value;
    var estado=document.getElementById("estado").value;
    var pais=document.getElementById("pais").value;
    var mensagem=document.getElementById("mensagem").value;
    if(!nome || !email || !mensagem)
	    alert(url_decode(alerta));
	else
	{   alert("faleConosco/faleConosco.php?nome="+nome+"&email="+email+"&estado="+estado+"&mensagem="+mensagem+"&pais="+pais);
		var win2 = new Window('dialog2'+index, {className: "dialog", title: obrigado, bottom:200, left:300, width:200, height:100, zIndex:150, opacity:10, resizable: true,hideEffect: Effect.SwitchOff, url: "faleConosco/faleConosco.php?nome="+nome+"&email="+email+"&estado="+estado+"&mensagem="+mensagem+"&pais="+pais})
		win2.show();
		index++;   
		document.getElementById('nome').value = ''; 
		document.getElementById('email').value = ''; 
		document.getElementById('estado').value = ''; 
		document.getElementById('mensagem').value = ''; 
		document.getElementById('pais').value = ''; 
	}	
}



function url_encode(str) { 
        var hex_chars = "0123456789ABCDEF"; 
        var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
        var n, strCode, hex1, hex2, strEncode = ""; 

        for(n = 0; n < str.length; n++) { 
            if (noEncode.test(str.charAt(n))) { 
                strEncode += str.charAt(n); 
            } else { 
                strCode = str.charCodeAt(n); 
                hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
                hex2 = hex_chars.charAt(strCode % 16); 
                strEncode += "%" + (hex1 + hex2); 
            } 
        } 
        return strEncode; 
    } 

    // url_decode version 1.0 
    function url_decode(str) { 
        var n, strCode, strDecode = ""; 

        for (n = 0; n < str.length; n++) { 
            if (str.charAt(n) == "%") { 
                strCode = str.charAt(n + 1) + str.charAt(n + 2); 
                strDecode += String.fromCharCode(parseInt(strCode, 16)); 
                n += 2; 
            } else { 
                strDecode += str.charAt(n); 
            } 
        } 

        return strDecode; 
    }  
