function GetXMLHttp() {
    if(navigator.appName == "Microsoft Internet Explorer") {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        xmlHttp = new XMLHttpRequest();
    }
    return xmlHttp;
}

var xmlRequest = GetXMLHttp();

function abrirPag(valor, local, load, clas){
    var url = valor;

    xmlRequest.open("GET",url,true);    
    xmlRequest.onreadystatechange = function(mudancaEstado){
        if (xmlRequest.readyState == 4){
            document.getElementById(local).innerHTML = xmlRequest.responseText;
        }
    };
    xmlRequest.send(null);

    if (xmlRequest.readyState == 1) {
        document.getElementById(local).innerHTML = "<div class='"+clas+"'><img src='includes/imagem/loads/"+load+".gif'></div>";
    }

    return url;
}
function abrirPag2(valor, local){
    var url = valor;

    xmlRequest.open("GET",url,true);    
    xmlRequest.onreadystatechange = function(mudancaEstado){
        if (xmlRequest.readyState == 4){
            document.getElementById(local).innerHTML = xmlRequest.responseText;
        }
    };
    xmlRequest.send(null);

    return url;
}
function abrirPag3(valor, local, load, clas){
    var url = valor;

    xmlRequest.open("GET",url,true);    
    xmlRequest.onreadystatechange = function(mudancaEstado){
        if (xmlRequest.readyState == 4){
            document.getElementById(local).innerHTML = xmlRequest.responseText;
        }
    };
    xmlRequest.send(null);

    if (xmlRequest.readyState == 1) {
        document.getElementById(local).innerHTML += "<div class='"+clas+"'><img src='includes/imagem/loads/"+load+".gif'></div>";
    }

    return url;
}

function abrirPag4(valor, local, local2){
    var url = valor;

    xmlRequest.open("GET",url,true);    
    xmlRequest.onreadystatechange = function(mudancaEstado){
        if (xmlRequest.readyState == 4){
            document.getElementById(local).innerHTML = xmlRequest.responseText;
        }
    };
    xmlRequest.send(null);

    if (xmlRequest.readyState == 1) {
        document.getElementById(local2).innerHTML = "<div class='load4'><img src='includes/imagem/loads/load 1.gif' alt='' title='Loading...'></div>";
    }

    return url;
}


function abrirPag5(valor, local){
    var url = valor;

    xmlRequest.open("GET",url,true);    
    xmlRequest.onreadystatechange = function(mudancaEstado){
        if (xmlRequest.readyState == 4){
            document.getElementById(local).innerHTML += xmlRequest.responseText;
        }
    };
    xmlRequest.send(null);

    return url;
}

//Fun��o que envia o formul�rio
function enviarForm(url, campos, destino) {
    var elemento = document.getElementById(destino); //Atribui � vari�vel 'elemento' o elemento que ir� receber a p�gina postada
    objetoXML(); //Executa a fun��o objetoXML()
    if (!xmlhttp) { //Se o objeto de 'xmlhttp' n�o estiver true
        elemento.innerHTML = 'Imposs&oacute;vel iniciar o objeto XMLHttpRequest.';
        return;
    } else { //Sen�o
        elemento.innerHTML += "<div class='load5'><img src='includes/imagem/loads/load 7.gif' alt='' title='Loading...'></div>"; //Insere no 'elemento' o texto atribu�do
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { //Se a requisi��o estiver completada
            if (xmlhttp.status == 200) { //Se o status da requisi��o estiver OK
                elemento.innerHTML = xmlhttp.responseText; //Insere no 'elemento' a p�gina postada
            } else { //Sen�o
                elemento.innerHMTL = 'P7aacute;gina n&atilde;o encontrada!'; //Insere no 'elemento' o texto atribu�do
            }
        }
    }
    xmlhttp.open('POST', url+'&'+campos, true); //Abre a p�gina que receber� os campos do formul�rio
    xmlhttp.send(campos); //Envia o formul�rio com dados da vari�vel 'campos' (passado por par�metro)
}

function setarCampos() {
    campos = "label="+encodeURI(document.getElementById('label').value)+"&url="+encodeURI(document.getElementById('url').value);
}

function confirmar(epi_id, link_id, local) {
    var text = '<span class="confirm" id="remove'+link_id+'">Certeza que deseja remover o link '+link_id+'? <a href="javascript:void(0)" onclick="abrirPag3(\'painel.php?painel=28&epi='+epi_id+'&link='+link_id+'\',\'links_id'+epi_id+'\',\'load 7\',\'load3\')">Sim</a> <a href="javascript:void(0)"" onclick="remover(\''+local+'\',\'remove'+link_id+'\')">N&atilde;o</a></span>';
    document.getElementById(local).innerHTML += text;
}

function confirmar2(epi_id, link_id, local) {
    var text = '<span class="confirm" id="remove'+link_id+'">Certeza que deseja remover todos os links? <a href="javascript:void(0)" onclick="abrirPag3(\'painel.php?painel=29&epi='+epi_id+'\',\'links_id'+epi_id+'\',\'load 7\',\'load3\')">Sim</a> <a href="javascript:void(0)"" onclick="remover(\''+local+'\',\'remove'+link_id+'\')">N&atilde;o</a></span>';
    document.getElementById(local).innerHTML += text;
}

function remover(local, div) {
    var d = document.getElementById(local);
    var olddiv = document.getElementById(div);
    d.removeChild(olddiv);
}


function setarCampos2(id) {
    campos = "label1="+encodeURI(document.getElementById(id+'label1').value)+"&url1="+encodeURI(document.getElementById(id+'url1').value);
    campos += "&label2="+encodeURI(document.getElementById(id+'label2').value)+"&url2="+encodeURI(document.getElementById(id+'url2').value);
    campos += "&label3="+encodeURI(document.getElementById(id+'label3').value)+"&url3="+encodeURI(document.getElementById(id+'url3').value);
    campos += "&label4="+encodeURI(document.getElementById(id+'label4').value)+"&url4="+encodeURI(document.getElementById(id+'url4').value);
    campos += "&label5="+encodeURI(document.getElementById(id+'label5').value)+"&url5="+encodeURI(document.getElementById(id+'url5').value);
}

function setarCampos3(id){
    var aa= document.getElementById(id);
    for (var i =0; i < aa.elements.length; i++)
    {
        aa.elements[i].checked = checked;
    }
}

function setarCampos4(id){
    if(document.getElementById(id).value == ''){
        alert('Digite alguma coisa filhao!');
        return;
    }
    campos = "comentario="+encodeURI(document.getElementById(id).value);
}

function objetoXML() {

    if (navegador.indexOf('msie') != -1) { //Internet Explorer

        var controle = (navegador.indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; //Operador tern�rio que adiciona o objeto padr�o do seu navegador (caso for o IE) � vari�vel 'controle'

        try {

            xmlhttp = new ActiveXObject(controle); //Inicia o objeto no IE

        } catch (e) { }

    } else { //Firefox, Safari, Mozilla

        xmlhttp = new XMLHttpRequest(); //Inicia o objeto no Firefox, Safari, Mozilla

    }

}
var navegador = navigator.userAgent.toLowerCase(); //Cria e atribui � vari�vel global 'navegador' (em caracteres min�sculos) o nome e a vers�o do navegador

//Cria uma vari�vel global chamada 'xmlhttp'
var xmlhttp;

function morecoments(id, pagina)
{
    var d = document.getElementById(id);
    var olddiv = document.getElementById("more");
    d.removeChild(olddiv);
    abrirPag5(pagina, 'comments_list');
}

function eraseform(id)
{
    document.getElementById(id).value = '';
    document.form1.contador.value = '0/300';
}

function atualizacmm(id){
    var pag = 'noticias.php?board=reload&id='+id+'';
    abrirPag3(pag, 'comments_list', 'load 7', 'load5');
}