<?php
include 'header.php';
include 'erpc_clientes_toolbar.php';
require_once 'inc/clientes.php';
require_once 'inc/usuario.php';

checkLogin('login.php');

$clientes = clientes_create();



?>

<form method="post" action="erpc_clientes_ws.php" id=validate_custom>
  <div class="block">
    <div class="header">
      <h2>Cliente - Adicionar</h2>
    </div>
    <div class="block">
      <div class="content">
        <?php
        displayMessagesAndErrors(true);
        ?>
      </div>
    </div>
  </div>

  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#form1" aria-controls="form1" role="tab" data-toggle="tab">Cadastro</a></li>
    <li role="presentation"><a href="#form2" aria-controls="form2" role="tab" data-toggle="tab">Impostos</a></li>
    <li role="presentation"><a href="#form3" aria-controls="form3" role="tab" data-toggle="tab">Comercial</a></li>
    <li role="presentation"><a href="#form4" aria-controls="form4" role="tab" data-toggle="tab">Miscelanea</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div role="tabpanel" class="tab-pane fade in active" id="form1">
      <? include_once "erpc_clientes_cadastro.php";?>
    </div> <!-- tab-pane -->

    <div role="tabpanel" class="tab-pane fade in" id="form2">
      <? include_once "erpc_clientes_imposto.php";?>
    </div> <!-- tab-pane -->

    <div role="tabpanel" class="tab-pane fade in" id="form3">
      <? include_once "erpc_clientes_comercial.php"; ?>
    </div> <!-- tab-pane -->
    
    <div role="tabpanel" class="tab-pane fade in" id="form4">
      <? include_once "erpc_clientes_miscelanea.php"; ?>
    </div> <!-- tab-pane -->
    
  </div> <!-- tab-content -->

  <div class="block">
    <div class="content controls">
      <div class="form-row">
        <div class="col-md-12 text-right">

          <!--button type="submit" name="btn-add" id="btn-add" class="btn btn-primary btn-cleanx" onClick="$('#validate_custom').validationEngine('hide');" >Adicionar</button-->

          <button type="submit" name="btn-venda" id="btn-venda" class="btn btn-primary btn-cleanx" onClick="validarForm();" >Adicionar e Vender</button>
          <button type="submit" name="btn-add" id="btn-add" class="btn btn-primary btn-cleanx" onClick="validarForm();" >Adicionar</button>
          

          <!--
          <button name="btn-add" class="btn btn-primary btn-cleanx">Adicionar</button>-->
          <button id="btn-voltar" class="btn btn-default btn-cleanx">Voltar</button>
        </div>
      </div>
    </div>
  </div>
</form>

<script type='text/javascript' src='js\jquery-3.1.1.min.js' ></script>
<script type='text/javascript' src='js\validar_form.js' ></script>

<script>
    
    validarForm = function(){

      // var x = $('#validate_custom').validationEngine('hideAll', options:{autoPositionUpdate:true});
      var x = $('#validate_custom').validationEngine('hide');

      nreq = $(":required").length;
      nval = 0;
      vmsg  = "";

      $(":required").each(function(index, element) {
          var p_id   = $(this).attr("name");
          var p_type = $(this).attr("type");

          switch (p_type) {
            case 'radio':
                 if($(this).attr("checked")){
                   nval ++;
                   nval ++;
                 }
                 break;
            default:
                if($(this).val()!=""){
                  nval ++;
                }else{
                  $(this).css("background-color", "#C33"); // Coloca o campo na cor vermelha
                }
          }
      });

      if(nreq!=nval){
        // $("#dialog").dialog();
        var p_msg = 'Existem campos obrigatórios ainda não preenchidos. Verifique os campos em vermelho e mensagens informadas.';
        noty({text: '' + p_msg + '', type: 'error', timeout: 5000});
      };
  }
    
    
</script>

<?php include 'inc/helper_modal_div.php'; ?>
<?php include 'footer.php'; ?>
<script type="text/javascript" >

    //$("#clientes[ds_ie]").keyup(function(){
    $("[name='clientes[ds_ie]']").keyup(function(){
      $(this).val($(this).val().replace(".", ""));
    });
    $("[name='clientes[ds_ie]']").blur(function(){
      $(this).val($(this).val().replace(".", ""));
    });

    

</script>
<script type="text/javascript" src="js\acme.js"></script>
<script type="text/javascript" src="js\caracteres.js"></script>
<script type="text/javascript" src="js\verifica_cnpj_cpf.js"></script>
<script type="text/javascript" src="js\busca_CEP.js"></script>