function Fechar(){
 parent.window.close();
}

function Editar(url,id){
 alert(url);
 location=url+id;
}

function BuscaUsuario(codigo,nome,url,tipo,template,idioma){
  if(tipo==0){
   if(codigo=="" && nome==""){
    alert('Preencha código ou nome para realizar a busca!');
   }else{
    if(nome!=""){
     location=url+"&opcao=Nome&valor="+nome;
    }
    if(codigo!=""){
     location=url+"&usuario_i_codigo="+codigo;
    }
   }
  }else if(tipo==1){
   abre("usuario02.php?template="+template+"&idioma="+idioma,"usuario",50,50,400,450,"yes");
  }
}

function cent(amount){
 //retorna o valor com 2 casas decimais
 return(amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function dec(cantidad, decimales){
 //arredonda o valor
 var cantidad = parseFloat(cantidad);
 var decimales = parseFloat(decimales);
 decimales = (!decimales ? 2 : decimales);
 return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
}

function Usuario(codigo,nome){
 opener.form.usuario_i_codigo.value = codigo;
 opener.form.usuario_c_nome.value = nome;
 window.close();
}

function BuscaCadastro(nome,url){
 if(nome==""){
  alert('Preencha o nome para realizar a busca!');
 }else{
  location=url+"&Nome="+nome;
 }
}

function abre(pagina,nome,topo,left,largura,altura,scrool){
 window.open(pagina,nome,'top='+topo+',left='+left+',width='+largura+',height='+altura+',toolbar=no,menubar=no,resizable=no,scrollbars='+scrool);
}

function popup(caminho,nome,largura,altura,rolagem){
 var esquerda = (screen.width - largura) / 2;
 var cima = (screen.height - altura) / 2 -50;
 window.open(caminho,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + rolagem + ',resizable=no,copyhistory=no,top=' + cima + ',left=' + esquerda + ',width=' + largura + ',height=' + altura);
}

function MarcaTudo(linhas){
 for(i=1;i<=linhas;i++){
  if(document.form.tudo.value == " M "){
   document.form[i].checked = true;
   valor = " D ";
  }
  if(document.form.tudo.value == " D "){
   document.form[i].checked = false;
   valor = " M ";
  }
 }
 document.form.tudo.value = valor;
}

function SalvarPermissao(linhas,url){
 var acumula = "";
 for(i=1;i<=linhas;i++){
  if(document.form[i].checked==true){
   acumula += document.form[i].value+"|";
  }
 }
 location = url+"&p="+acumula;
}

function Calendario(dia,name1,mes,name2,ano,name3,nomecampo){
 opener.document.getElementById(name1).value=dia;
 opener.document.getElementById(name2).value=mes;
 opener.document.getElementById(name3).value=ano;
 opener.document.getElementById(nomecampo).value=dia+"/"+mes+"/"+ano;
 window.close();
}

function EscolheArquivo(file,retorno){
 opener.document.getElementById(retorno).value=file;
 window.close();
}

function ApagaArquivo(file,dir,retorno){
 if(confirm("Confirmar exclusão do Arquivo?")){
  location="files.php?dir="+dir+"&retorno="+retorno+"&del="+file;
 }
}

function ApagaDown(url){
 if(confirm("Confirmar exclusão do Arquivo?")){
  location=url;
 }
}

function EscolheIcone(file,campo,nomeform){
 opener.document.getElementById(campo).value=file;
 window.close();
}

function EscolheBanner(file){
 opener.form.banner_c_arquivo.value = file;
 window.close();
}

function desabilitar(campo){
 for(i=0;i<4;i++){
  if(campo.name!=document.form[i].name){
   document.form[i].style.background = "#cccccc";
   document.form[i].disabled = true;
  }
 }
}

function limpar_form(){
 elementos = document.form.elements.length-3;
 for(i=0;i<elementos;i++){
  document.form[i].disabled = false;
  document.form[i].style.background = "#ffffff";
  document.form[i].value = "";
 }
 document.form[0].focus();
}

function ImagemFrame(nro,usu,tpl,idioma){
 if(nro==1){
  frame_imagem.location.href = "imagem10.php?usu="+usu+"&TEMPLATE="+tpl+"&IDIOMA="+idioma;
  document.form.button1.disabled = true;
  document.form.button2.disabled = false;
  document.form.button3.disabled = false;
  document.form.button4.disabled = false;
  return true;
 }
 else if(nro==2){
  frame_imagem.location.href = "imagem20.php?usu="+usu+"&TEMPLATE="+tpl+"&IDIOMA="+idioma;
  document.form.button1.disabled = false;
  document.form.button2.disabled = true;
  document.form.button3.disabled = false;
  document.form.button4.disabled = false;
  return true;
 }
 else if(nro==3){
  frame_imagem.location.href = "imagem30.php?usu="+usu+"&TEMPLATE="+tpl+"&IDIOMA="+idioma;
  document.form.button1.disabled = false;
  document.form.button2.disabled = false;
  document.form.button3.disabled = true;
  document.form.button4.disabled = false;
  return true;
 }
 else if(nro==4){
  frame_imagem.location.href = "imagem40.php?usu="+usu+"&TEMPLATE="+tpl+"&IDIOMA="+idioma;
  document.form.button1.disabled = false;
  document.form.button2.disabled = false;
  document.form.button3.disabled = false;
  document.form.button4.disabled = true;
  return true;
 }
 else
  return false;
}

function ConfirmDel(url,msg){
 if(confirm(msg)){
  location=url;
  return true;
 }
}

function MostraMini(url){
 parent.frame_mini.location.href=url;
}

function MostraMax(url,altura,largura){
 abre(url,'Maximizar',0,0,altura,largura,'no');
}

function FotosConteudo(imagem,oid){
 frame_foto.location.href="miniatura.php?image="+imagem+"&image_oid="+oid+"&altura=150&largura=150";
}

function Adicionar(){
 if(parent.frame_mini.form1==null){
  alert('Selecione um diretório!');
 }else{
  var codigos = "";
  for (i=0;i<parent.frame_mini.form1.elements.length;i++){
   if(parent.frame_mini.form1[i].checked==true){
    codigos += parent.frame_mini.form1[i].value+"|";
   }
  }
  if(codigos==""){
   alert('Selecione alguma imagem para enviar');
  }else{
   parent.opener.form.imagens_conteudo.value = codigos;
   parent.window.close();
  }
 }
}

function DirColor(dir,cor1,cor2){
 cor = dir.bgColor;
}

function MarcaTudoInner(linhas,texto1,texto2){
 var fim = "";
 for(i=0;i<linhas;i++){
  if(document.getElementById('inner').innerHTML==texto1){
   document.form1.marca[i].checked=true;
   fim = texto2;
  }
  if(document.getElementById('inner').innerHTML==texto2){
   document.form1.marca[i].checked=false;
   fim = texto1;
  }
 }
 document.getElementById('inner').innerHTML = fim;
}

function ApagarImgConteudo(conteudo,url){
 location = url+"&apagar";
}

function Escolha(valor,url){
 location = url+"&escolha="+valor;
}

function Anuncie(url){
 location = url;
}

function Maximiza(){
 windowWidth = window.screen.availWidth; windowHeight = window.screen.availHeight;
 window.moveTo(0,0);
 window.resizeTo(windowWidth,windowHeight);
}

function makevisible(cur,which){
 cur.filters.alpha.opacity=which
}

function Conteudo(codigo,x,loc){
 opener.location="index.php"+x+"&loc="+loc+"&edt="+codigo;
 window.close();
}

function soma(campo,campo2,limite) {
   var mais_um=eval(campo.value.length-1);
   mais_um++;
   if (campo.value.length>limite) {
      campo.value='';
      campo.value=valor_limite;
      alert("Limite de "+limite+" caracteres");
   }else{
        valor_limite=campo.value;
        campo2.value='';
          campo2.value=(limite-mais_um);
   }
   campo.focus();
}

function mostra_tamanho(){
   document.form.exibe2.value=limite;
}

function Album(url,nome,opcao){
 if(nome==""){
  alert("Preencha o nome para pesquisa!");
 }else{
  location=url+"&diretorio_c_nome="+nome+"&opcao="+opcao;
 }
}

function FormataValor(Campo){
 var vr = Campo.value;
 vr = vr.replace(",", ".");
 Campo.value = vr;
}

function LanceMinimo(valorminimo){
 valor = document.form.lance_f_valor.value;
 if(valor==0){
  alert("Valor em branco!");
  document.form.lance_f_valor.value = cent(dec(valorminimo,2));
  document.form.lance_f_valor.focus();
  return false;
 }
 if(valor<valorminimo){
  alert("Lance Mínimo de R$ "+cent(dec(valorminimo,2)));
  document.form.lance_f_valor.value = cent(dec(valorminimo,2));
  document.form.lance_f_valor.focus();
  return false;
 }
}

function Evento(mes,ano,template,idioma){
  document.calendario.location.href='calendario01.php?M='+mes+'&A='+ano;
  document.eventos.location.href='evento02.php?template='+template+'&idioma='+idioma+'&M='+mes+'&A='+ano;
}

function mascara_hora(hora,x)
 {
   var myhora = '';
   myhora = myhora + hora;
   if (myhora.length == 2)
   {
    myhora = myhora + ':';
    document.form[x].value = myhora;
   }
   if (myhora.length == 5)
   {
    verifica_hora(x);
   }
 }

function verifica_hora(x)
{
 hrs = (document.form[x].value.substring(0,2));
 min = (document.form[x].value.substring(3,5));
 situacao = "";
// verifica hora
 if ( (hrs < 00 ) || (hrs > 23) || ( min < 00) || ( min > 59) )
  {
   alert("E R R O !!!\n\nHora inválida!\nPreencha corretamente o campo!");
   document.form[x].value="";
   document.form[x].focus();
  }
}

////

function validar(Form,campo){
 var invalid, s;
 invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
 var s;
 // inicio de verificacao de cnpj ou cpf
 if (Form.campo.value.length == 0){
  alert("O CNPJ/CPF é um campo obrigatório !");
  Form.campo.focus();
  return false;
 }
 s = limpa_string(Form.campo.value);
 // checa se é cpf
 if (s.length == 11){
  if (valida_CPF(Form.cnpj.value) == false ){
   alert("O CPF não é válido !");
   Form.cnpj.focus();
   return false;
  }
 // checa se é cgc
 }else if (s.length == 14){
  if (valida_CGC(Form.cnpj.value) == false ) {
   alert("O CNPJ não é válido !");
   Form.cnpj.focus();
   return false;
  }
 }else{
  alert("O CPF/CNPJ não é válido !");
  Form.cnpj.focus();
  return false;
 }
 // final da verificacao de cnpj ou cpf
 // verifica o cep
 // primeiro deixa somente numeros no cep
 // obs.:a chamada abaixo tambem pode ser utilizada para checar telefones
 s = limpa_string(Form.cep.value);
 if (s.length < 8){
  alert("Digite corretamente o CEP: 99999-999 !");
  Form.cep.focus();
  return false;
 }
 // verifica se o email é válido
 if (Form.email.value.length == 0){
  alert("Digite corretamente seu E-mail por favor!");
  Form.email.focus();
  return false;
 }
 if (invalid.test(document.form.email.value) == false){
  // caso o teste falhe, para mudar a cor do texto na caixa, mude na linha abaixo
  document.form.email.style.color = "red";
  alert("Endereço de E-mail inválido !");
  Form.email.focus();
  return (false);
 }
 return true;
}
// fim da funcao validar()

function limpa_string(S){
 // Deixa so' os digitos no numero
 var Digitos = "0123456789";
 var temp = "";
 var digito = "";
 for(var i=0; i<S.length; i++){
  digito = S.charAt(i);
  if (Digitos.indexOf(digito)>=0){
   temp=temp+digito
  }
 }//for
 return temp
}
// fim da funcao

function valida_CPF(s){
 var i;
 s = limpa_string(s);
 var c = s.substr(0,9);
 var dv = s.substr(9,2);
 var d1 = 0;
 for(i = 0; i < 9; i++){
  d1 += c.charAt(i)*(10-i);
 }
 if (d1 == 0) return false;
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1){
  return false;
 }
 d1 *= 2;
 for (i = 0; i < 9; i++){
  d1 += c.charAt(i)*(11-i);
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1){
  return false;
 }
 return true;
}

function valida_CGC(s){
 var i;
 s = limpa_string(s);
 var c = s.substr(0,12);
 var dv = s.substr(12,2);
 var d1 = 0;
 for (i = 0; i < 12; i++){
  d1 += c.charAt(11-i)*(2+(i % 8));
 }
 if (d1 == 0) return false;
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(0) != d1){
  return false;
 }
 d1 *= 2;
 for (i = 0; i < 12; i++){
  d1 += c.charAt(11-i)*(2+((i+1) % 8));
 }
 d1 = 11 - (d1 % 11);
 if (d1 > 9) d1 = 0;
 if (dv.charAt(1) != d1){
  return false;
 }
 return true;
}

// validar(this)

function EmitirBoleto(linhas,tipo){
 if(tipo==1){
  MarcaTudo(linhas);
 }
 var soma = 0;
 var contador = 0;
 for(i=1;i<=linhas;i++){
  if(document.form[i].checked == true){
   soma += parseFloat(document.form[i].value);
   contador++;
  }
 }
 document.getElementById('total_pagar').value = soma.toFixed(2);
 document.getElementById('total_parcelas').value = contador;
}

function ImprimeBoleto(){
 var valor_total = parseFloat(document.getElementById('total_pagar').value);
 var vcto = document.getElementById('Ddia1').value+"-"+document.getElementById('Dmes1').value+"-"+document.getElementById('Dano1').value;
 var usuario = document.getElementById('id_usuario').value;
 var ref = document.getElementById('ref').value;
 var id_lanc = document.getElementById('id_lanc').value;
 var parcelas = document.getElementById('total_parcelas').value;
 if(parcelas==1){
  if(Number(valor_total)>0 && vcto!="--"){
   abre("boleto/boleto.php?valor="+valor_total+"&vcto="+vcto+"&usuario="+usuario+"&ref="+ref+"&id_lanc="+id_lanc,"boleto",50,100,660,540,"no");
  }else{
   alert("Erro!\n\nInforme Valor e Vcto. para emitir o Boleto.");
  }
 }else if(parcelas>1){
  abre("boleto/boleto.php?valor="+valor_total+"&vcto="+vcto+"&usuario="+usuario+"&ref="+ref+"&unica="+parcelas,"boleto",50,100,660,540,"no");
 }else{
  alert("Selecione uma parcela para emitir o Boleto!");
  return false;
 }
}

function NewWin(){
 var leftpos = (screen.availWidth - 200)-40;
 resiz = (navigator.appName=="Netscape") ? 0 : 1;
 window.open("http://www.icq.com/icq2go/flicq.html", "TOFI","width=164,height=446,top=40,left="+leftpos+",directories=no,location=no,menubar=no,scroll=no,status=no,titlebar=no,toolbar=no,resizable="+resiz+"");
}

function imprimir() {
document.getElementById('botao').style.visibility = 'hidden';
//document.focus();
window.print();
}

function SaveNews(formato,campo){
 if(formato=="Html"){
  //frame_editor.AtualizaPagina();
  document.getElementById('newsmsg_t_corpo').value = frame_editor.Composition.document.body.innerHTML;
  document.form[campo].disabled = false;
 }else{
  document.form[campo].disabled = false;
 }

}

function Visualizar(id){
 abre("news_preview.php?id="+id,"Visualizar",50,50,700,400,"yes");
}

function DownPerfil(codigo){
 if(codigo==7){
  document.getElementById("downusuario").style.visibility = "visible";
 }else{
  document.getElementById("downusuario").style.visibility = "hidden";
  document.form.download_i_usuario.value = "";
  document.form.usuario_c_nome.value = "";
 }
}

function BuscaUsuario(){
 abre("buscausuario.php","Usuário",50,100,600,400,"yes");
}

function Usuario(codigo,nome){
 opener.document.form.download_i_usuario.value = codigo;
 opener.document.form.usuario_c_nome.value = nome;
 window.close();
}

function Permissao(url,usuario){
 location = url+"&usuario_i_codigo="+usuario;
}
function js_setDiaMesAno(obj,dia,mes,ano,DIA,MES,ANO){
 document.getElementById(DIA).value = dia;
 document.getElementById(MES).value = mes;
 document.getElementById(ANO).value = ano;
}

function js_colocaBarras(obj,strValor,apagando,DIA,MES,ANO){
 var strRetorno      = '';
 var strNumDigitados = strValor.length;
 var strRetorno = '';
 if(!apagando){
  if(strNumDigitados >= 2 && strNumDigitados < 4){
   strRetorno = strValor.substr(0,2)+'/'+strValor.substr(2,strNumDigitados-1);
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,strNumDigitados-1),'',DIA,MES,ANO);
  }else if(strNumDigitados >= 4 && strNumDigitados < 8){
   var fev               = 29;
   var diaatual   = new Number(strValor.substr(0,2));
   var mesatual   = new Number(strValor.substr(2,2));
   mesatual--;
   var dia = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
   if(diaatual > dia[mesatual]) {
    strRetorno = dia[mesatual]+'/'+strValor.substr(2,2)+'/'+strValor.substr(4,strNumDigitados-1);
   }else {
    strRetorno = strValor.substr(0,2)+'/'+strValor.substr(2,2)+'/'+strValor.substr(4,strNumDigitados-1);
   }
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,2),strValor.substr(4,strNumDigitados-1),DIA,MES,ANO);
  }else if(strNumDigitados == 8){
   var diaatual = new Number(strValor.substr(0,2));
   var mesatual = new Number(strValor.substr(2,2));
   mesatual--;
   if (checkleapyear(strValor.substr(4,4))) {
    var fev        = 29;
   }else{
    var fev        = 28;
   }
   var dia = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
   var ano = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
   if(diaatual > dia[mesatual]) {
    strRetorno = dia[mesatual]+'/'+strValor.substr(2,2)+'/'+strValor.substr(4,4);
   }else {
    strRetorno = strValor.substr(0,2)+'/'+strValor.substr(2,2)+'/'+strValor.substr(4,4);
   }
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,2),strValor.substr(4,4),DIA,MES,ANO);
  }else{
   return strValor;
  }
  return strRetorno;
 }else{
  if(strNumDigitados <= 2){
   js_setDiaMesAno(obj,strValor.substr(0,strNumDigitados-1),'','',DIA,MES,ANO);
  }else if(strNumDigitados >= 2 && strNumDigitados < 4){
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,strNumDigitados-1),'',DIA,MES,ANO);
  }else if(strNumDigitados >= 4 && strNumDigitados < 8){
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,2),strValor.substr(4,strNumDigitados-1),DIA,MES,ANO);
  }else if(strNumDigitados == 8){
   js_setDiaMesAno(obj,strValor.substr(0,2),strValor.substr(2,2),strValor.substr(4,4),DIA,MES,ANO);
  }
  return '';
 }
}

function checkleapyear(datea){
  datea = parseInt(datea);
  if(datea%4 == 0){
    if(datea%100 != 0){
      return true;
    }else{
      if(datea%400 == 0){
        return true;
      }else{
        return false;
      }
    }
  }
  return false;
}
function js_validaDbData(obj) {
 var strValor = obj.value;
 if (strValor == '' || strValor == null){
  return false;
 }
 var Dia = strValor.substr(0,2);
 var Mes = strValor.substr(3,2);
 var Ano = strValor.substr(6,4);
 var data = new Date(Ano,(Mes-1),Dia);
 if (checkleapyear(Ano)) {
  var fev        = 29;
 }else{
  var fev        = 28;
 }
 var dia = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
 var diaexpr = new RegExp("[0-3][0-9]");
 if(Dia.match(diaexpr) == null || Dia > dia[Mes-1] || Dia == "00") {
  alert("Dia Inválido!");
  obj.value = '';
  obj.select();
  return false;
 }
 var mesexpr = new RegExp("[01][0-9]");
 if(Mes.match(mesexpr) == null ||  Mes > 12 || Mes == "00") {
  alert("Mes inválido");
  obj.value = '';
  obj.select();
  return false;
 }
 var anoexpr = new RegExp("[12][0-9][0-9][0-9]");
 if(Ano.match(anoexpr) == null) {
  alert("Ano inválido");
  obj.value = '';
  obj.select();
  return false;
 }
 return true;
}
function js_search_in_array(arr,valor){
  for(var ix=0; ix<arr.length; ix++){
    if(arr[ix] == valor){
      return true;
    }
  }
  return false;
}




function js_mascaraData(campo,evt,DIA,MES,ANO){
 //var strAux           = '';
 //var tecla            = evt.keyCode;
 var valor            = campo.value;
 //var exprLiterais     = new RegExp("[^0-9]+");
 //const teclasNaoFormatadas = new Array(8,13,35,36,37,38,39,40,45,46);
 valor  = valor.replace(".",""); // tira ponto "."
 valor  = valor.replace("-",""); // tira traco "-"
 valor  = valor.replace("/",""); //
 valor  = valor.replace("/","");
 valor  = valor.replace("/","");
 //if(tecla == 8 || tecla == 46 ){
 campo.value = js_colocaBarras(campo,valor,false,DIA,MES,ANO);
 return true;
 //}
 /*
 if (!js_search_in_array(teclasNaoFormatadas,tecla)){
  // tira os caracteres literais
  for(i=0; i < valor.length; i++){
   if(!valor[i].match(exprLiterais)){
    strAux += valor[i];
   }else{
    strAux = '';
   }
  }
  campo.value = js_colocaBarras(campo,strAux,false,DIA,MES,ANO);
  return true;
 }
 */
}
function js_bloqueiaSelecionar(obj){
 obj.selectionStart = null;
 obj.selectionEnd   = null;
 return false;
}
function js_validaEntrada(obj){
 return true;
}


