function checkdata(formulario) {
  var reDate     = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;   
  var reEmail    = /^\w+([-.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  var reZipcode  = /^[1-9]\d{5}$/; 
  var rePhone    = /^\d{3}-\d{8}|\d{4}-\d{7}$/; 
  var reMobile   = /^13\d{9}$/;         
  var reCurrency = /^\d+(\.\d{1,4})?$/; 
  var reNumber   = /^\d+$/;
  var reInteger  = /^[-\+]?\d+$/;                                                                                               
  var reFloat    = /^[-\+]?\d+(\,\d+)?$/;      

  //--------------------------------------------------------------------
  // MODULOS DE CADASTROS DO SISTEMA
  //--------------------------------------------------------------------
  if (formulario == "CadastroMaquina") {
    with(document.frmCadastroMaquina) { 

      if (cmbGrupoMaquinas.value == "") {
        alert("Selecione um grupo de máquinas!");
        cmbGrupoMaquinas.focus();
        return false; 
      }
      if (txtNome.value == "") {
        alert("Campo Nome da Máquina Inválido!");
        txtNome.focus();
        return false; 
      }
      if ((txtCusto.value != "") && (!reFloat.test(txtCusto.value))) {
        alert("Campo Custo Inválido!");
        txtCusto.focus();
        return false; 
      }
      if (chkFormatoMaterial[1].checked) {
        if (!reFloat.test(txtCapX.value)){
            alert("Campo capacidade X Invalido! Digite somente valores numéricos!");
            txtCapX.focus();
            return false; 
        }
        if (!reFloat.test(txtCapY.value)){
            alert("Campo capacidade Y Invalido! Digite somente valores numéricos!");
            txtCapY.focus();
            return false; 
        }
        if (!reFloat.test(txtCapZ.value)){
            alert("Campo capacidade Z Invalido! Digite somente valores numéricos!");
            txtCapZ.focus();
            return false; 
        }
        if (!reFloat.test(txtCapPesoMesa.value)){
            alert("Campo peso sobre mesa Invalido! Digite somente valores numéricos!");
            txtCapPesoMesa.focus();
            return false; 
        }
      }

      if (chkFormatoMaterial[0].checked) {      
        if (!reFloat.test(txtCapDiametro.value)){
            alert("Campo diâmetro Invalido! Digite somente valores numéricos!");
            txtCapDiametro.focus();
            return false; 
        }  
        if (!reFloat.test(txtCapComprimento.value)){
            alert("Campo comprimento Invalido! Digite somente valores numéricos!");
            txtCapComprimento.focus();
            return false; 
        }
        if (!reFloat.test(txtCapPesoBarramento.value)){
            alert("Campo peso sobre barramento Invalido! Digite somente valores numéricos!");
            txtCapPesoBarramento.focus();
            return false; 
        }           
      }
    }
  }

  if (formulario == "CadastroTerceiro") {
    with(document.frmCadastroTerceiro) { 
    
      if (txtRazaoSocial.value == "") {
        alert("Campo Razao Social em branco!");
        txtRazaoSocial.focus();
        return false; 
      }
      if (txtCNPJ.value == "") {
        alert("Campo CNPJ em branco!");
        txtCNPJ.focus();
        return false; 
      }
      if (txtTelefone.value == "") {
        alert("Campo Telefone em branco!");
        txtTelefone.focus();
        return false; 
      }

      if (txtTipoServico.value == "") {
        alert("Campo Tipo de Servico em branco!");
        txtTipoServico.focus();
        return false; 
      }
    }
  }

  if (formulario == "CadastroFornecedores") {
    with(document.frmCadastroFornecedores) { 
    
      if (txtNome.value == "") {
        alert("Campo Nome do Fornecedor em branco!");
        txtNome.focus();
        return false; 
      }
      if (txtCNPJ.value == "") {
        alert("Campo CNPJ em branco!");
        txtCNPJ.focus();
        return false; 
      }        
      if (txtMateriaPrima.value == "") {
        alert("Campo Matéria Prima em branco!");
        txtMateriaPrima.focus();
        return false; 
      }
      if (txtFerramentas.value == "") {
        alert("Campo Ferramentas em branco!");
        txtFerramentas.focus();
        return false; 
      }
      if (txtTipoServico.value == "") {
        alert("Campo Tipo Servico em branco!");
        txtTipoServico.focus();
        return false; 
      }
      if (txtTelefone.value == "") {
        alert("Campo Telefone em branco!");
        txtTelefone.focus();
        return false; 
      }    
    }
  }
  
  if (formulario == "CadastroMateriais") {
    with(document.frmCadastroMateriais) { 
    
      if (txtNome.value == "") {
        alert("Campo Descrição em branco!");
        txtNome.focus();
        return false; 
      }

      if(!reFloat.test(txtPeso.value)){
        alert("Campo Peso Invalido! Digite somente valores numéricos!");
        txtPeso.focus();
        return false; 
      }  

      if (txtTipoMaterial.value == "") {
        alert("Campo Tipo do Material em branco!");
        txtTipoMaterial.focus();
        return false; 
      }

      if (!reFloat.test(txtDimX.value)){
        alert("Campo DimX Invalido! Digite somente valores numéricos!");
        txtDimX.focus();
        return false; 
      }  
      if (!reFloat.test(txtDimY.value)){
        alert("Campo DimY Invalido! Digite somente valores numéricos!");
        txtDimY.focus();
        return false; 
      }
      if (!reFloat.test(txtDimZ.value)){
        alert("Campo DimZ Invalido! Digite somente valores numéricos!");
        txtDimZ.focus();
        return false; 
      }
    }
  }
  
  if (formulario == "CadastroClientes" ) {
    with(document.frmCadastroClientes) { 
      
      if (txtNome.value == "") {
        alert("Campo Nome em branco!");
        txtNome.focus();
        return false; 
      }
     
      if (txtCidade.value == "") {
        alert("Campo Cidade em branco!");
        txtCidade.focus();
        return false; 
      }
      
      if (txtUF.value == "") {
        alert("Campo Estado em branco!");
        txtUF.focus();
        return false; 
      }
     
      if (txtEndereco.value == "") {
        alert("Campo Endereco em branco!");
        txtEndereco.focus();
        return false; 
      }
      
      if (txtTelefone.value == "") {
        alert("Campo Telefone em branco!");
        txtTelefone.focus();
        return false; 
      }
     
      if (reNumber.test(txtCidade.value)){
        alert("Campo Cidade Inválido! Digite somente letras!");
        txtCidade.focus();
        return false; 
      }
     
      if (reNumber.test(txtUF.value)){
        alert("Campo Estado Inválido! Digite somente letras!");
        txtUF.focus();
        return false; 
      }     
    }    
  }
  
  if (formulario == "CadastroContatos" ) {
    with(document.frmCadastroContatos) { 
      
      if (txtNome.value == "") {
        alert("Campo Nome em branco!");
        txtNome.focus();
        return false; 
      }  

      //if (txtEmail.value == "") {
      // alert("Campo E-mail em branco!");
      //  txtEmail.focus();
      //  return false; 
      //}

      if (txtDepartamento.value == "") {
        alert("Campo Departamento em branco!");
        txtDepartamento.focus();
        return false; 
      }  

      if (txtRamal.value == "") {
        alert("Campo Ramal em branco!");
        txtRamal.focus();
        return false; 
      }  

   if (txtEmail.value != "") {
      if (!reEmail.test(txtEmail.value)){
        alert("Campo Email Inválido! Digite um e-mail válido!");
        txtEmail.focus();
        return false; 
      }
   }

      if (txtRamal.value == "") {
        alert("Campo Ramal em branco!");
        txtRamal.focus();
        return false; 
      }
    }
  }
     
     
  if (formulario == "CadastroFuncionarios" ) {
    with(document.frmCadastroFuncionarios) { 
      
      if (txtMatricula.value == "") {
        alert("Campo Matricula em branco!");
        txtMatricula.focus();
        return false; 
      }
      if (cmbGrupo.value == "") {
        alert("Selecione um grupo de acesso para o funcionário!");
        cmbGrupo.focus();
        return false; 
      }
      if (txtNome.value == "") {
        alert("Campo Nome em branco!");
        txtNome.focus();
        return false; 
      }
      if (txtTelefone.value == "") {
        alert("Campo Telefone em branco!");
        txtTelefone.focus();
        return false; 
      }
      if (txtCelular.value == "") {
        alert("Campo Celular em branco!");
        txtCelular.focus();
        return false; 
      }
      if (txtEmail.value == "") {
        alert("Campo Email em branco!");
        txtEmail.focus();
        return false; 
      }
      if (txtDataAniversario.value == "") {
        alert("Campo Data de Aniversário em branco!");
        txtDataAniversario.focus();
        return false; 
      }
      if (txtSenha.value == "") {
        alert("Campo Senha em branco!");
        txtSenha.focus();
        return false; 
      }  
      if (txtConfSenha.value == "") {
        alert("Campo Conf. Senha em branco!");
        txtConfSenha.focus();
        return false; 
      }  
      if (txtSenha.value != txtConfSenha.value) {
        alert("As senhas digitadas são diferentes. Digite-as novamente!");
        txtSenha.focus();
        return false; 
      }       
      if (!reNumber.test(txtMatricula.value)){
        alert("Campo Matrícula Inválido! Digite uma Matrícula válida!");
        txtMatricula.focus();
        return false; 
      }     
      if (!reEmail.test(txtEmail.value)){
        alert("Campo Email Inválido! Digite um e-mail válido!");
        txtEmail.focus();
        return false; 
      }
      if (!reDate.test(txtDataAniversario.value)){
        alert("Campo Data de Aniversário Inválido! Digite uma data no formato DD/MM/AAAA!");
        txtDataAniversario.focus();
        return false; 
      }
    }
  }
  
  if (formulario == "CadastroGrupoMaquinas" ) {
    with(document.frmCadastroGrupoMaquinas) { 
      if (txtDescricao.value == "") {
        alert("Campo Descrição Inválido! Favor digite uma Descrição!");
        txtDescricao.focus();
        return false; 
      }  
      if (txtCustoHora.value == "") {
        alert("Campo Custo/Hora em branco!");
        txtCustoHora.focus();
        return false; 
      }        
      if (!reFloat.test(txtCustoHora.value)){
        alert("Campo Custo/Hora Inválido! Digite um Custo/Hora válido!");
        txtCustoHora.focus();
        return false; 
      }     
    }
  }

  if (formulario == "CadastroTratamentos" ) {
    with(document.frmCadastroTratamentos) { 
      if (txtDescricao.value == "") {
        alert("Campo Descrição Inválido! Favor digite uma Descrição!");
        txtDescricao.focus();
        return false; 
      }  
      if ((txtCusto.value != "") && (!reFloat.test(txtCusto.value))){
        alert("Campo Custo (kg) Inválido! Digite um custo válido!");
        txtCusto.focus();
        return false; 
      }         
    }
  }
  
  if (formulario == "CadastroCategorias" ) {
    with(document.frmCadastroCategorias) { 
      if (txtDescricao.value == "") {
        alert("Campo Descrição Inválido! Favor digite uma Descrição!");
        txtDescricao.focus();
        return false; 
      }  
      if (txtOrdem.value == "") {
        alert("Campo Ordem Inválido! Favor digite uma Ordem!");
        txtOrdem.focus();
        return false; 
      }  
      if (!reNumber.test(txtOrdem.value)){
        alert("Campo Ordem Inválido! Digite uma Ordem válida!");
        txtOrdem.focus();
        return false; 
      }
    }
  }
  
  if (formulario == "CadastroMenus" ) {
    with(document.frmCadastroMenus) { 
      
      if (cmbCategoria.value == "") {
        alert("Selecione uma categoria para classificar as telas do menu!");
        cmbCategoria.focus();
        return false; 
      }
      if (txtDescricao.value == "") {
        alert("Campo Descrição Inválido! Favor digite uma Descrição!");
        txtDescricao.focus();
        return false; 
      }  
      if (txtLink.value == "") {
        alert("Campo Link Inválido! Favor digite um Link!");
        txtLink.focus();
        return false; 
      }  
      if (txtOrdem.value == "") {
        alert("Campo Ordem Inválido! Favor digite uma Ordem!");
        txtOrdem.focus();
        return false; 
      }  
      if (!reNumber.test(txtOrdem.value)){
        alert("Campo Ordem Inválido! Digite uma Ordem válida!");
        txtOrdem.focus();
        return false; 
      }
    }
  }

  if (formulario == "CadastroGrupos" ) {
    with(document.frmCadastroGrupos) { 
      
      if (txtDescricao.value == "") {
        alert("Campo Descrição Inválido! Favor digite uma Descrição!");
        txtDescricao.focus();
        return false; 
      }  
      if (chkTipoAcesso[0].checked==true) {
        var sel=0;     
        for(i=0;i<chkTelas.length;i++){
          if (chkTelas[i].checked==true) {sel=1};
        }
        if (sel==0) {
          alert("Selecione pelo menos uma Categoria/Tela!");
          txtDescricao.focus();
          return false; 
        }  
      }
    }
  }  
  
  //--------------------------------------------------------------------
  // MODULO DE PEDIDO DE COMPRAS - CONSUMIVEIS
  //--------------------------------------------------------------------  
  if (formulario == "CadastroPedidoConsumiveis") {
    with(document.frmCadastroPedidoConsumiveis) { 
    
      if (txtDescricao.value == "") {
        alert("Favor preencha a descrição do item!");
        txtDescricao.focus();
        return false; 
      } 
      
      if (txtSolicitante.value == "") {
        alert("Favor preencha o solicitante do item!");
        txtSolicitante.focus();
        return false; 
      }       
    
      if (txtQuantidade.value == "") {
        alert("Favor preencha a quantidade de itens!");
        txtQuantidade.focus();
        return false; 
      }   

      if (!reNumber.test(txtQuantidade.value)){
        alert("Campo Quantidade Inválido! Digite apenas números!");
        txtQuantidade.focus();
        return false; 
      }     
         
      if (cmbUnidade.value == "") {
        alert("Favor selecione uma unidade de medida para o item!");
        cmbUnidade.focus();
        return false; 
      }    


      if (txtDataPedido.value == "") {
        alert("Favor preencha a data do pedido!");
        txtDataPedido.focus();
        return false; 
      }   
      
      if (txtDataPedido.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_tsmp1(txtDataPedido.value) == null){
          txtDataPedido.focus();
          return false;
        }
      }   

    }
  }
  //--------------------------------------------------------------------
  // MODULO DE PEDIDO DE COMPRAS - MATERIA PRIMA
  //--------------------------------------------------------------------  
  if (formulario == "CadastroPedidoMateriaPrima") {
    with(document.frmCadastroPedidoMateriaPrima) { 
    
      if (cmbMaterial.value == "") {
        alert("Favor selecione o material desejado!");
        cmbMaterial.focus();
        return false; 
      } 
      
      if (txtSolicitante.value == "") {
        alert("Favor preencha o solicitante do item!");
        txtSolicitante.focus();
        return false; 
      }       
    
      if (txtQuantidade.value == "") {
        alert("Favor preencha a quantidade de itens!");
        txtQuantidade.focus();
        return false; 
      }   

      if (!reNumber.test(txtQuantidade.value)){
        alert("Campo Quantidade Inválido! Digite apenas números!");
        txtQuantidade.focus();
        return false; 
      }     

      if (txtDataPedido.value == "") {
        alert("Favor preencha a data do pedido!");
        txtDataPedido.focus();
        return false; 
      }   
      
      if (txtDataPedido.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_tsmp1(txtDataPedido.value) == null){
          txtDataPedido.focus();
          return false;
        }
      }                 
    }
  }  
  
  //--------------------------------------------------------------------
  // MODULO DE GERACAO DE OC DE PC
  //--------------------------------------------------------------------  
  if (formulario == "GerarOrdemCompra") {
    with(document.frmGerarOrdemCompra) { 
    
      if (chkTipoOrdem[1].checked) {
        if (cmbFornecedor.value == ""){
            alert("Favor selecionar um fornecedor para gerar a OC!");
            cmbFornecedor.focus();
            return false; 
        }
      }
      else {
        if (txtFornecedor.value == ""){
            alert("Favor digitar um fornecedor para gerar a OC!");
            txtFornecedor.focus();
            return false; 
        }
      }     
    }
  }  
  
  //--------------------------------------------------------------------
  // MODULO DE COMPRAS
  //--------------------------------------------------------------------  
  if (formulario == "CadastroCompra") {
    with(document.frmCadastroCompra) { 
    
      if (txtDataCompra.value == "") {
        alert("Favor preencha a data da compra!");
        txtDataCompra.focus();
        return false; 
      } 
    
      if (txtDataCompra.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_date1(txtDataCompra.value) == null){
          txtDataCompra.focus();
          return false;
        }
      }   
         
      if (txtDataEntrega.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_date1(txtDataEntrega.value) == null){
          txtDataEntrega.focus();
          return false;
        }
      }    
      
    }
  }  
  
  //--------------------------------------------------------------------
  // MODULO DE PLANEJAMENTO
  //--------------------------------------------------------------------  
  
  //--------------------------------------------------------------------
  // MODULO DE ORCAMENTO
  //--------------------------------------------------------------------  
  if (formulario == "OrcamentoCadastroGeral" ) {
    with(document.frmOrcamento) { 
      if (txtDataOrcamento.value == "") {
        alert("Favor preencha a data de criação!");
        txtDataOrcamento.focus();
        return false; 
      } 
      if (txtDataOrcamento.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_date1(txtDataOrcamento.value) == null){
          txtDataOrcamento.focus();
          return false;
        }
      }        
      if (txtDescricao.value == "") {
        alert("Favor coloque uma descrição para o orçamento!");
        txtDescricao.focus();
        return false; 
      }  
      if (cmbCliente.value == "") {
        alert("Favor selecione um cliente!");
        cmbCliente.focus();
        return false; 
      }             
      if (txtValidadeProposta.value == "") {
        alert("Favor preencha a data com a validade da proposta!");
        txtValidadeProposta.focus();
        return false; 
      } 
      if (txtValidadeProposta.value != "") {
        //VERIFICA A DATA COM A FUNCAO DO CALENDAR1
        if (cal_prs_date1(txtValidadeProposta.value) == null){
          txtValidadeProposta.focus();
          return false;
        }
      }   
      if (!reNumber.test(txtEntrega.value)){
        alert("Campo Entrega Inválido! Digite apenas números!");
        txtEntrega.focus();
        return false; 
      } 
      if (txtTipoFerramenta.value == "") {
        alert("Favor informe o tipo da ferramenta!");
        txtTipoFerramenta.focus();
        return false; 
      }  
      if (txtNumFerramenta.value == "") {
        alert("Favor informe o número da ferramenta!");
        txtNumFerramenta.focus();
        return false; 
      }       
    }
  }  
  if (formulario == "OrcamentoCadastroSubPeca" ) {
    with(document.frmOrcamento) { 
      if (txtPosicao.value == "") {
        alert("Informe a posição da sub-peça!");
        txtPosicao.focus();
        return false; 
      }
      if (cmbMaterial.value == "") {
        alert("Selecione o tipo do material da sub-peça!");
        cmbMaterial.focus();
        return false; 
      }
      if (cmbTratamentoTermico.value == "") {
        alert("Selecione o tratamento térmico da sub-peça!");
        cmbTratamentoTermico.focus();
        return false; 
      }
      if (cmbTratamentoSuperficial.value == "") {
        alert("Selecione o tratamento superficial da sub-peça!");
        cmbTratamentoSuperficial.focus();
        return false; 
      }      
      if (!reNumber.test(txtQuantidade.value)){
        alert("Campo Quantidade Inválido! Digite apenas números!");
        txtQuantidade.focus();
        return false; 
      }     
      if ((txtCustoMaterial.value != "") && (!reFloat.test(txtCustoMaterial.value))){
        alert("Campo Custo Material Inválido! Digite apenas números!");
        txtCustoMaterial.focus();
        return false; 
      }  
      if ((txtCustoTratTermico.value != "") && (!reFloat.test(txtCustoTratTermico.value))){
        alert("Campo Custo Tratamento Térmico Inválido! Digite apenas números!");
        txtCustoTratTermico.focus();
        return false; 
      } 
      if ((txtCustoTratSuperficial.value != "") && (!reFloat.test(txtCustoTratSuperficial.value))){
        alert("Campo Custo Tratamento Superficial Inválido! Digite apenas números!");
        txtCustoTratSuperficial.focus();
        return false; 
      }       
      return true;
    }
  }  
  if (formulario == "OrcamentoCadastroFabril" ) {
    with(document.frmOrcamento) { 
      if (cmbSubPeca.value == "") {
        alert("Selecione uma sub-peça!");
        cmbSubPeca.focus();
        return false; 
      } 
      if (cmbGrupoMaquina.value == "") {
        alert("Selecione um grupo de máquinas!");
        cmbGrupoMaquina.focus();
        return false; 
      }       
      if (!reFloat.test(txtHoras.value)){
        alert("Campo Horas Inválido! Digite apenas números!");
        txtHoras.focus();
        return false; 
      }  
      if (!reFloat.test(txtValor.value)){
        alert("Campo Valor Inválido! Digite apenas números!");
        txtValor.focus();
        return false; 
      } 
      return true;
    }
  }    
  if (formulario == "OrcamentoDescontoAcrescimo" ) {
    with(document.frmOrcamento) {      
      if (!reFloat.test(txtPorcentagem.value)){
        alert("Campo Porcentagem Inválido! Digite apenas números!");
        txtPorcentagem.focus();
        return false; 
      }       
      return true;
    }
  }    
} 
//--------------------------------------------------------------------
// FUNCOES GERAIS
//--------------------------------------------------------------------  
function valida_cpf(){
    with(document.frmCadastroUsuario) {
        var i;
        s = document.frmConUsuarios.txtCPF.value;
        if (s.length != 11) {
        alert ("Tamanho do CPF deve ser de 11 caracteres!");
        document.frmConUsuarios.txtCPF.focus();
        return false;
        }
        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){
        alert("CPF Invalido!");
        document.frmConUsuarios.txtCPF.focus();
        return false;
        }

        d1 = 11 - (d1 % 11);
        if (d1 > 9){
        d1 = 0;
        }

        if (dv.charAt(0) != d1) {
        alert("CPF Invalido!");
        document.frmConUsuarios.txtCPF.focus();
        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("CPF Invalido!");
            document.frmConUsuarios.txtCPF.focus();
            return false;
        }
        return true;
    }
}