function formata(objeto, mask, evt) {
 
var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var Numeros = '0123456789';
var Fixos  = '().-:/ ';
var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

evt = (evt) ? evt : (window.event) ? window.event : "";
var value = objeto.value;
if (evt) {
 var ntecla = (evt.which) ? evt.which : evt.keyCode;
  tecla = Charset.substr(ntecla - 32, 1);
 if (ntecla < 32) return true;

 var tamanho = value.length;
 if (tamanho >= mask.length) return false;

 var pos = mask.substr(tamanho,1);
 while (Fixos.indexOf(pos) != -1) {
  value += pos;
  tamanho = value.length;
  if (tamanho >= mask.length) return false;
  pos = mask.substr(tamanho,1);
 }

 switch (pos) {
   case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   case '*' : objeto.value = value; return true; break;
   default : return false; break;
 }
}
objeto.value = value;
return true;
}


 function verificarCPF(c){
var i; 
s = c;
var c = s.substr(0,9); 
var dv = s.substr(9,2); 
var d1 = 0; 
var v = false;
for (i = 0; i < 9; i++) 
{ 
d1 += c.charAt(i)*(10-i); 
} 
if (d1 == 0){ 
alert("Número do documento  Inválido");
document.getElementById("cpf").focus();
v = true; 
return false; 
} 
d1 = 11 - (d1 % 11); 
if (d1 > 9) d1 = 0; 
if (dv.charAt(0) != d1) 
{ 
alert("Número do documento  Inválido");
document.getElementById("cpf").focus();
v = true;
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) 
{ 
alert("Número do documento  Inválido");
document.getElementById("cpf").focus();
v = true;
return false; 
} 
/*if (!v) {
alert(c + "\nCPF Válido") 
}*/
}

function valida_cnpj(cnpj) {
  var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
  digitos_iguais = 1;
  if (cnpj.length < 14 && cnpj.length < 15) {
    alert("Número do documento Inválido")
    document.formCadastro.cnpj.focus();
    return false;
  }
  for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
	      {
	      digitos_iguais = 0;
	      break;
	      }
  if (!digitos_iguais)
        {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0)) {
          	alert("Número do documento Inválido")
		    document.formCadastro.cnpj.focus();
		    return false;
        }
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1)) {
          	alert("Número do documento Inválido")
		    document.formCadastro.cnpj.focus();
		    return false;
        }
        return true;
        }
  else
        return false;
  } 

function validaSenha(senha) {
	x = senha.length;
	if (x < 6) {
		alert("A senha deve ter no mínimo 6 caracteres");
		document.getElementById("senha").focus();
		return false;
	}
}

function deletar(table,id) {
	if (confirm("Deseja mesmo apagar o registro "+id+" do cadastro de "+table+" ?")) {
		location.href="?id="+id+"&op=deletar&table="+table;				
	}
}

function busca(table) {

    document.getElementById('novabusca').style.display = "block";

}

function fechar() {
    document.getElementById('novabusca').style.display = "none";

}

function cadastra(cad1, cad2) {

    window.open("janela.php?table="+cad1,"cadastros","width=900px,height=500px,scrolling=1");

}

function abre(video) {
    window.open("video.php?codigo="+video,"videos","width=400px,height=500px");
}

