<?php
require_once ("../../config/Cado.php");
require_once ("cDocumento.php");
$oDocumento = new cDocumento();

if($_POST['action']=="editar")
{
	$dts=$oDocumento->mostrarUno($_POST['doc_id']);
	$dt = mysqli_fetch_array($dts);
	$mod_id=$dt['tb_modulo_id'];
	$doc_abr=$dt['tb_documento_abr'];
	$doc_nom=$dt['tb_documento_nom'];
	$doc_def=$dt['tb_documento_def'];
	$imp_id=$dt['tb_impresora_id'];
	mysqli_free_result($dts);
}
?>
				<form role="form" id="for_doc" method="POST">

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

					<div class="box-header">
						<h3 class="box-title">Información del Documento</h3>
					</div>
					<div class="box-body">

						<div class="form-group">							
							<div class="row">
								<div class="col-lg-2 col-xs-6 ">
									<label for="cmb_mod_id">Modulo:</label>
									<select name="cmb_mod_id" id="cmb_mod_id"  class="form-control"></select>
								</div>
								<div class="col-lg-2 col-xs-6">
									<label for="txt_doc_abr">Abreviatura:</label>
									<input name="txt_doc_abr" type="text" id="txt_doc_abr" value="<?php echo $doc_abr?>" autocomplete="off" maxlength="5" class="form-control">
								</div>
								<div class="col-lg-4 col-xs-6">
									<label for="txt_doc_nom">Nombre:</label>
									<input name="txt_doc_nom" type="text" id="txt_doc_nom" value="<?php echo $doc_nom?>" autocomplete="off" maxlength="50"class="form-control">
								</div>
								<div class="col-lg-4 col-xs-6 checkbox">
									<label for="">&nbsp;</label> <br>
									<label>
										<input name="chk_doc_def"  type="checkbox" id="chk_doc_def" value="1" <?php if($doc_def==1)echo 'checked'?> title="Indica si es documento por defecto">Mostrar por defecto
									</label>
								</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>
			
						
<!--
<section class="content" id="form">
	<div class="row">
		<div class="col-xs-12">
			<div class="box box-info">
			
			</div>
		</div>
	</div>
</section>
-->


<script type="text/javascript">


	$('#txt_doc_abr, #txt_doc_nom').change(function(){
		$(this).val($(this).val().toUpperCase());
	});

	$("#save_form").click(function() {
		$("#for_doc").submit();
	});

	function cmb_mod_id()
	{	
		$.ajax({
			type: "POST",
			url: "../modulo/cmb_mod_id.php",
			async : true,
			dataType: "html",                      
			data: ({
				mod_id: '<?php echo $mod_id?>'
			}),
			beforeSend: function() {
				$('#cmb_mod_id').html('<option value="">Cargando...</option>');
			},
			success: function(html){
				$('#cmb_mod_id').html(html);
			}
		});
	}

	
		$('#for_doc').bootstrapValidator({
	      //live: 'disabled',
	      message: 'Valor no valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: {	     	
	      	cmb_mod_id: {
	      		group: '.col-lg-2',
	      		validators: {
	      			notEmpty: {
	      				message: 'Campo requerido'
	      			}
	      		}
	      	},
	      	txt_doc_abr: {
	      		group: '.col-lg-2',
	      		validators: {
	      			notEmpty: {
	      				message: 'Campo requerido'
	      			}
	      		}
	      	},
	      	txt_doc_nom: {
	      		group: '.col-lg-2',
	      		validators: {
	      			notEmpty: {
	      				message: 'Campo requerido'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) {

	  	$.ajax({
	  		type: "POST",
	  		url: "../documento/documento_reg.php",
	  		async:true,
	  		dataType: "html",
	  		data: $("#for_doc").serialize(),
	  		beforeSend: function() {
					
				},
				success: function(html){
				$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');			
				toastr["success"](html);	
				},
				complete: function(){
					documento_tabla();
				}
			}); 

	  });

	// EJECUTAR APENAS CARGUE

	
	cmb_mod_id();
	
	$("#cmb_mod_id").focus(); 

	
	/*$("#txt_cli_doc").autoNumeric({
		aSep:'',
		vMin:'',
		vMax:'99999999999'
	});*/

	

	$("#cmb_mod_id").keydown(function(e){
		if (e.which == 13){$("#txt_doc_abr").focus();return false;}
	});

	$("#txt_doc_abr").keypress(function(e){
		if(e.which==13){$("#txt_doc_nom").focus();;return false;}
	});

	$("#txt_doc_nom").keypress(function(e){
		if(e.which==13){$("#cmb_imp_id").focus();;return false;}
	});

	$("#cmb_imp_id").keydown(function(e){
		if (e.which == 13){$("#save_form").focus();return false;}
	});

	
</script>