    function abre(pg,w,h){
        x = ((screen.width - w)/2)+150;
        y = ((screen.height - h)/2)-50;
        window.open(pg,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width='+w+',height='+h+',top='+y+',left='+x);
    }
    
    function valida_FaleConosco(x){
    
      if (x.nome.value.length < 4)  {
            alert('Por favor informe seu nome completo.');
            x.nome.focus();
            return false;
      }
      
      if (x.telefone.value.length != 14)  {
        alert('Por favor informe seu telefone. Assim é mais fácil entrarmos em contato com você.');
        x.telefone.focus();
        return false;
      }

      if ((x.email.value.length > 0) && (!isEmail(x.email.value))) {
        alert('Por favor nos informe seu e-mail corretamente.');
        x.email.focus();
        return false;
      }
      
      if (x.mensagem.value.length <= 10)  {
        alert('Ops, você esqueceu de deixar sua mensagem.');
        x.mensagem.focus();
        return false;
      }
        
      return confirma();
    }
    
  function preenche_dados(sexo){
      if (sexo == 1) {
        document.frm.vocativo.value = 'Prezado';
        document.frm.tratamento.value = 'Sr.';
      } else {
        document.frm.vocativo.value = 'Prezada';
        document.frm.tratamento.value = 'Sra.';
      }
  }
  
  function validaBairroRegiao(campo){
      var nome = document.getElementById('nome'); 
      if (nome.value.length <= 2) {
        alert('Por favor preencha o campo '+ campo +' corretamente.');
        nome.focus();
        return false;
      }
      return confirma();
    }
    
    function validaLogin(evt){
      var charCode = (evt.which) ? evt.which : event.keyCode;
      //return (charCode>=48 && charCode<=57 || charCode<20) || (charCode >= 97 && charCode<=122) || (charCode >= 65 && charCode<=90);
      return (charCode>=48 && charCode<=57) || (charCode >= 97 && charCode<=122);
    }
  
    function deleteRow(linha,arquivo){
    if(confirm('Este processo irá excluir o registro desejado. Deseja realmente excluir ?')) {
      //define o objeto XMLHttpRequest
      var req;
      var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');

      for (var i = 0; i < msxmlhttp.length; i++)
        try {req = new ActiveXObject(msxmlhttp[i]);} catch (e) {req = null;}

      if(!req && typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();

      req.open("post", "./util/apaga_ini.php?delete=1&arquivo=" + arquivo, false);
      req.send(null);
      retorno = parseInt(unescape(req.responseText.replace(/\+/g,'')));
      if (retorno == 1)
        document.getElementById('tbCadastros').deleteRow(linha)
    }
  }

  function valida_cad_externo() {
  
    var n = parseInt(document.getElementById('qteregs').value);
    var eleNome;
    var eleEstado;
    var eleCidade;
    var eleBairro;
    
    for (var i=1; i<=n; i++) {

      eleNome = document.getElementById('nome'+i);

      if (eleNome != null) {

         eleEstado = document.getElementById('codestado'+i);
         eleCidade = document.getElementById('codcidade'+i);
         eleBairro = document.getElementById('codbairro'+i);

         if (eleNome.value.length < 3) {
           alert('Preencha o Nome completo do novo contato.');
           eleNome.focus();
           return false;
           break;
         };

         if (eleCidade.selectedIndex == 0) {
           alert('Selecione a Cidade do novo contato. Para isso selecione\nprimeiro o Estado em seguida escolha a cidade.');
           eleEstado.focus();
           return false;
           break;
         };

         eleNome   = null;
         eleCidade = null;
         eleBairro = null;

      };//if (eleNome != null) {

    };//for (var i=1; i<=n; i++) {

    return confirma();
  };
  
  function carregaCidade(codestado,local){
 
    if (codestado != '') {

      if (parseInt(local) > 0)
        var objeto = document.getElementById('idCidade'+local);
      else var objeto = document.getElementById('idCidade');

      objeto.innerHTML = '<select class="combo"><option>aguarde...</option></select>';

      //define o objeto XMLHttpRequest
      var req;
      var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
      for (var i = 0; i < msxmlhttp.length; i++) {
        try {req = new ActiveXObject(msxmlhttp[i]);} catch (e) {req = null;}
      }

      if(!req && typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();

      req.open("post", "./util/busca_cidades.php?codestado=" + codestado + "&local="+local, false);
      req.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
      //req.setRequestHeader("encoding", "ISO-8859-1");
      //req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
      //req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
      req.setRequestHeader("Pragma", "no-chache");
      req.setRequestHeader("Cache-Control", "no-chache");
      req.send(null);

      page = unescape(req.responseText.replace(/\+/g,''));
      objeto.innerHTML = page;
      req = false;
    } else
      objeto.innerHTML = 'falha buscando cidades...';
  }

  function carregaBairro(codcidade,local){

    if (codcidade != '') {

      if (parseInt(local) > 0)
        var objeto = document.getElementById('idBairro'+local);
      else var objeto = document.getElementById('idBairro');
      
      objeto.innerHTML = '<select class="combo"><option>aguarde...</option></select>';

      //define o objeto XMLHttpRequest
      var req;
      var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
      for (var i = 0; i < msxmlhttp.length; i++) {
        try {req = new ActiveXObject(msxmlhttp[i]);} catch (e) {req = null;}
      }
      if(!req && typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();

      req.open("post", "./util/busca_bairros.php?codcidade=" + codcidade + "&local="+local, false);
      req.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
      //req.setRequestHeader("encoding", "ISO-8859-1");
      //req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
      //req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
      req.setRequestHeader("Pragma", "no-chache");
      req.setRequestHeader("Cache-Control", "no-chache");
      req.send(null);

      page = unescape(req.responseText.replace(/\+/g,''));
      objeto.innerHTML = page;
      req = false;
    } else
      objeto.innerHTML = 'falha buscando bairros...';
  }


  function carregaRegiao(codcidade,local){
    
    if (parseInt(local) > 0)
      var objeto = document.getElementById('idRegiao'+local);
    else var objeto = document.getElementById('idRegiao');

    
    if ((objeto != null) && (codcidade != '')) {

      objeto.innerHTML = '<select class="combo"><option>aguarde...</option></select>';

      //define o objeto XMLHttpRequest
      var req;
      var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
      for (var i = 0; i < msxmlhttp.length; i++) {
        try {req = new ActiveXObject(msxmlhttp[i]);} catch (e) {req = null;}
      }
      if(!req && typeof XMLHttpRequest != "undefined")
        req = new XMLHttpRequest();

      req.open("post", "./util/busca_regioes.php?codcidade=" + codcidade + "&local="+local, false);
      req.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
      //req.setRequestHeader("encoding", "ISO-8859-1");
      //req.setRequestHeader("Cache-Control", "no-store, no-cache, must-rete");
      //req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
      req.setRequestHeader("Pragma", "no-chache");
      req.setRequestHeader("Cache-Control", "no-chache");
      req.send(null);

      page = unescape(req.responseText.replace(/\+/g,''));
      objeto.innerHTML = page;
      req = false;
    }
  }

    //Diferença d1-d2. As datas devem ser dd/mm/aaaa
    function diferencaDias(d1,d2){
        var dt1 = d1.split("/");
        var dt2 = d2.split("/");
        var ano1, mes1, dia1, ano2, mes2, dia2;
                
        dia1 = dt1[0]
        mes1 = dt1[1];
        ano1 = dt1[2];
        dia2 = dt2[0]
        mes2 = dt2[1];
        ano2 = dt2[2];
    
        var data1 = new Date(ano1, mes1, dia1);
        var data2 = new Date(ano2, mes2, dia2);
    
        var dif =
              Date.UTC(data1.getYear(),data1.getMonth(),data1.getDate(),0,0,1)
            - Date.UTC(data2.getYear(),data2.getMonth(),data2.getDate(),0,0,1);
    
        //var retorno = Math.abs((dif / 1000 / 60 / 60 / 24));
        var retorno = (dif / 1000 / 60 / 60 / 24);
        return retorno;
    }
  
    function habilitaCampos(x) {
      var empresa       = document.getElementById('empresa');
      var localtrabalho = document.getElementById('localtrabalho');
      var dataadmissao  = document.getElementById('dataadmissao');
      var datademissao  = document.getElementById('datademissao');
      var salario       = document.getElementById('salario');
      var contribuicao  = document.getElementById('contribuicao');
      var tipofiliado   = document.getElementById('tipoFiliado');
      var carreira      = document.getElementById('carreira');
      var nivel         = document.getElementById('nivel');
      var datainscricao = document.getElementById('datainscricao');
      var ninscricao    = document.getElementById('ninscricao');
      
      
      if (x) {
        empresa.style.background       = '#EAEAEA';
        localtrabalho.style.background = '#EAEAEA';
        dataadmissao.style.background  = '#EAEAEA';
        datademissao.style.background  = '#EAEAEA';
        salario.style.background       = '#EAEAEA';
        contribuicao.style.background  = '#EAEAEA';
        tipofiliado.style.background   = '#EAEAEA';
        carreira.style.background      = '#EAEAEA';
        nivel.style.background         = '#EAEAEA';
        datainscricao.style.background = '#EAEAEA';
        ninscricao.style.background    = '#EAEAEA';
      } else { 
        empresa.style.background       = '#FFFFFF';
        localtrabalho.style.background = '#FFFFFF';
        dataadmissao.style.background  = '#FFFFFF';
        datademissao.style.background  = '#FFFFFF';
        salario.style.background       = '#FFFFFF';
        contribuicao.style.background  = '#FFFFFF';
        tipofiliado.style.background   = '#FFFFFF';
        carreira.style.background      = '#FFFFFF';
        nivel.style.background         = '#FFFFFF';
        datainscricao.style.background = '#FFFFFF';
        ninscricao.style.background    = '#FFFFFF';
      };
      
      empresa.disabled       = x;
      localtrabalho.disabled = x;
      dataadmissao.disabled  = x;
      datademissao.disabled  = x;
      salario.disabled       = x;
      contribuicao.disabled  = x;
      tipofiliado.disabled   = x;
      carreira.disabled      = x;
      nivel.disabled         = x;
      datainscricao.disabled = x;
      ninscricao.disabled    = x;
    }
    
    function verificaCampos(x) {
          habilitaCampos((x!=0) && (x!=2));
    }
    
    function habilitaFiliado(x) {
      
      var tipoFiliado  = document.getElementById('tipoFiliado');
      
      if (x==1) {
        tipoFiliado.style.background = '#EAEAEA';
        tipoFiliado.disabled  = false;
      } else { 
        tipoFiliado.style.background = '#FFFFFF';
        tipoFiliado.disabled  = true;
      }
    }

    function criar_grupo(nome,pagina,codcontato) {
        if (confirm("Esta opção permite criar um novo grupo o qual terá "+nome+" como coordenardor(a).\n\nDeseja continuar ?"))
            window.location.href = pagina+'?codcontato='+codcontato+'&criar=1';
    }
    
    function Limpar(valor, validos) {
        // retira caracteres invalidos da string
        var result = "";
        var aux;
        for (var i=0; i < valor.length; i++) {
            aux = validos.indexOf(valor.substring(i, i+1));
            if (aux>=0) {
                result += aux;
            }
        }
        return result
    }
    
    // formata moeda
    function FormataMoeda(campo,tammax,teclapres,decimal) {
        var tecla = teclapres.keyCode;
        vr = Limpar(campo.value,"0123456789");
        tam = vr.length;
        dec=decimal

        if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

        if (tecla == 8 ) { tam = tam - 1 ; }

        if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {

            if ( tam <= dec ) { campo.value = vr ; }

            if ( (tam > dec) && (tam <= 5) ){
                campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
            }
            if ( (tam >= 6) && (tam <= 8) ){
                campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;
            }
            if ( (tam >= 9) && (tam <= 11) ){
                campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
            }
            if ( (tam >= 12) && (tam <= 14) ){
                campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
            }
            if ( (tam >= 15) && (tam <= 17) ){
                campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
            }
        }
    } 


    function validaUpload() { 
      
      var f1 = document.getElementById('f1');
      var submit = document.getElementById('submit');
      
      if (f1.value.length > 0) {
         var listaf1 = f1.value.split('\\');        
         
         var extensao = listaf1[listaf1.length - 1].toLowerCase();
         
         var pos     = extensao.indexOf(".jpg");
         var pos1    = extensao.indexOf(".bmp");         
         
         if (parseInt(pos+pos1) <= 0) {
           alert('Atenção, NÃO É PERMITIDO ENVIAR ESSE TIPO DE ARQUIVO!\nSão permitidos apenas arquivos de imagem no formato JPG ou BMP.\n\nPor favor verifique o arquivo e tente novamente.');
           return false;
         }
         
      } else {
         alert('Atenção, é necessário selecionar um arquivo de foto para realizar este procedimento.');
         return false;
      }
      
       submit.disabled = confirma();
       return submit.disabled;
         
    }

    function confirma() {
       return confirm("Cornfirmação \n"+
                       "======== \n\n"+
                       "Deseja salvar estas informações ?");
    
    }
  
    function validaPublicidade() { 
      
      var data = document.getElementById('data');
      var f1 = document.getElementById('f1');
      var f2 = document.getElementById('f2');
      var submit = document.getElementById('submit');
      
      if ((data.value.length != 10) || (f1.value.length == 0) || (f2.value.length == 0)) {
      
         alert('Atenção, para a correta divulgação do evento é necessário que sejam preenchidos dos campos.');
         data.focus();
         return false;
      
      } else {
      
        if (f1.value.length > 0) {
           var listaf1 = f1.value.split('\\');        
           var pos     = listaf1[listaf1.length - 1].indexOf(".jpg");
         
           if (parseInt(pos) <= 0) {
             alert('Atenção, o Arquivo Mini que você está tentando enviar deve estar no formato JPG.');
             return false;
           }
        } 
      
        if (f2.value.length > 0) {
           var listaf2 = f2.value.split('\\');        
           var pos     = listaf2[listaf2.length - 1].indexOf(".jpg");        
         
           if (parseInt(pos) <= 0) {
             alert('Atenção, o Arquivo que você está tentando enviar deve estar no formato JPG.');
             return false;
           }
        } //if (f2.value.length > 0){

      }
       
       submit.disabled = confirma();
       return submit.disabled;
    }
    
    
    function separa_cidade_uf(str,operacao) {
      var pos = str.indexOf('/');
      if (operacao == 0)
        return str.substr(0,pos-1);//Retorna a Cidade
      else
        return str.substr(pos+1,str.length);//Retorna o Estado
    }
  
    function consulta_cep(str1,tipo,end,num){
        var uf;
        var local;
        
        if (str1 != '') {
          var  uf    = separa_cidade_uf(str1,1);
          var  local = separa_cidade_uf(str1,0);
        }
        
        w = 365; h = 330;
        x = ((screen.width - w)/2)+150;
        y = ((screen.height - h)/2)-50;

        window.open('consulta_cep.php?uf='+uf+'&local='+local+'&tipo='+tipo+'&end='+end+'&num='+num,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }

   function consulta_cep2(url,strUF,strCidade,tipo,end,num){
        
        w = 365; h = 330;
        x = ((screen.width - w)/2)+150;
        y = ((screen.height - h)/2)-50;

        window.open(url + '/consulta_cep.php?uf='+strUF+'&local='+strCidade+'&tipo='+tipo+'&end='+end+'&num='+num,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
    
	function consulta_titulo(titulo){

        w = 560; h = 460;
        x = ((screen.width - w)/2)+170;
        y = ((screen.height - h)/2)-100;

        window.open('consulta_titulo.php?numero='+titulo,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
    
    function valida_rel_financeiro(x) {
    
        if (x.codconta.selectedIndex == 0) {
            alert('É necessário selecione a Conta para geração do relatório.');
            x.codconta.focus();
            return false;
        }

        if (x.de.value.length != 10 ) {
            alert('É necessário fornecer a Data Inicial geração do relatório.');
            x.de.focus();
            return false;
        }
        
        if (x.ate.value.length != 10 ) {
            alert('É necessário fornecer a Data Final geração do relatório.');
            x.ate.focus();
            return false;
        }
        
        if (diferencaDias(x.ate.value,x.de.value) > 366 ) {
            alert("A diferença entre as datas não deve ser superior a um ano.");
            x.ate.value = '';
            x.ate.focus();
            return false;            
        }
        
        return true;
    
    }
    
    function valida_visualizacao(x){
         
        if (x.de.value.length != 10 ) {
            alert('É necessário fornecer a Data Inicial geração do relatório.');
            x.de.focus();
            return false;
        }
        
        if (x.ate.value.length != 10 ) {
            alert('É necessário fornecer a Data Final geração do relatório.');
            x.ate.focus();
            return false;
        }
        
        if (diferencaDias(x.ate.value,x.de.value) > 366 ) {
            alert("A diferença entre as datas não deve ser superior a um ano.");
            x.ate.value = '';
            x.ate.focus();
            return false;            
        }
        
        if ((x.criarmodelo[1].checked) && (x.opcoesdatas.selectedIndex == 6)) {
            alert('Atenção\n'+
                  '=====\n\n'+
                  'Para salvar um Modelo de Reltório é necessário que selecione\noutra opção diferente "Escolher data" em "Opções Rápidas".');
            x.opcoesdatas.focus();
            return false;
        }

        if ((x.criarmodelo[1].checked) && (x.nomenovomodelo.value == '')) {
            alert('Por favor forneça o nome do novo Modelo de Relatório.');
            x.nomenovomodelo.focus();
            return false;
        }
        else
            return true;
    }

    function valida_candidato(x){
        
        if (x.nomecandidato.value.length < 2 ) {
            alert('É necessário fornecer o Nome do Candidato.');
            x.nomecandidato.focus();
            return false;
        }
        
        return confirma();
    }

     function limpa_contatos(x) {
        x.nome.value='';
        x.apelido.value='';
        x.endereco.value='';
        x.numero.value='';
        x.complemento.value='';
        x.codestado.selectedIndex = 0;
        x.codcidade.selectedIndex = 0;
        x.codbairro.selectedIndex = 0;
        x.codregiao.selectedIndex = 0;
        x.cep.value='';
        x.sexo.selectedIndex = 1;
        x.datanascimento__data.value='';
        
        x.telefone1.value='';
        x.telefone2.value='';
        x.celular.value='';
        x.email.value='';
        
        if (x.autorizaPlaca != null) x.autorizaPlaca.selectedIndex= 0;
          
        if (x.autorizaAdesivo != null) x.autorizaAdesivo.selectedIndex= 0;
          
        if (x.apoio != null) x.apoio.selectedIndex= 0;
        
        if (x.motivo != null) x.motivo.value='';
        
        x.codclassificacao.selectedIndex= 0;
        x.indicacao.value='';
        x.vocativo.value='';
        x.tratamento.value='';
        x.codprofissao.selectedIndex=0;
        x.relacionamento.selectedIndex=2;
        x.cpf.value='';
        x.rg.value='';
        x.codescolaridade.selectedIndex=0;
        x.curso.value='';
        x.nomepai.value='';
        x.nomemae.value='';
        
        if (x.grupo != null) x.grupo.selectedIndex=0;
        
        x.filiadopartido.selectedIndex=1;
        x.tipofiliado.selectedIndex=0;
        x.datainscricao__data.value='';
        x.ninscricao.value='';
        x.numerotitulo.value='';
        x.zonatitulo.value='';
        x.secaotitulo.value='';
        
        x.empresa.value='';
        x.localtrabalho.value='';
        x.dataadmissao__data.value='';
        x.datademissao__data.value=''
        x.salario__real.value='';
        x.contribuicao__real.value='';
        x.carreira.checked=false;
        x.nivel.selectedIndex=-1;
        
        x._selecao1.value='';
        x._selecao2.value='';
        x._selecao3.value='';
        x._selecao4.value='';
        x._selecao5.value='';
        
        x.obs.value='';
    }
 
    function limpa_memoria(x) {
        x.tipocontato.value = '';
        x.assunto.value     = '';
        x.solucao.value     = '';
        x.responsavel.selectedIndex = -1;
    }

    function limpa_financeiro(x){
        x.dataregistro.value='';
        x.dataentrada.value='';
        x.descricao.value='';
        x.complemento.value='';
        x.codconta.selectedIndex=0;
        x.codclasse.selectedIndex=0;
        x.codformapg.selectedIndex=0;
        x.situacao.selectedIndex=0;
        x.valor.value='';
        x.vinculo.value='';
        x.comentario.value='';
    }
 
    function limpa_filtros_financeiro(){
        frm.opcoesdatas.selectedIndex = 6;
        frm.de.value='';
        frm.ate.value='';
        frm.tipodata[0].checked = true;
        frm.situacao.selectedIndex = 2;
        frm.tipo.selectedIndex = 2;
        frm.termo.value = '';
        frm.valor.value = '';
    }
 
    function seleciona_data(indice,de,ate){
   
        var dt  = new Date();
        var dia = dt.getDate();
        var mes = (dt.getMonth()+1);
        var ano = dt.getFullYear();
        
        if (dia < 10) dia = '0'+dia;
        if (mes < 10) mes = '0'+mes;
        
        
        switch (indice) {
        
            //Mês corrente
            case 0: frm.de.value  = "01/"+mes+"/"+ano;
                     frm.ate.value = MaxDiaMes(mes,ano)+"/"+mes+"/"+ano;
                     break

            //Ano corrente
            case 1: frm.de.value  = "01/01/"+ano;
                     frm.ate.value = "31/12/"+ano;
                     break
            
            //Último mês
            case 2: 
                    if (parseInt(mes) == 1) { 
                      mes = 12; 
                      ano--; 
                    } else mes = mes-1;
                    
                    if (dia < 10) dia = '0'+dia;
                    if (mes < 10) mes = '0'+mes;
                    
                     frm.de.value  = "01/"+mes+"/"+ano;
                     frm.ate.value = MaxDiaMes(mes,ano)+"/"+mes+"/"+ano;
                     break
        
            //Último ano
            case 3: frm.de.value  = "01/01/"+(ano-1);
                     frm.ate.value = "31/12/"+(ano-1);
                     break
                     
            //Até Hoje
            case 4: frm.de.value  = "01/01/"+ano;
                     frm.ate.value = dia+"/"+mes+"/"+ano;
                     break

            //Hoje
            case 5: frm.de.value  = dia+"/"+mes+"/"+ano;
                     frm.ate.value = dia+"/"+mes+"/"+ano;
                     break
                     
            //Escolher data
            case 6: frm.de.value='';
                     frm.ate.value='';
                     frm.de.focus();
                     break
        }
    }
 
    
    function valida_financeiro(x){
        
        if (x.codconta.selectedIndex == 0) {
            alert('Selecione a conta deste lançamento.');
            x.codconta.focus();
            return false;
        }

        if (!isDate(x.dataregistro__data.value)) {
            alert('Verifique a data de registro deste lançamento.');
            x.dataregistro__data.focus();
            return false;
        }
        
        if (!isDate(x.dataentrada__data.value)) {
            alert('Verifique a data de entrada deste lançamento.');
            x.dataentrada__data.focus();
            return false;
        }
        
        if (x.descricao.value == '') {
            alert('Preencha a descrição deste lançamento.');
            x.descricao.focus();
            return false;
        }

        if (x.codformapg.selectedIndex == 0) {
            alert('Selecione a forma de pagamento deste lançamento.');
            x.codformapg.focus();
            return false;
        }

        if (x.codclasse.selectedIndex == 0) {
            alert('Selecione a classe deste lançamento.');
            x.codclasse.focus();
            return false;
        }

        if (x.valor.value == '')  {
            alert('VALOR DO LANÇAMENTO INVÁLIDO !\n'+
                  '======================\n\n' +             
                  'Preencha corretamente o valor deste lançamento.');
            x.valor.focus();
            return false;
        }
    
        if (parseInt(x._ncampos.value) > 0)
          alert("Atenção\n" +
                "=====\n\n" +
                'Você adicionou desdobramentos financeiros.\nÉ necessário preencher todos os campos dos desdobramentos, do contrário eles não serão salvos no sistema.');
        
        return confirma();
        
    }

    function valida_memoria(x) {

        if (x.data__data.value == '') {
            alert('Preencha a data deste registro.');
            x.data__data.focus();
            return false;
        }

        if (x.tipocontato.value == '') {
            alert('Por favor especifique um tipo de contato. Selecione clicando no respectivo ícone ou digite no campo Tipo Contato.');
            x.tipocontato.focus();
            return false;
        }

        if (x.assunto.value.length < 5) {
            alert('Preencha o Assunto deste registro.');
            x.assunto.focus();
            return false;
        }
   
        if (x.responsavel.selectedIndex == -1) {
            alert('Selecione o Coordenador(a) responsável por este registro. Caso não tenha nenhum coordenador disponível será necessário criar um coordenar de grupo para realizar este procedimento.');
            x.responsavel.focus();
            return false;
        }
            
        return confirma();
    }
 
    function ler(codigo,pagina){
        w = 550; h = 450;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-50;
        window.open(pagina +'?codigo='+codigo,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
    
    
    function excluir_registro(pagina,codigo) {
        if (confirm("Tem certeza de que deseja excluir permanentemente este registro?")) {
            window.location.href = pagina+'?codigo='+codigo+'&excluir=1';
        }
    }
    
    function calendario(campo){
        w = 350; h = 300;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-50;
        window.open('mostra_calendario.php?campo='+campo,'','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
 
    function agenda_telefonica(){
        w = 580; h = 450;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-50;
        window.open('agenda_tel.php','','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }

    function abre_listas(campo,codigo){
        w = 330; h = 450;
        x = ((screen.width - w)/2)+130;
        y = ((screen.height - h)/2)-50;
        window.open('listas.php?campo='+campo+'&codigo='+codigo,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
 
    function fechar() {
        window.parent.close();
    }

    function imprimir() {
        window.parent.print();
    }

    function verifica_login(x) {
        if (x.dominio.value == '') {
            alert('Para acessar sua conta é necessário acessar seu domínio.');
            x.login.focus();
            return false;
        }

        if (x.login.value.length < 2) {
            alert('Digite seu login para ter acesso!');
            x.login.focus();
            return false;
        }

        if (x.senha.value.length < 5) {
            alert('Verifique sua senha de acesso!');
            x.senha.focus();
            return false;
        } 

        return true;
    }


    function sair(dominio) {
        if (confirm ('Deseja finalizar o sistema e encerrar esta seção ?'))
            location.href = 'http://www.solpoliticos.com.br/'+ dominio;
    }

    function limpa_formulario(formulario) {
        if (confirm ('Deseja limpar todos os campos ?')) {
            document.forms[formulario].reset();
        }
    }

    function mudacor(jsThis,jsColor) {
        if ((window.document.all) || (window.document.getElementById))
            jsThis.style.backgroundColor = jsColor;
        else 
            if (window.document.layers)
                jsThis.bgColor = jsColor;
    }

    function valida_cadastro(x) {

        if ((x.nome.value.length < 5) && (x.apelido.value.length < 5)) {
            alert('Preencha o Nome completo ou Apelido deste contato.');
            x.nome.focus();
            return false;
        }
      
        if ((x.datanasc.value != '') && (x.datanasc.value.length != 10)){
            alert('Preencha corretamente a Data de Nascimento. Ex.: dd/MM/aaaa');
            x.datanasc.focus();
            return false;        
        }
        
        return confirma();
    }

    function valida_cadastro2(x) {

        if ((x.nome.value.length < 5) && (x.apelido.value.length < 5)) {
            alert('Preencha o Nome completo ou Apelido deste contato na guia Dados Pessoais.');
            x.nome.focus();
            return false;
        }
      
        if (x.codcidade.options[x.codcidade.selectedIndex].value <= 0) {
            alert('Selecione o Estado e a Cidade deste contato na guia Dados Pessoais.');
            
            if (x.codestado.options[x.codestado.selectedIndex].value <= 0)
              x.codestado.focus();
            else
              x.codcidade.focus();
              
            return false;
        }
        
        if ((x.datanascimento__data.value != '') && (x.datanascimento__data.value.length != 10)){
            alert('Preencha corretamente a Data de Nascimento na guia Dados Pessoais. Ex.: dd/MM/aaaa');
            x.datanascimento__data.focus();
            return false;        
        }
        
        return confirma();
    }

    function refresh() {
        var url = unescape(window.top.location.href);
        window.location.href = url;
    }

    function EnableChecks(form_name, check_name, todos_name) {
      var i, j, len;
      len=document.forms[form_name].elements.length;
      
       j = 0; 
       for(i = 0; i < len; i++) {

         if (document.forms[form_name].elements[i].name == check_name+(j)) { 
           j++;

           if (document.forms[form_name].elements[todos_name].checked == true) {
              document.forms[form_name].elements[i].checked = true;
              document.forms[form_name].elements['marcatodos'].checked = true;
              document.forms[form_name].elements['marcatodos1'].checked = true;
                if (j==2) {frmLista.n_itens_selecionados.value = 0;}
                conta_itens_selecionados(document.forms[form_name].elements[todos_name]); 
           } else {
              document.forms[form_name].elements[i].checked = false;
              document.forms[form_name].elements['marcatodos'].checked = false;
              document.forms[form_name].elements['marcatodos1'].checked = false;
                conta_itens_selecionados(document.forms[form_name].elements[todos_name]);
                frmLista.n_itens_selecionados.value = 0;
           }
         }
       }  
    } 

    function marca_desmarcaRB(form_name, todos) {
        var i, j, len;
        len=document.forms[form_name].elements.length;
         
        for(i=0; i < len; i++)
            for(j=0; j < len; j++)
                if (document.forms[form_name].elements[i].name == '_a'+(j)) {
                    document.forms[form_name].elements[i].checked = document.forms[form_name].elements[todos].checked;
                    break;
                }
    };


    function valida_mensagem(x) {
        
        if (x.titulomsg.value == '') {
            alert('Para o envio desta mensagem é necessário escrever um assunto.');
            x.titulomsg.focus();
            return false;
        }

        if (x.descricaomsg.value.length == 0) {
            alert('Por favor descreva sua mensagem.');
            x.descricaomsg.focus();
            return false;
        }

        var destinatarios = document.getElementById('destinatarios');
        
        if (x.destinatarios.selectedIndex < 0) {
            alert('Por favor selecione o(s) destinatário(s) para esta mensagem.\nSe necessário selecione mais de um destinatário pressionando CTRL + clique sobre os nomes desejados.');
            x.destinatarios.focus();
            return false
        } else
        
        return confirma();
    }
  
    function valida_mensagemtw(x) {
        
        if (x.mensagem.value == '') {
            alert('Por favor digite sua mensagem.');
            x.mensagem.focus();
            return false;
        }
        
        if (x.mensagem.value.length > 140) {
            alert('Sua mensagem não pode ter mais de 140 caracteres.');
            x.mensagem.focus();
            return false;
        }
        else
        
        return confirma();
    }

    function valida_usuario(x) {

        if (x.loginusuario.value.length < 5) {
            alert('O login do usuário deve ter no mínio 2 caracteres!');
            x.loginusuario.focus();
            return false;
        }
        
        if (x.nomeusuario.value.length < 2) {
            alert('Por favor confira o nome do usuário!\nDeve ter no mínimo 5 caractéres.');
            x.nomeusuario.focus();
            return false;
        }

        if (x.senhausuario.value.length < 5) {
            alert('Por favor digite a senha do usuário. A mesma deve conter no mínimo 5 caracteres!');
            x.senhausuario.focus();
            return false;
        }

        if (x._senhausuario1.value != x.senhausuario.value) {
            alert('Por favor confira a senha e sua confirmação!');
            x._senhausuario1.value ='';
            x.senhausuario.focus();
            return false;
        }
   
        if (!isEmail(x.emailusuario.value)) {
            alert('Por favor confira o e-mail do usuário!');
            x.emailusuario.focus();
            return false;
        }

        if (x.horainicio.value.length != 5) {
          alert('Por favor verifique a hora de início. Se necessário preencha com 00:00.');
          x.horainicio.focus();
          return false;
        }
     
        if (x.horafim.value.length != 5) {
          alert('Por favor verifique a hora final. Se necessário preencha com 00:00.');
          x.horafim.focus();
          return false;
        }
        
        if (!valida_horario(x.horainicio.value)) {
            alert('A hora de início permitida é de 00:00 às 23:59. Por favor verifique a hora de início.');
            x.horainicio.focus();
            return false;
        }
        
        if (!valida_horario(x.horafim.value)) {
            alert('A hora final permitida é de 00:00 às 23:59. Por favor verifique a hora final.');
            x.horafim.focus();
            return false;
        }
        
        var h1 = parseInt(x.horainicio.value.replace(':',''),10);
        var h2 = parseInt(x.horafim.value.replace(':',''),10);
        
        if ((h1 >= h2) && (h1 != 0)) {
          alert('O horário final deve ser superior ao horário inicial. Por favor verifique os horários. ')
          x.horafim.focus();
          return false;
        }
        
        return confirma();
    }

    function verifica_alterarsenha(x) {

        if (x.senhaatual.value.length < 5) {
            alert('Por favor digite a senha atual. A mesma deve conter no mínimo 5 caracteres!');
            x.senhaatual.focus();
            return false;
        }
        
        if (x.novasenha.value.length < 5) {
            alert('Por favor digite a nova senha. A mesma deve conter no mínimo 5 caracteres!');
            x.novasenha.focus();
            return false;
        }
        
        if (x.senhaatual.value == x.novasenha.value) {
            alert('A nova senha não pode ser igual a senha atual. Por favor digite outra senha!');
            x.novasenha.value ='';
            x.novasenha.focus();
            return false;
        }
        
        if (x.novasenha1.value != x.novasenha.value) {
            alert('Por favor confira a nova senha e sua confirmação!');
            x.novasenha1.value ='';
            x.novasenha.focus();
            return false;
        }
        
        return confirma();
    }

    
    function valida_atividade(x) {

        if (x.nomeatv.value == '') {
            alert('Digite um nome para a atividade.');
            x.nomeatv.focus();
            return false;
        }

        if (x.descricaoatv.value.length < 1) {
            alert('Por favor descreva a atividade.');
            x.descricaoatv.focus();
            return false;
        }

        var destinatarios = document.getElementById('destinatarios');
        
        if (destinatarios.selectedIndex < 0) {
            alert('Por favor selecione o(s) destinatário(s) para esta atividade.\n\nSe necessário selecione mais de um destinatário/coordenador clicando e arrastando o mouse. Caso não haja nenhum destinatário será necessário criar os coordenadores de grupos.');
            destinatarios.focus();
            return false
        } else
          
        return confirma();
    }

    
    function limpa_usuarios(x) {
        x.nomeusuario.value  ='';
        x.loginusuario.value ='';
        x.senhausuario.value ='';
        x.senhausuario1.value='';
        x.emailusuario.value ='';
        marca_desmarcaRB('frm','_a');
    }


    function valida_agenda(x) {
        
        if (!isDate(x.datarealizacao__data.value)) {
            alert('Digite corretamente a data de realização do agendamento.');
            x.datarealizacao__data.focus();
            return false;
        }
        
        if ((x.horarealizacao.value.length != 5) || !valida_horario(x.horarealizacao.value) ) {
            alert('Digite corretamente a hora de realização do agendamento.');
            x.horarealizacao.focus();
            return false;
        }
        
        if (x.descricaoagenda.value.length < 1) {
            alert('Por favor descreva o agendamento.');
            x.descricaoagenda.focus();
            return false;
        } else
        
        return confirma();
    }

    function valida_horario(horario) {
      var hora   = parseInt(horario.substr(0,2));
      var minuto = parseInt(horario.substr(3,2));
      return !(hora < 0 || hora > 23 || minuto < 0 || minuto > 59);
    }
    
    function limpa_agenda(x){
        x.datarealizacao__data.value = '';
        x.horarealizacao.value       = '';
        x.tipo.selectedIndex         = 0;
        x.descricaoagenda.value      ='';
    }

    function limpa_filtros_contatos(x){
        document.forms[x].codigo.value = '';
        document.forms[x].parte.selectedIndex = 0;
        document.forms[x].nome.value = '';
        md_item(document.forms[x].cidades);
        document.forms[x].logradouro.selectedIndex = 0;
        document.forms[x].endereco.value = '';
        document.forms[x].numero.value = '';
        document.forms[x].complemento.value = '';
        document.forms[x].ordenacao.selectedIndex = 2;
        document.forms[x].filiadopartido.checked = false;
        document.forms[x].coordenador.selectedIndex = 0;
    }

    function separa_itens(x) {
        a = x.substring(0,x.indexOf("#"));
        b = x.substring(x.indexOf("#")+1,x.indexOf("$"));
        c = x.substring(x.indexOf("$")+1,x.length);
        navegacao(a,b,c);
    }

    function md_item(x){
        x.selectedIndex = -1;
    }

    function conta_itens_selecionados(x) {
        var aux = eval(frmLista.n_itens_selecionados.value);

        if (x.checked)
            aux = aux + 1;
        else aux = aux - 1;
    
        frmLista.n_itens_selecionados.value = aux;
    }

    function envia_contatos(x) {
        if (frmLista.n_itens_selecionados.value > 0) {
     
            if (x==1) {
                str = 'Este procedimento irá associar o(s) contato(s) selecionado(s) ao coordenardor(a)\n'+frmLista.grupo.options[frmLista.grupo.selectedIndex].text+'.\n\nTem certeza de que deseja continuar?';
            } else 
                if(x==2) {
                    str = "Cornfirmação de Exclusão\n"+
                          "================\n\n"+
                          "Este procedimento irá EXCLUIR este contato e TODOS seus vínculos tais como: Memória Política, Coordenadores, Atividades e etc.\n\n"+
                          "Este processo é irreversível. Deseja realmente excluir este contato ?";
                };
   
            if (confirm(str)) {
              document.frmLista.operacao.value = x;  
              document.frmLista.submit();  
            }

        } else
           alert('Para realizar esta operação é necessário selecionar algum contato!')
    }

    function ler_contato(codcontato){
        w = 560; h = 430;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-30;
        window.open('con_ler.php?codcontato='+codcontato,'','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
    }
 
    function desvincula_contato(objeto,codcontato,codgrupo){
        w = 200; h = 95;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-30;

        if (confirm('Deseja realmente desvincular este contato do grupo?')) {
            window.open('con_desvincular.php?codcontato='+codcontato+'&codgrupo='+codgrupo,'','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
            objeto.style.visibility = 'hidden';
        }
    }
 
    function desvincula_cidade(objeto,codcidade,nomecidade){
        w = 200; h = 95;
        x = (screen.width - w)/2;
        y = ((screen.height - h)/2)-30;

        if (confirm('Deseja realmente retirar a cidade ['+nomecidade+'] de sua lista de cidades disponíveis?')) {
            window.open('cid_desvincular.php?operacao=-1&codcidade='+codcidade,'','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
            objeto.style.visibility = 'hidden';
        }
    }
 
    function valida_cidade(x) {
        if (x.nomescidades.value.length < 2) {
            alert('Por favor especifique melhor sua busca e tente novamente.');
            x.nomescidades.focus();
            return false;
        } else
            return true;
    }
     
    function valida_preferencias(x) {
     
       if ((x.nomeadmtec != null) && (x.nomeadmtec.value.length < 5)) {
         alert('Por favor confira o nome do administrador técnico do sistema!\nDeve ter no mínimo 5 caractéres.');
         x.nomeadmtec.focus();
         return false;
       }

       if ((x.emailadmtec != null) && !isEmail(x.emailadmtec.value)) {
         alert('Por favor confira o e-mail do administrador técnico do sistema!');
         x.emailadmtec.focus();
         return false;
       }
        
       return confirma();
      
     }
     
     function valida_grupos(x) {
     
       if (x.meta.value <= 0) {
         alert('Por favor confira a meta deste coordenador. Deve ter um número maior que zero contatos.');
         x.meta.focus();
         return false;
       }
       return confirma()
     }
 
     function vincula_cidade(objeto,codcidade,nomecidade){
       w = 200; h = 95;
       x = (screen.width - w)/2;
       y = ((screen.height - h)/2)-30;

       if (confirm('Deseja realmente incluir a cidade ['+nomecidade+'] à sua lista de cidades disponíveis?')) {
           window.open('cid_desvincular.php?operacao=1&codcidade='+codcidade,'','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+y+',left='+x);
           objeto.style.visibility = 'hidden';
       }
     }
     
     function alerta_acesso(){
       alert('ACESSO NEGADO !\n\nVocê não tem acesso à esta opção. Caso necessário contate o administrador do sistema.');
     }
     
     function muda_cor(x){
        if (x.style.color == 'white')
         x.style.color='black'
        else x.style.color='white';
     }
     
      function ajuda(tema){
       w = 420; h = 490;
       x = ((screen.width - w)/2) + 120;
       y = ((screen.height - h)/2)-40;
       window.open('ajuda/index.php?tema='+tema,'','toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width='+w+',height='+h+',top='+y+',left='+x);
     }
     
     function valida_lembrar_senha(f) {
       
       if (f.dominio.value == '') {
         alert('Para utilizar o Lembrar senha é necessário acessá-lo através de seu domínio.');
         return false;
       } else return true;
       
     }
     
     function maximizar_janela(){
       top.moveTo(0,0);
       top.resizeTo(screen.width,(screen.height-50));
     }
     
     //função retorna dia máximo do mês solicitado
    function MaxDiaMes(mes,ano) {
        if (mes == "" || isNaN(mes) == true || mes > 12 || mes < 1 || ano == "" || isNaN(ano) == true) {
            return false
        } else {
            //anos com final 0-4-8-2-6, bissextos
            //ou divisiveis por 4
            var Meses = new Array(12)
            Meses[1] = 31
            if (ano % 4 == 0) {
                Meses[2] = 29
            } else {
                Meses[2] = 28
            }
            Meses[3] = 31
            Meses[4] = 30
            Meses[5] = 31
            Meses[6] = 30
            Meses[7] = 31
            Meses[8] = 31
            Meses[9] = 30
            Meses[10] = 31
            Meses[11] = 30
            Meses[12] = 31
            return Meses[parseInt(mes)]
        }
    }

    //returna a data atual formatada para padrão brasileiro
    function dataAgora(){
        var dt = new Date();
        return formatData(dt.getDate()+"/"+(dt.getMonth()+1)+"/"+dt.getFullYear());
    }
    //retorna a hora atual formatada
    function hotaAgora(){
        var dt = new Date();
        return dt.getHours()+":"+dt.getMinutes();
    }


    //função para formatar data
    function formatData(valor) {
        if (!isDateAux(valor) == false) {
            return false
        } else {
            var priB = valor.indexOf("/");
            var secB = valor.indexOf("/",priB+1);
            var dia = valor.substring(0,priB);
            var mes = valor.substring(priB+1,secB);
            var ano = valor.substring(secB+1);
            dia = "0" + dia;
            mes = "0" + mes;
            if (dia.length > 2) {
                dia = dia.substring(dia.length - 2, dia.length);
            }
            if (mes.length > 2) {
                mes = mes.substring(mes.length - 2, mes.length);
            }
            ano = parseInt(ano);
            ano = ano + "";
            if (ano.length < 4) {
                ano = parseInt(ano)
                if (ano < 29) {
                    ano = ano + 2000;
                } else {
                    ano = ano + 1900;
                }
            }
            return dia + "/" + mes + "/" + ano;
        }
    }


    function verifica_conta(x){

      if (x.nomeconta.value.length < 2) {
        alert('Preencha corretamente o campo conta.');
        x.nomeconta.focus();
        return false;
      }
      
      return confirma;
    }

    function limpa_conta(x){
      x.nomeconta.value = '';
      x.agencia.value = '';
      x.numero.value = '';
    } ;
  
    function verifica_classe(x){

      if (x.nomeclasse.value.length < 3) {
        alert('Preencha corretamente o campo classe.');
        x.nomeclasse.focus();
        return false;
      }
      
      return confirma();
    }

    function limpa_classe(x){
      x.nomeclasse.value = '';
    }
  
    function verifica_formaspg(x){

      if (x.formapg.value.length <= 4) {
        alert('Preencha corretamente o campo forma.');
        x.formapg.focus();
        return false;
      }

      if (x.abreviacao.value.length == '') {
        alert('Preencha corretamente o campo abreviação.');
        x.abreviacao.focus();
        return false;
      }
      
      return confirma();
    }

    function limpa_formaspg(x){
      x.formapg.value = '';
      x.abreviacao.value = '';
    }  

    function verifica_tipofiliado(x) {
      var tipof = document.getElementById('tipofiliado');
      if (tipof != null)
        tipof.disabled = (x.selectedIndex != 1)
    }
    
    function valida_conta(x){

      if (x.nomeconta.value.length < 2) {
        alert('Preencha corretamente o campo conta.');
        x.nomeconta.focus();
        return false;
      }
      else
        return confirma();
    }

    function limpa_conta(x){
      x.nomeconta.value = '';
      x.agencia.value = '';
      x.numero.value = '';
    } ;
  
    function valida_classe(x){

      if (x.nomeclasse.value.length < 3) {
        alert('Preencha corretamente o campo classe.');
        x.nomeclasse.focus();
        return false;
      } else
        return confirma();
    }

    function limpa_classe(x){
      x.nomeclasse.value = '';
    }
  
    function valida_formaspg(x){

      if (x.formapg.value.length <= 4) {
        alert('Preencha corretamente o campo forma.');
        x.formapg.focus();
        return false;
      }

      if (x.abreviacao.value.length == '') {
        alert('Preencha corretamente o campo abreviação.');
        x.abreviacao.focus();
        return false;
      } else
        return confirma();
    }

    function limpa_formaspg(x){
      x.formapg.value = '';
      x.abreviacao.value = '';
    }