<?php

require_once ("../../config/Cado.php");

require_once ("cTarjeta.php");

$oTarjeta = new cTarjeta();



if($_POST['action']=="editar")

{

	$dts=$oTarjeta->mostrarUno($_POST['tar_id']);

	$dt = mysql_fetch_array($dts);

	$tar_nom	=$dt['tb_tarjeta_nom'];

	$caj_id		=$dt['tb_caja_id'];

	mysql_free_result($dts);

}

?>



				<form role="form" id="for_tar" method="POST"> 

					<input name="action_tarjeta" id="action_tarjeta" type="hidden" value="<?php echo $_POST['action']?>">

					<input name="hdd_tar_id" id="hdd_tar_id" type="hidden" value="<?php echo $_POST['tar_id']?>">



					<div class="box-header">

						<h3 class="box-title">Información de la Tarjeta</h3>

					</div>

					<div class="box-body">



						<div class="form-group">							

							<div class="row">

								<div class="col-lg-6 col-xs-6">

									<label for="txt_tar_nom">Nombre:</label>

									<input name="txt_tar_nom" type="text" id="txt_tar_nom" value="<?php echo $tar_nom?>" maxlength="50" class="form-control" > 

								</div>

								<div class="col-lg-4 col-xs-6">

									<label for="cmb_caj_id">Caja:</label>

									<select name="cmb_caj_id" id="cmb_caj_id" class="form-control"></select>

								</div>

							</div>

						</div>

					</div>

				</form>

				<div class="box-footer pull-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">



	function cmb_caj_id(ids)

	{	

		$.ajax({

			type: "POST",

			url: "../caja/cmb_caj_id.php",

			async:true,

			dataType: "html",                      

			data: ({

				caj_id: ids

			}),

			beforeSend: function() {

				$('#cmb_caj_id').html('<option value="">Cargando...</option>');

			},

			success: function(html){

				$('#cmb_caj_id').html(html);

			}

		});

	}



	cmb_caj_id(<?php echo $caj_id?>);



	$('#txt_tar_nom').change(function(){

		$(this).val($(this).val().toUpperCase());

	});



	

	$("#save_form").click(function() {

		$("#for_tar").submit();

	});



	$(document).ready(function() {

		$('#for_tar').bootstrapValidator({

	      message: 'Valor no valido',

	      feedbackIcons: {

	      	valid: 'glyphicon glyphicon-ok',

	      	invalid: 'glyphicon glyphicon-remove',

	      	validating: 'glyphicon glyphicon-refresh'

	      },

	      fields: {	        	

	      	txt_tar_nom: {

	      		group: '.col-lg-6',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	},

	      	cmb_caj_id: {

	      		group: '.col-lg-4',

	      		validators: {

	      			notEmpty: {

	      				message: 'Este campo es requerido'

	      			}

	      		}

	      	}

	      }

	  }).on('success.form.bv', function(e) {



	  	$.ajax({

	  		type: "POST",

	  		url: "../tarjeta/tarjeta_reg.php",

	  		async:true,

	  		dataType: "json",

	  		data: $("#for_tar").serialize(),

	  		beforeSend: function() { 

	 

	  		},

	  		success: function(data){	

	  			$('.modal').modal('hide');

				$('.in').removeClass('modal-backdrop');			

				toastr["success"](data.tar_msj);	

				

	  			<?php

	  			if($_POST['vista']=="cmb_tar_id")

	  			{

	  				echo $_POST['vista'].'(data.tar_id)';

	  			}

	  			?>

	  		},

	  		complete: function(){

	  			<?php

	  			if($_POST['vista']=="tarjeta_tabla")

	  			{

	  				echo $_POST['vista'].'()';

	  			}

	  			?>

	  		}

	  	});



	  });



	  $('#txt_tar_nom').focus();



	  $('#txt_tar_nom').keydown(function(ev) {

	  	if(ev.keyCode==13){$('#cmb_caj_id').focus(); return false;}

	  });

	  $('#cmb_caj_id').keydown(function(ev) {

	  	if(ev.keyCode==13){$('#save_form').focus(); return false;}

	  }); 





	});	

</script>