<?php
require_once ("../../config/Cado.php");
require_once ("cMarca.php");
$oMarca = new cMarca();
if($_POST['action']=="insertar")
{
	$mar_nom=$_POST['mar_nom'];
}
if($_POST['action']=="editar")
{
	$dts=$oMarca->mostrarUno($_POST['mar_id']);
	$dt = mysqli_fetch_array($dts);
		$mar_nom=$dt['tb_marca_nom'];
	mysqli_free_result($dts);
}
?>
<form role="form" id="for_mar" method="POST">

<input name="action_marca" id="action_marca" type="hidden" value="<?php echo $_POST['action']?>">
<input name="hdd_mar_id" id="hdd_mar_id" type="hidden" value="<?php echo $_POST['mar_id']?>">
	<div class="box-header">
            <h3 class="box-title">Registro de Laboratorio</h3>
          </div>
          <div class="box-body">
    <div class="form-group">
      <div class="row">
        <div class="col-lg-10 col-xs-12">
          <label for="txt_mar_nom">Nombre:</label>
          <input name="txt_mar_nom" type="text" id="txt_mar_nom" value="<?php echo $mar_nom?>" class="form-control">
        </div>
      </div>
    </div>
    </div>
</form>
		 <div class="box-footer  float-right">
          <button type="button" data-dismiss="modal" class="btn btn-default cancel">Cancelar</button>
            <button class="btn btn-primary" id="btn_marca_save">Guardar</button>
          </div>
     
<script type="text/javascript">
$(function() {
	
	$('#txt_mar_nom').focus();
	
	$('#txt_mar_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
  	$("#btn_marca_save").click(function() {
	    $("#for_mar").submit();
  	});
  	$(document).ready(function() {
	    $('#for_mar').bootstrapValidator({
	      //live: 'disabled',
	      message: 'This value is not valid',
	      feedbackIcons: {
	        valid: 'glyphicon glyphicon-ok',
	        invalid: 'glyphicon glyphicon-remove',
	        validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {
	        txt_mar_nom: {
	          group: '.col-lg-10',
	          validators: {
	            notEmpty: {
	              message: 'Este campo es requerido'
	            }
	          }
	        }
	      }
	    }).on('success.form.bv', function(e) {
	      /*--- Save ---*/
	      $.ajax({
				type: "POST",
				url: "../marca/marca_reg.php",
				async:true,
				dataType: "json",
				data: $("#for_mar").serialize(),
				beforeSend: function() {
					$('#msj_marca').html("Guardando...");
					$('#msj_marca').show(100);
				},
				success: function(data){
					
				
						
					<?php if($_POST['vista']=="producto"){?>
						$('#div_marca_form_dialog').modal('hide');
						$('.div_marca_form').html('')
						toastr["success"](data.mar_msj);
						//cmb_mar_id(data.mar_id);
						
					//cmb_mar_id('<?php echo $_POST['cat_id'] ?>');
						
					<?php }else if($_POST['vista']=="marca"){
						?>
						$('.modal').modal('hide');
						$('.in').removeClass('modal-backdrop');			
						toastr["success"](data.mar_msj);	
						<?php 
					}?>
				},
				complete: function(){					
					
					
				}
			});
	    });
	});
});
$("#txt_mar_nom").keypress(function(e){
	if(e.which==13){
		$("#btn_marca_guardar").focus();;return false;
	}
});
</script>