<?php
require_once ("../../config/Cado.php");
require_once ("cCancha.php");
$oCancha = new cCancha();

if($_POST['action']=="editar")
{
	$id = $_POST['cancha_id'];
	$dtscancha =  $oCancha->MostrarUno($id);
	$dts = mysqli_fetch_array($dtscancha);
	$sal_id=$dts['tb_salon_id'];
	$mes_nom=$dts['tb_cancha_nom'];
	
	mysqli_free_result($dtscancha);
}
else if($_POST['vista']=='cancha_tabla'){
	$sal_id=$_POST['salon_id'];
}
?>

				<form  id="for_cancha" > 
						<input name="action_cancha" id="action_cancha" type="hidden" value="<?php echo $_POST['action']?>">
						<input name="hdd_cancha_id" id="hdd_cancha_id" type="hidden" value="<?php echo $_POST['cancha_id']?>">

					<div class="box-header">
						<h3 class="box-title">Información de la cancha</h3>
					</div>
					<div class="box-body">

						<div class="form-group">							
							<div class="row">
								<div class="col-lg-4 col-xs-12">
									<label for="txt_cancha_nom">Nombre:</label>
									<input name="txt_cancha_nom" type="text" id="txt_cancha_nom" value="<?php echo $mes_nom; ?>"  maxlength="25" class="form-control" > 
								</div>
								<div class="col-lg-8 col-xs-12">
									<label for="cmb_salon_id">Piso:</label>
									<select name="cmb_salon_id" id="cmb_salon_id" class="form-control  input-sm">	</select>  
								</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">

	function cmb_salon_id(ids)
	{	
		$.ajax({
			type: "POST",
			url: "../piso/cmb_salon_id.php",
			async:true,
			dataType: "html",                      
			data: ({
				salon_id: ids
			}),
			beforeSend: function() {
				$('#cmb_salon_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_salon_id').html(html);
			}
		});
	}

	cmb_salon_id(<?php echo $sal_id; ?>);

	$('#txt_cancha_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});


	$("#save_form").click(function() {
		$("#for_cancha").submit();
	});
	
	$('#txt_cancha_nom').focus();

	$('#txt_cancha_nom').keydown(function(ev) {
		if(ev.keyCode==13){$('#cmb_salon_id').focus(); return false;}
	});
	$('#cmb_salon_id').keydown(function(ev) {
		if(ev.keyCode==13){$('#btn_for_cancha_guardar').focus(); return false;}
	});

	
	$('#for_cancha').bootstrapValidator({
	     
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },  
	      fields: {	       	
	      	txt_cancha_nom: {
	      		group: '.col-lg-6',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {
		  
	  	$.ajax({
	  		type: "POST",
	  		url: "../cancha/cancha_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_cancha").serialize(),
	  		beforeSend: function() {					 
	  			
	  		},
	  		success: function(data){	
			$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');			
				toastr["success"](data.cancha_msj);	
	  		},
	  		complete: function(){
	  				cancha_tabla(<?php echo $sal_id; ?>);	
	  		}
	  	}); 

	  });
	
</script>