<?php
require_once ("../../config/Cado.php");
require_once ("cEmpaque.php");
$oEmpaque = new cEmpaque();
if($_POST['action']=="insertar")
{
	$pre_nom=$_POST['pre_nom'];
}
if($_POST['action']=="editar"){
	$dts=$oEmpaque->mostrarUno($_POST['emp_id']);
	$dt = mysqli_fetch_array($dts);
	$pre_nom=$dt['tb_empaque_nom'];
	$pre_fac=$dt['tb_empaque_fac'];
	mysqli_free_result($dts);
}
?>
				<form role="form" id="for_cat" method="POST">
						<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
						<input name="hdd_emp_id" id="hdd_emp_id" type="hidden" value="<?php echo $_POST['emp_id']?>">
						
					<div class="box-header">
						<h3 class="box-title">Información de la Empaque</h3>
					</div>
					<div class="box-body">
					<div class="form-group">							
							<div class="row">
								<div class="col-lg-6 col-sm-3 col-xs-12">
									<label for="txt_emp_nom">Nombre:</label>
									<input name="txt_emp_nom" id="txt_emp_nom" type="text" autocomplete="off" value="<?php echo $pre_nom ?>" class="form-control">
								</div>
								
								
								<div class="col-lg-6 col-sm-3 col-xs-12">
									<label for="txt_emp_fac">Factor:</label>
									<input name="txt_emp_fac" id="txt_emp_fac" type="text" autocomplete="off"  value="<?php echo $pre_fac * 1 ?>" 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="save_form_emp">Guardar</button>
			</div>
		
<script type="text/javascript">
	
	
	$('#txt_emp_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	
		
	$("#save_form_emp").click(function() {
		$("#for_cat").submit();
	});

	$(document).ready(function() {
		$('#for_cat').bootstrapValidator({
	      //live: 'disabled',
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {	      	
	      	txt_emp_nom: {
	      		group: '.col-xs-6',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {
	  	$('#msj_categoria').html("Cargando...");
	  	$('#msj_categoria').show(100);
	  	/*--- Save ---*/
	  	$.ajax({
	  		type: "POST",
	  		url: "../empaque/empaque_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_cat").serialize(),
	  		beforeSend: function() {
	  			
	  		},
	  		success: function(data){	
				
				toastr["success"](data.emp_msj);
				
				
				
				<?php if($_POST['vista']=="producto"){?>
					$('#div_empaque_form_dialog').modal('hide');
					cmb_empaque(data.emp_id);					
	  			<?php }else{?>
					$('.modal').modal('hide');
					$('.in').removeClass('modal-backdrop');			
					empaque_tabla();
				<?php 					
				}?>
				
				
				
				
				
	  		},
	  		complete: function(){
				}
			});
	  });
	
});
	
	
	$("#txt_emp_nom").keypress(function(e){
		if(e.which==13){$("#txt_emp_fac").focus();return false;}
	});
	$("#txt_emp_fac").keydown(function(e){
		if (e.which == 13){$("#save_form_emp").focus();return false;}
	});
	
</script>