/**
 * Funções By Gelvinn (incluindo os erros de portugues..hehe)
 * Modificações e aperfeiçoamentos By Micael Liberato 
 */
 
// JavaScript Document 
// FUNÇÃO RESPONSÁVEL DE CONECTAR A UMA PAGINA EXTERNA NO NOSSO CASO A BUSCA_NOME.PHP 
// E RETORNAR OS RESULTADOS 

function ajax(url) 
{ 

//alert(nick); 
//alert(dest); 
//alert(msg); 

req = null; 
// Procura por um objeto nativo (Mozilla/Safari) 
if (window.XMLHttpRequest) { 
req = new XMLHttpRequest(); 
req.onreadystatechange = processReqChange; 
req.open("GET",url,true); 
req.send(null); 
// Procura por uma versão ActiveX (IE) 
} else if (window.ActiveXObject) { 
req = new ActiveXObject("Microsoft.XMLHTTP"); 
if (req) { 

req.onreadystatechange = processReqChange; 
req.open("GET",url,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="pagina" e insere o conteudo 
// retornado nela, como texto HTML 

document.getElementById('resultado').innerHTML = req.responseText; 

} else { 
alert("Houve um problema ao obter os dados:n" + req.statusText); 
} 
} 
} 
 
var vEmailD = false;

function criaReqStr(oForm){
    var aPostStr = new Array();

    for(var i = 0; i < oForm.elements.length; i++){
        var sValor = encodeURIComponent(oForm.elements[i].name);
        sValor += "=";
        sValor += encodeURIComponent(oForm.elements[i].value);
        aPostStr.push(sValor);
    }
    // retorna uma string no padrão "post request":
    // nome1=valor1&nome2=valor2&...&nomeN=valorN
    return aPostStr.join("&");
}

function vEmail(mail) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=vemail&mail=" + mail, true);
    XMLHttp.onreadystatechange = function () {
        if (XMLHttp.readyState == 4) {
            var v = document.getElementById('vEmail');
            v.innerHTML = XMLHttp.responseText;

            if (XMLHttp.responseText == 'Email Disponivel!') {
                vEmailD = true;
            } else if (XMLHttp.responseText == 'Email Indisponivel!') {
                vEmailD = false;
            } else if (XMLHttp.responseText == 'Email Inválido!') {
                vEmailD = false;
            }

        } else {
            var v = document.getElementById('vEmail');
            v.innerHTML = 'Carregando...';
        }
    };
    XMLHttp.send(null);
}

function enviaRecado(idUsu,msg,idRemetente) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=enviarecado&id=" + idUsu + "&msg=" + msg + "&idrem=" + idRemetente, true);
    XMLHttp.onreadystatechange = function () {

        var carregando = document.getElementById('carregando');

        if (XMLHttp.readyState == 4) {
            carregando.style.display = 'none';

            document.getElementById('textoRecado').value = '';

            var c = document.getElementById('atualizaRecados');
            c.innerHTML = XMLHttp.responseText;
        } else {

            carregando.style.display = 'block';
        }
    };
    XMLHttp.send(null);
}
function enviaRecadoOnline(para,msg,tipo) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=enviarecadoonline&para=" + para + "&tipo=" + tipo + "&msg=" + msg , true);
    XMLHttp.onreadystatechange = function () {

        var carregando = document.getElementById('carregando');

        if (XMLHttp.readyState == 4) {
            carregando.style.display = 'none';

            document.getElementById('msg').value = '';
			document.getElementById('para').value = '';

            var c = document.getElementById('atualizaRecados');
            c.innerHTML = XMLHttp.responseText;
        } else {

            carregando.style.display = 'block';
        }
    };
    XMLHttp.send(null);
}
function excluiRecado(idRecado,idUsu) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=excluirecado&id=" + idRecado + "&idusu=" + idUsu, true);
    XMLHttp.onreadystatechange = function () {

        var carregando = document.getElementById('carregando');

        if (XMLHttp.readyState == 4) {
            carregando.style.display = 'none';

            document.getElementById('textoRecado').value = '';

            var c = document.getElementById('atualizaRecados');
            c.innerHTML = XMLHttp.responseText;
        } else {

            carregando.style.display = 'block';
        }
    };
    XMLHttp.send(null);
}


function excluiRecadoOnline(idRecado,idUsu) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=excluirecadoonline&id=" + idRecado + "&idusu=" + idUsu, true);
    XMLHttp.onreadystatechange = function () {

        var carregando = document.getElementById('carregando');

        if (XMLHttp.readyState == 4) {
            carregando.style.display = 'none';

            
			  document.getElementById('msg').value = '';
			document.getElementById('para').value = '';

       
            var c = document.getElementById('atualizaRecados');
            c.innerHTML = XMLHttp.responseText;
        } else {

            carregando.style.display = 'block';
        }
    };
    XMLHttp.send(null);
}
function menuPromocoesUp() { 
    var menu = document.getElementById('programacao'); menu.style.visibility = 'visible';
}
function menuPromocoesOut() { 
    var menu = document.getElementById('programacao'); menu.style.visibility = 'hidden';
}

function fecharPopup() { 
    var menu = document.getElementById('popup'); menu.style.visibility = 'hidden';
}

function mostraCamposExtras() { 
    var campos = document.getElementById('camposExtras'); campos.style.display = 'block'; var fCampos = document.getElementById('fCamposExtras'); fCampos.innerHTML = '<a href="" onclick="ocultaCamposExtras(); return false;" style="display:block; background-color: #DBEEF7; border:1px solid; cursor:pointer;">Ocultar Campos</a>';
}
function ocultaCamposExtras() { 
    var campos = document.getElementById('camposExtras'); campos.style.display = 'none'; var fCampos = document.getElementById('fCamposExtras'); fCampos.innerHTML = '<a href="" onclick="mostraCamposExtras(); return false;" style="display:block; background-color: #DBEEF7; border:1px solid; cursor:pointer;">Adicionar Campos</a>';
}

function jaCadastrado() {  
    var campos = document.getElementById('cadastrado'); campos.style.display = 'block'; var fCampos = document.getElementById('nao_cadastrado'); fCampos.style.display = 'none';
}
function naoCadastrado() { 
    var campos = document.getElementById('cadastrado'); campos.style.display = 'none'; var fCampos = document.getElementById('nao_cadastrado'); fCampos.style.display = 'block';
}

function validaPParticipar() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';
//    var val = 'E';

//        if (document.fCadastro.aemail.value==''){
//            msg=(msg+'\n - Email' + pam)
//        }
//        if (document.fCadastro.fsenha.value==''){
//            msg=(msg+'\n - Senha')
  //      }
  
   //     val = '';
   // }
  if (document.fCadastro.cad.checked == true){
//
//        if (document.fCadastro.femail.value==''){
//            msg=(msg+'\n - Email')
//        }
//        if (document.fCadastro.fsenha.value==''){
//            msg=(msg+'\n - Senha')
//        }
//        if (document.fCadastro.fsenha.value != document.fCadastro.fconfsenha.value){
//            msg=(msg+'\n - Senhas Não Conferem')
//        }
//        if (document.fCadastro.fnome.value==''){
//            msg=(msg+'\n - Nome Completo')
//        }
//        if (document.fCadastro.frg.value==''){
//            msg=(msg+'\n - RG')
//        }
//        if (document.fCadastro.fnascimento.value==''){
//            msg=(msg+'\n - Data de Nasc.')
//        }
//        if (document.fCadastro.ftelefone.value==''){
//            msg=(msg+'\n - Telefone')
//        }
//        if (document.fCadastro.fendereco.value==''){
//            msg=(msg+'\n - Endereço')
//        }
//        if (document.fCadastro.fbairro.value==''){
//            msg=(msg+'\n - Bairro')
//        }
//        if (document.fCadastro.fcidade.value==''){
//            msg=(msg+'\n - Cidade')
//        }
//        if (document.fCadastro.festado.value==''){
//            msg=(msg+'\n - Estado')
//        }
//        if (document.fCadastro.ftermos.value=='aceito'){
//            msg=(msg+'\n - Você deve aceitar os Termos de Uso!')
//        }
//        val = '';
//    }
 if (document.fCadastro.femail.value==''){
        msg=(msg+'\n - Email')
    }
   
    if (document.fCadastro.fnome.value==''){
        msg=(msg+'\n - Nome Completo')
    }
    if (document.fCadastro.frg.value==''){
        msg=(msg+'\n - RG')
    }
    if (document.fCadastro.fnascimento.value==''){
        msg=(msg+'\n - Data de Nasc.')
    }
    if (document.fCadastro.ftelefone.value==''){
        msg=(msg+'\n - Telefone')
    }
    if (document.fCadastro.fendereco.value==''){
        msg=(msg+'\n - Endereço')
    }
    if (document.fCadastro.fbairro.value==''){
        msg=(msg+'\n - Bairro')
    }
    if (document.fCadastro.fcidade.value==''){
        msg=(msg+'\n - Cidade')
    }
    if (document.fCadastro.festado.value==''){
        msg=(msg+'\n - Estado')
    }  }
	
	  if (document.fCadastro.ftermos.checked == false){
            msg=(msg+'\n - Você deve aceitar os Termos de Uso!')
        } 
//    if (val=='') {
        if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
            alert(msg);
        }else{
            document.fCadastro.submit();
        }
 //   }

}
function validaCadastro() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.fCadastro.femail.value==''){
        msg=(msg+'\n - Email')
    }
    if (vEmailD == false){
        msg=(msg+'\n - Email Inválido')
    }
    if (document.fCadastro.fsenha.value==''){
        msg=(msg+'\n - Senha')
    }
    if (document.fCadastro.fsenha.value != document.fCadastro.fconfsenha.value){
        msg=(msg+'\n - Senhas Não Conferem')
    }
    if (document.fCadastro.fnome.value==''){
        msg=(msg+'\n - Nome Completo')
    }
    if (document.fCadastro.frg.value==''){
        msg=(msg+'\n - RG')
    }
    if (document.fCadastro.fnascimento.value==''){
        msg=(msg+'\n - Data de Nasc.')
    }
    if (document.fCadastro.ftelefone.value==''){
        msg=(msg+'\n - Telefone')
    }
    if (document.fCadastro.fendereco.value==''){
        msg=(msg+'\n - Endereço')
    }
    if (document.fCadastro.fbairro.value==''){
        msg=(msg+'\n - Bairro')
    }
    if (document.fCadastro.fcidade.value==''){
        msg=(msg+'\n - Cidade')
    }
    if (document.fCadastro.festado.value==''){
        msg=(msg+'\n - Estado')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.fCadastro.submit();
    }
}
function vAlterarCadastro() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

  
    if (document.fCadastro.fnome.value==''){
        msg=(msg+'\n - Nome Completo')
    }
    if (document.fCadastro.frg.value==''){
        msg=(msg+'\n - RG')
    }
    if (document.fCadastro.ftelefone.value==''){
        msg=(msg+'\n - Telefone')
    }
    if (document.fCadastro.fendereco.value==''){
        msg=(msg+'\n - Endereço')
    }
    if (document.fCadastro.fbairro.value==''){
        msg=(msg+'\n - Bairro')
    }
    if (document.fCadastro.fcidade.value==''){
        msg=(msg+'\n - Cidade')
    }
    if (document.fCadastro.festado.value==''){
        msg=(msg+'\n - Estado')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.fCadastro.submit();
    }
}

function vAlterarSenha() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.fCadastro.fsenha.value==''){
        msg=(msg+'\n - Senha')
    }
    if (document.fCadastro.fsenha.value != document.fCadastro.fconfsenha.value){
        msg=(msg+'\n - Senhas Não Conferem')
    }
 

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.fCadastro.submit();
    }
}

function validaPromocao() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.fCPromocao.ptitulo.value==''){
        msg=(msg+'\n - Título')
    }
    if (document.fCPromocao.pinicio.value==''){
        msg=(msg+'\n - Data de Início')
    }
    if (document.fCPromocao.ptermino.value==''){
        msg=(msg+'\n - Data de Termino')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.fCPromocao.submit();
    }
}

function validaPedido() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.fCPromocao.musica.value==''){
        msg=(msg+'\n - Musica')
    }
    if (document.fCPromocao.cantor.value==''){
        msg=(msg+'\n - Cantor')
    }
    
    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
         alert('Seu pedido foi enviado com sucesso');
		document.fCPromocao.submit();
    }
}

// BASES -------------------------------------------------------------------------------------------------------

function atualizaSite(pg,id) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/paginas.php?pg=" + pg + "&id=" + id, true);
    XMLHttp.onreadystatechange = function () {
        if (XMLHttp.readyState == 4) {
            var divCarregando = document.getElementById("carregando");
            divCarregando.style.visibility = "hidden";
            var divConteudo = document.getElementById("conteudo");
            divConteudo.innerHTML = XMLHttp.responseText;
        } else {
            var divCarregando = document.getElementById("carregando");
            divCarregando.style.visibility = "visible";
        }
    };
    XMLHttp.send(null);
}

function atualizaSiteR(pg,id) {
    setTimeout("location.href='index.php?pg=" + pg + "&id=" + id,0);
}

function deletaFoto(idFoto,idColecao) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=deletafoto&id=" + idFoto, true);
    XMLHttp.onreadystatechange = function () {
        if (XMLHttp.readyState == 4) {
            atualizaSite('5',idColecao);
        }
    };
    XMLHttp.send(null);
}

function deletaColecao(id) {
    var XMLHttp = criaXMLHttp();
    XMLHttp.open("get", "scripts/funcoes.php?funcao=colecao&acao=excluir&id=" + id, true);
    XMLHttp.onreadystatechange = function () {
        if (XMLHttp.readyState == 4) {
            atualizaSite('2');
        }
    };
    XMLHttp.send(null);
}

function atualizaUpload(id) {
    window.location.href = "../?pg=5&id=" + id ;
}


function validaEmail() {

    var msg='Os seguintes campos devem ser preenchidos corretamente: ';
	
    if (document.formEmail.nomeEmail.value==''){
        msg=(msg+'\n - Nome')
    }
	
    if (document.formEmail.emailEmail.value==''){
        msg=(msg+'\n - Email')
    }
	
    if (document.formEmail.assuntoEmail.value==''){
        msg=(msg+'\n - Assunto')
    }
	
    if (document.formEmail.msgEmail.value==''){
        msg=(msg+'\n - Mensagem')
    }
	
    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.formEmail.submit();
    }
}

function validaUsuario(){
    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.formUsuario.nome.value==''){
        msg=(msg+'\n - Nome de exibição')
    }

    if (document.formUsuario.login.value==''){
        msg=(msg+'\n - Login')
    }

    if (document.formUsuario.senha.value==''){
        msg=(msg+'\n - Senha')
    }

    if(document.formUsuario.confirmar_senha.value != document.formUsuario.senha.value){
        msg=(msg+'\n - Confirmar senha')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.formUsuario.submit();
    }
}

function validaNovidade(){
    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.formNovidade.data.value==''){
        msg=(msg+'\n - Data da novidade')
    }

    if (document.formNovidade.titulo.value==''){
        msg=(msg+'\n - Título da novidade')
    }

    if (document.formNovidade.texto.value==''){
        msg=(msg+'\n - Texto da novidade')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.formNovidade.submit();
    }
}

function validaColecao(){
    var msg='Os seguintes campos devem ser preenchidos corretamente: ';

    if (document.formColecao.nome.value==''){
        msg=(msg+'\n - Nome da coleção')
    }

    if (document.formColecao.data.value==''){
        msg=(msg+'\n - Data da coleção')
    }

    if(document.formColecao.comentario.value==''){
        msg=(msg+'\n - Comentário')
    }

    if (msg!='Os seguintes campos devem ser preenchidos corretamente: '){
        alert(msg);
    }else{
        document.formColecao.submit();
    }
}

function mascaraData(evento, objeto){
    var keypress=(window.event)?event.keyCode:evento.which;
    campo = eval (objeto);
    if (campo.value == '00/00/0000')
    {
        campo.value=""
    }

    caracteres = '0123456789';
    separacao1 = '/';
    conjunto1 = 2;
    conjunto2 = 5;
    conjunto3 = 10;
    conjunto4 = 13;
    conjunto5 = 16;
    if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (11))
    {
        if (campo.value.length == conjunto1 )
            campo.value = campo.value + separacao1;
        else if (campo.value.length == conjunto2)
            campo.value = campo.value + separacao1;
    }
    else
        event.returnValue = false;
}