<?php
require_once ("../../config/Cado.php");
require_once ("cPresentacion.php");
$oPresentacion = new cPresentacion();


if($_POST['action']=="insertar")
{
	$pre_nom=$_POST['pre_nom'];
}
if($_POST['action']=="editar"){
	$dts=$oPresentacion->mostrarUno($_POST['pre_id']);
	$dt = mysqli_fetch_array($dts);
	$pre_nom=$dt['tb_presentacion_nom'];
	mysqli_free_result($dts);
}
?>
				<form role="form" id="for_pre" method="POST">
						<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
						<input name="hdd_pre_id" id="hdd_pre_id" type="hidden" value="<?php echo $_POST['pre_id']?>">
						
					<div class="box-header">
						<h3 class="box-title">Información de la Presentacion</h3>
					</div>
					<div class="box-body">
					<div class="form-group">							
							<div class="row">
								<div class="col-lg-12 col-sm-12 col-xs-12">
									<label for="txt_pre_nom">Nombre:</label>
									<input name="txt_pre_nom" id="txt_pre_nom" type="text" autocomplete="off" value="<?php echo $pre_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="save_form_pre">Guardar</button>
			</div>
		
<script type="text/javascript">
	
	
	$('#txt_pre_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	
		
	$("#save_form_pre").click(function() {
		$("#for_pre").submit();
	});

	$(document).ready(function() {
		$('#for_pre').bootstrapValidator({
	      //live: 'disabled',
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {	      	
	      	txt_pre_nom: {
	      		group: '.col-xs-6',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {
	  	
	  	$.ajax({
	  		type: "POST",
	  		url: "../presentacion/presentacion_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_pre").serialize(),
	  		beforeSend: function() {
	  			
	  		},
	  		success: function(data){	
				
				toastr["success"](data.pre_msj);
				
				<?php if($_POST['vista']=="producto"){?>
				$('#div_presentacion_form_dialog').modal('hide');
					cmb_pre_id(data.pre_id);					
	  			<?php }else{?>
					$('.modal').modal('hide');
					$('.in').removeClass('modal-backdrop');			
					presentacion_tabla();			
				<?php 					
				}?>
			
	  		},
	  		complete: function(){
				}
			});
	  });
	
});
	
	
	$("#txt_pre_nom").keypress(function(e){
		if(e.which==13){$("#save_form_pre").focus();return false;}
	});
	
	
</script>