function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
     var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

     if(document.all) { // Internet Explorer
       nTecla = evtKeyPress.keyCode; }
     else if(document.layers) { // Nestcape
       nTecla = evtKeyPress.which;
     }

     sValue = objForm[strField].value;

     // Limpa todos os caracteres de formatação que
     // já estiverem no campo.
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( "-", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( ".", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "/", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( "(", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( ")", "" );
     sValue = sValue.toString().replace( " ", "" );
     sValue = sValue.toString().replace( " ", "" );
     fldLen = sValue.length;
     mskLen = sMask.length;

     i = 0;
     nCount = 0;
     sCod = "";
     mskLen = fldLen;

     while (i <= mskLen) {
       bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
       bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

       if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++; }
       else {
         sCod += sValue.charAt(nCount);
         nCount++;
       }

       i++;
     }

     objForm[strField].value = sCod;

     if (nTecla != 8) { // backspace
       if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
       else { // qualquer caracter...
         return true;
       } }
     else {
       return true;
     }
   }

function Verificar()   // Verificação das Teclas
{
    var tecla=window.event.keyCode;
    var alt=window.event.altKey;      // Para Controle da Tecla ALT
    var ctrl=window.event.ctrlKey;    //  Para Controle da Tecla CTRL

    
    if (tecla==27)        
	{ event.keyCode=0; event.returnValue=false;} //Cancelar menu ESC
}

function verifica_promotor() {

var erro = "";
var xnome =     document.form.nomepromotor.value;

var tmp1 =      /(@.*@)|(\.\.)|(@\.)|(^\.)/;

if (xnome.length == 0){
   alert("Você não informou o nome!");
   document.form.nomepromotor.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();
}

}

function verifica_cliente(t) {


var erro = "";

if (t == 2){
   var xfonte =   document.form.fonte.value;
}

var xnome =     document.form.nomecliente.value;
var xrg =       document.form.rg.value;
var xexped =    document.form.exped.value;
var xuf =       document.form.uf.value;
var xendereco = document.form.endereco.value;
var xcidade =   document.form.cidade.value;
var xcep =      document.form.cep.value;
var xtelefone = document.form.telefone.value;
var xcelular =  document.form.celular.value;
var xcpf =      document.form.cpf.value;
var xemail =    document.form.email.value;
var xbanco =    document.form.banco.value;
var xagencia =  document.form.agencia.value;

var xtipo_conta = document.form.tipo_conta.value;
var xconta =    document.form.conta.value;
var xsalario =  document.form.salario.value;
var xemp_orgao = document.form.emp_orgao.value;
var xprofissao = document.form.profissao.value;
var xrenda_bruta = document.form.renda_bruta.value;

var xreferencia = document.form.referencia.value;
var xparentesco = document.form.parentesco.value;
var xfoneref = document.form.foneref.value;

var xreferencia2 = document.form.referencia2.value;
var xparentesco2 = document.form.parentesco2.value;
var xfoneref2 = document.form.foneref2.value;

var xnasc = document.form.nasc.value;
var xtemporesidencia = document.form.temporesidencia.value;
var xtipo_res = document.form.tipo_res.value;
var xsexo = document.form.sexo.value;

var xnaturalidade = document.form.naturalidade.value;
var xemp_orgao = document.form.emp_orgao.value;
var xpai = document.form.pai.value;
var xmae = document.form.mae.value;


var xestado_civil = document.form.estado_civil.value;

var tmp1 =      /(@.*@)|(\.\.)|(@\.)|(^\.)/;

if (xfonte == "0" || xfonte == ""){
   alert("Você não informou o campo origem!");
   document.form.fonte.focus();
   erro="t";
   return false;
}

if (xnome.length == 0){
   alert("Você não informou o nome!");
   document.form.nomecliente.focus();
   erro="t";
   return false;
}

if ((xcpf.length < 14) && (xcpf.length > 0)){
   alert("Faltam dígitos no CPF informado!");
   document.form.cpf.focus();
   erro = "t";
   return false;
}

if (xcpf.length == 0){
   alert("Você precisa informar o CPF !");
   document.form.cpf.focus();
   erro = "t";
   return false;
}

if (xrg.length == 0){
   alert("Você não informou o RG!");
   document.form.rg.focus();
   erro="t";
   return false;
}
if (xexped.length == 0){
   alert("Você não informou o órgão expedidor do RG!");
   document.form.exped.focus();
   erro="t";
   return false;
}


if (xendereco.length == 0){
   alert("Você não informou o endereço!");
   document.form.endereco.focus();
   erro="t";
   return false;
}

if (xcidade.length == 0){
   alert("Você não informou a cidade!");
   document.form.cidade.focus();
   erro="t";
   return false;
}

if (xuf.length == 0){
   alert("Você não informou o estado!");
   document.form.uf.focus();
   erro="t";
   return false;
}

//testa o cep digitado
if (xcep.length < 8){
   alert("Faltam dígitos no CEP informado!");
   document.form.cep.focus();
   erro="t";
   return false;
}

//testa o telefone digitado
if (xtelefone.length == 0){
   alert("Você não informou o Telefone!");
   document.form.telefone.focus();
   erro="t";
   return false;
}

if ((xtelefone.length < 14) && (xtelefone.length > 0)){
   alert("Faltam dígitos no telefone informado!");
   document.form.telefone.focus();
   erro = "t";
   return false;
}
//testa o telefone digitado

if ((xcelular.length < 14) && (xcelular.length > 0)){
   alert("Faltam dígitos no celular informado!");
   document.form.celular.focus();
   erro = "t";
   return false;
} 

if (xemail.length > 0){
   
   if (!((xemail.indexOf(".") > 0) && (xemail.indexOf("@") > 0)) && 
    ((xemail.lastIndexOf(".") < (xemail.length - 1)) && 
	 (xemail.lastIndexOf("@") < (xemail.length - 1)))){
     alert("O e-mail digitado é inválido!");
     document.form.email.focus();
     erro = "t";
	 return false;
   }
}  

if (xtemporesidencia.length == 0){
   alert("Você não informou o tempo de residência!");
   document.form.temporesidencia.focus();
   erro="t";
   return false;
}

if (xtipo_res == "0"){
   alert("Você não informou o tipo da residência!");
   document.form.tipo_res.focus();
   erro="t";
   return false;
}

if (xsexo == "0"){
   alert("Você não informou o sexo!");
   document.form.sexo.focus();
   erro="t";
   return false;
}

if (xnaturalidade.length == 0){
   alert("Você não informou sua naturalidade!");
   document.form.naturalidade.focus();
   erro="t";
   return false;
}

if (xpai.length == 0){
   alert("Você não informou o nome de seu pai!");
   document.form.pai.focus();
   erro="t";
   return false;
}
if (xmae.length == 0){
   alert("Você não informou o nome de sua mãe!");
   document.form.mae.focus();
   erro="t";
   return false;
}

if (xestado_civil.length == 0){
   alert("Você não informou seu estado civil!");
   document.form.estado_civil.focus();
   erro="t";
   return false;
}
 
if (xemp_orgao.length == 0){
   alert("Você não informou o órgão ou empresa.");
   document.form.emp_orgao.focus();
   erro = "t";
   return false;
}

if (xprofissao == "0"){
   alert("Você não informou o tipo da profissão!");
   document.form.profissao.focus();
   erro="t";
   return false;
}

if (xsalario.length == 0){
   alert("Você não informou a renda líquida.");
   document.form.salario.focus();
   erro = "t";
   return false;
}

if (xrenda_bruta.length == 0){
   alert("Você não informou a renda bruta.");
   document.form.renda_bruta.focus();
   erro = "t";
   return false;
} 

if (xreferencia.length == 0){
   alert("Você não informou o nome da primeira referencia pessoal!");
   document.form.referencia.focus();
   erro="t";
   return false;
}

if (xparentesco == "0"){
   alert("Você não informou o nome do grau de parentesco da primeira referência pessoal!");
   document.form.parentesco.focus();
   erro="t";
   return false;
}

if (xfoneref.length == 0){
   alert("Você não informou telefone da primeira referência!");
   document.form.foneref.focus();
   erro="t";
   return false;
}

if ((xfoneref.length < 14) && (xfoneref.length > 0)){
   alert("Faltam dígitos no telefone da primeira referência pessoal!");
   document.form.foneref.focus();
   erro = "t";
   return false;
}
if ((xfoneref.length < 14) && (xfoneref.length > 0)){
   alert("Faltam dígitos no telefone informado da primeira referência pessoal!");
   document.form.foneref.focus();
   erro = "t";
   return false;
}

if (xreferencia2.length == 0){
   alert("Você não informou o nome da segunda referencia pessoal!");
   document.form.referencia2.focus();
   erro="t";
   return false;
}

if (xparentesco2 == "0"){
   alert("Você não informou o nome do grau de parentesco da segunda referência pessoal!");
   document.form.parentesco2.focus();
   erro="t";
   return false;
}

if (xfoneref2.length == 0){
   alert("Você não informou telefone da segunda referência!");
   document.form.foneref2.focus();
   erro="t";
   return false;
}

if ((xfoneref2.length < 14) && (xfoneref2.length > 0)){
   alert("Faltam dígitos no telefone da segunda referência pessoal!");
   document.form.foneref2.focus();
   erro = "t";
   return false;
}
if ((xfoneref2.length < 14) && (xfoneref2.length > 0)){
   alert("Faltam dígitos no telefone informado da segunda referência pessoal!");
   document.form.foneref2.focus();
   erro = "t";
   return false;
}

if (xbanco.length == 0){
   alert("Você precisa informar o nome de um banco!");
   document.form.banco.focus();
   erro = "t";
   return false;
} 

if (xagencia.length == 0){
   alert("Você precisa informar o número da agência do banco!");
   document.form.agencia.focus();
   erro = "t";
   return false;
}

if (xconta.length == 0){
   alert("Você precisa informar a conta corrente do cliente!");
   document.form.conta.focus();
   erro = "t";
   return false;
}

if (xtipo_conta == "0"){
   alert("Você precisa informar o tipo da conta!");
   document.form.tipo_conta.focus();
   erro = "t";
   return false;
}

if (erro == "") {
   document.form.submit();
}

}

function verifica_cheque() {

var erro = "";
var xnumero =     document.form.numero.value;
var xbanco =   document.form.banco.value;
var xagencia = document.form.agencia.value;
var xconta =   document.form.conta.value;
var xcontadeposito =   document.form.contadeposito.value;
var xcliente =      document.form.cliente.value;
var xpromotor = document.form.promotor.value;
var xvalor = document.form.valor.value;
var xdata = document.form.data.value;
var mydate=new Date();
var year=mydate.getYear();
var month=mydate.getMonth();
var daym=mydate.getDate();
var tmp1 =      /(@.*@)|(\.\.)|(@\.)|(^\.)/;
month++

if (xnumero.length == 0){
   alert("Você não informou o numero do cheque!");
   document.form.numero.focus();
   erro="t";
   return false;
}

if (xbanco.length == 0){
   alert("Você não informou o banco!");
   document.form.banco.focus();
   erro="t";
   return false;
}

if (xagencia.length == 0){
   alert("Você não informou a agência!");
   document.form.agencia.focus();
   erro="t";
   return false;
}

if (xconta.length == 0){
   alert("Você não informou a conta corrente");
   document.form.conta.focus();
   erro="t";
   return false;
}

if (xcontadeposito.length == 0){
   alert("Você não informou a conta corrente para depósito!");
   document.form.contadeposito.focus();
   erro="t";
   return false;
}


if (xcliente.length == 0){
   alert("Você não informou o cliente!");
   document.form.cliente.focus();
   erro="t";
   return false;
}

if (xpromotor.length == 0){
   alert("Você não informou o promotor!");
   document.form.promotor.focus();
   erro="t";
   return false;
}

if (xvalor.length == 0){
   alert("Você não informou o valor do cheque!");
   document.form.valor.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();;
}

}

function verifica_conta() {

var erro = "";
var xconta =   document.form.conta.value;
var xagencia = document.form.agencia.value;
var xbanco =   document.form.banco.value;
var xtitular = document.form.titular.value;

if (xconta.length == 0){
   alert("Você não informou o número da conta!");
   document.form.conta.focus();
   erro="t";
   return false;
}

if (xagencia.length == 0){
   alert("Você não informou a agência do banco!");
   document.form.agencia.focus();
   erro="t";
   return false;
}

if (xbanco.length == 0){
   alert("Você não informou o número do banco!");
   document.form.banco.focus();
   erro="t";
   return false;
}

if (xtitular.length == 0){
   alert("Você não informou o nome do titular da conta!");
   document.form.titular.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();;
}

}

function verifica_permissoes() {

var erro = "";
var xusuario =   document.form.usuario.value;

if (xusuario.length == 0){
   alert("Você não informou qual usuário!");
   document.form.usuario.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();;
}

}

function verifica_convenio() {

var erro = "";
var xnome = document.form.nomeconvenio.value;

if (xnome.length == 0){
   alert("Você não informou o nome do convênio!");
   document.form.nomeconvenio.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();
}

}

function verifica_bco() {
var erro = "";
var xnome  = document.form.nomebanco.value;

if (xnome.length == 0){
   alert("Você não informou o nome do banco!");
   document.form.nomebanco.focus();
   erro="t";
   return false;
}

if (erro == "") {
   document.form.submit();;
}

}

function verifica_contrato(t) {

var erro = "";
var xagenda = document.form.agenda.value;
if (t == 2){
   var xstatus = document.form.status.value;
   var xvalor_lib = document.form.valor_lib.value;
   var xdata_lib = document.form.data_lib.value;
} else {
   var xvalor = document.form.valor.value;
   var xdata_lib = document.form.data_lib.value;
}


if (t == 2){
  
  if (xdata_lib.length == 0){
   alert("Você não informou o dia da liberação!");
   document.form.data_lib.focus();
   erro="t";
   return false;
  } 

  if (xvalor_lib == "0,00"){
   alert("Você não informou o valor liberado!");
   document.form.valor_lib.focus();
   erro="t";
   return false;
  } 
} else {
  if (xvalor.length == 0){
   alert("Você não informou o valor do contrato!");
   document.form.valor.focus();
   erro="t";
   return false;
  }
  if (xagenda.length == 0){
   alert("Você não informou a agenda!");
   document.form.agenda.focus();
   erro="t";
   return false;
  }
}

if (erro == "") {
   document.form.submit();;
}

}

function verifica_cpf() {
var CPF = document.form.cpf.value; // Recebe o valor digitado no campo
cpfString = new String(CPF);
cpf1=cpfString.slice(0,3);
cpf2=cpfString.slice(4,7);
cpf3=cpfString.slice(8,11);
cpf4=cpfString.slice(12,14);
var CPF2 = String(cpf1+cpf2+cpf3+cpf4);
//Verifica se o campo é nulo
if (CPF == '') {
     alert('Este campo é de preenchimento obrigatório!');
     return false;
   }

   // Aqui começa a checagem do CPF
   var POSICAO, I, SOMA, DV, DV_INFORMADO;
   var DIGITO = new Array(10);
   DV_INFORMADO = CPF2.substr(9, 2); // Retira os dois últimos dígitos do número informado
   // Desemembra o número do CPF na array DIGITO
   for (I=0; I<=8; I++) {
     DIGITO[I] = CPF2.substr( I, 1);
   }

   // Calcula o valor do 10º dígito da verificação
   POSICAO = 10;
   SOMA = 0;
   for (I=0; I<=8; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
   DIGITO[9] = SOMA % 11;
   if (DIGITO[9] < 2) {
        DIGITO[9] = 0;
   } else {
       DIGITO[9] = 11 - DIGITO[9];
   }

// Calcula o valor do 11º dígito da verificação
   POSICAO = 11;
   SOMA = 0;
   for (I=0; I<=9; I++) {
      SOMA = SOMA + DIGITO[I] * POSICAO;
      POSICAO = POSICAO - 1;
   }
   DIGITO[10] = SOMA % 11;
   if (DIGITO[10] < 2) {
        DIGITO[10] = 0;
   } else {
        DIGITO[10] = 11 - DIGITO[10];
   }

   // Verifica se os valores dos dígitos verificadores conferem
   DV = DIGITO[9] * 10 + DIGITO[10];
   if (DV != DV_INFORMADO) {
      alert('CPF inválido');
      document.form.cpf.focus();
      return false;
   } else {
     return true;
   }
}


