<?php
require_once ("../../config/Cado.php");
require_once ("cMoneda.php");
$oMoneda = new cMoneda();
if($_POST['action']=="editar")
{
	$dts=$oMoneda->mostrarUno($_POST['mon_id']);
	$dt = mysqli_fetch_array($dts);
	$nom=$dt['tb_moneda_nom'];
	$sim=$dt['tb_moneda_sim'];
	mysqli_free_result($dts);
}
?>
			
				<form role="form" id="for_mon" method="POST"> 
					<input name="action_moneda" id="action_moneda" type="hidden" value="<?php echo $_POST['action']?>">
					<input name="hdd_mon_id" id="hdd_mon_id" type="hidden" value="<?php echo $_POST['mon_id']?>">
					<div class="box-header">
						<h3 class="box-title">Información de la Moneda</h3>
					</div>
					<div class="box-body">
						<div class="form-group">							
							<div class="row">
								<div class="col-lg-4 col-xs-6">
									<label for="txt_mon_sim">Simbolo:</label>
									<input name="txt_mon_sim" type="text" id="txt_mon_sim" value="<?php echo $sim?>"  maxlength="10" class="form-control" > 
								</div>
								<div class="col-lg-5 col-xs-6">
									<label for="txt_mon_nom">Moneda:</label>
									<input name="txt_mon_nom" type="text" id="txt_mon_nom" value="<?php echo $nom?>"  maxlength="50" 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">Guardar</button> 
				</div>
			
<script type="text/javascript">
	
	$('#txt_mon_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});
	$("#save_form").click(function() {
		$("#for_mon").submit();
	});
	$(document).ready(function() {
		
		$('#for_mon').bootstrapValidator({
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },  
	      fields: {	       	
	      	txt_mon_sim: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	txt_mon_nom: {
	      		group: '.col-lg-5',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {
	  $.ajax({
	  		type: "POST",
	  		url: "../moneda/moneda_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_mon").serialize(),
	  		beforeSend: function() {					 
	  			
	  		},
	  		success: function(data){	
	  			$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');			
				toastr["success"](data.mon_msj);				
	  		
	  			<?php
	  			if($_POST['vista']=="cmb_mon_id")
	  			{
	  				echo $_POST['vista'].'(data.mon_id)';
	  			}
	  			?>
	  		},
	  		complete: function(){
	  			<?php
	  			if($_POST['vista']=="moneda_tabla")
	  			{
	  				echo $_POST['vista'].'()';
	  			}
	  			?>
	  		}
	  	}); 
	  });
	  $('#txt_mon_sim').focus();	 
	  $('#txt_mon_sim').keydown(function(ev) {
	  	if(ev.keyCode==13){ $('#txt_mon_nom').focus(); return false;}
	  });
	  $('#txt_mon_nom').keydown(function(ev) {
	  	if(ev.keyCode==13){ $('#save_form').focus(); return false;}
	  });
	});	
</script>