<?php
require_once ("../../config/Cado.php");
require_once ("cEmpresa.php");
$oEmpresa = new cEmpresa();
if($_POST['action']=="editar"){
	$dts=$oEmpresa->mostrarUno($_POST['emp_id']);
	$dt = mysqli_fetch_array($dts);
	$ruc=$dt['tb_empresa_ruc'];
	$nomcom=$dt['tb_empresa_nomcom'];
	$razsoc=$dt['tb_empresa_razsoc'];
	$dir=$dt['tb_empresa_dir'];
	$dir2=$dt['tb_empresa_dir2'];
	$tel=$dt['tb_empresa_tel'];
	$ema=$dt['tb_empresa_ema'];
	$fir=$dt['tb_empresa_fir'];
	$rep=$dt['tb_empresa_rep'];		
	mysqli_free_result($dts);
}
?>
				<form role="form" id="for_emp" method="POST">
					<input name="action" id="action" type="hidden" value="<?php echo $_POST['action']?>">
					<input name="hdd_emp_id" id="hdd_emp_id" type="hidden" value="<?php echo $_POST['emp_id']?>">
					<div class="box-header">
						<h3 class="box-title">Información de la Empresa</h3>
					</div>
					<div class="box-body">
						<div class="form-group">
							<div class="row">        
								<div class="col-lg-3 col-xs-6">
									<label for="cmb_mod_id">RUC:</label>
									<input name="txt_emp_ruc" id="txt_emp_ruc" type="text" value="<?php echo $ruc?>" class="form-control" autocomplete="off" maxlength="11"> 
								</div>
								<div class="col-lg-3 col-xs-6">
									<label for="cmb_doc_id">Nombre Comercial:</label>
									<input name="txt_emp_nomcom" id="txt_emp_nomcom" type="text" value="<?php echo htmlspecialchars($nomcom)?>" autocomplete="off" class="form-control" > 
								</div> 
								<div class="col-lg-6 col-xs-6">
									<label for="cmb_doc_id">Razón Social:</label>
									<input name="txt_emp_razsoc" id="txt_emp_razsoc" type="text" value="<?php echo htmlspecialchars($razsoc)?>" autocomplete="off" class="form-control" > 
								</div> 
								<div class="col-lg-12 col-xs-6">
									<label for="cmb_alm_id">Dirección:</label>
									<input name="txt_emp_dir" type="text" id="txt_emp_dir" value="<?php echo htmlspecialchars($dir)?>" autocomplete="off" class="form-control" >  
								</div> 
							</div>
							<div class="row">  
							<div class="col-lg-3 col-xs-6">
								<label for="txt_tal_ser">Dirección 2:</label>
								<input name="txt_emp_dir2" type="text" id="txt_emp_dir2" value="<?php echo htmlspecialchars($dir2)?>" autocomplete="off" class="form-control" > 
							</div> 
							<div class="col-lg-3 col-xs-6">
								<label for="txt_tal_ini">Télefono:</label>
								<input name="txt_emp_tel" type="text" id="txt_emp_tel" value="<?php echo $tel?>" autocomplete="off" class="form-control" >
							</div> 
							<div class="col-lg-3 col-xs-6">
								<label for="txt_tal_fin">E-Mail:</label>
								<input name="txt_emp_ema" type="text" id="txt_emp_ema" value="<?php echo $ema?>"  autocomplete="off" class="form-control" >
							</div> 
							<div class="col-lg-3 col-xs-6">
								<label for="cmb_doc_id">Representante:</label>
								<input name="txt_emp_rep" id="txt_emp_rep" type="text" value="<?php echo $rep?>" autocomplete="off" 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 type="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_emp_nomcom, #txt_emp_razsoc, #txt_emp_dir, #txt_emp_dir2, #txt_emp_rep').change(function()
	{
	$(this).val($(this).val().toUpperCase());
	});
	$("#save_form").click(function() {
		$("#for_emp").submit();
	});
	$(document).ready(function() {
		$('#for_emp').bootstrapValidator({
	      //live: 'disabled',
	      message: 'Valor no Valido',
	      feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },
	      fields: { 	      	      
	      	txt_emp_ruc: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			},
	      			regexp: {
	      				regexp: /^[0-9]+$/,
	      				message: 'Caracteres no permitidos'
	      			}
	      		}
	      	},
	      	txt_emp_nomcom: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	txt_emp_razsoc: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	txt_emp_dir: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	txt_emp_ema: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	},
	      	txt_emp_rep: {
	      		group: '.col-lg-3',
	      		validators: {
	      			notEmpty: {
	      				message: 'Este campo es requerido'
	      			}
	      		}
	      	} 
	      }
	  }).on('success.form.bv', function(e) {
	  	
	  	$.ajax({
				type: "POST",
				url: "../empresa/empresa_reg.php",
				async:true,
				dataType: "html",
				data: $("#for_emp").serialize(),
				beforeSend: function() {
					//toastr["info"]('Guardando...');	
				},
				success: function(html){
				$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');	
				toastr["success"](html);	
				},
				complete: function(){
				//$("#content").load("../empresa/empresa_vista.php");
					empresa_tabla();
				}
			});	
	  });
	});
	$('#txt_emp_ruc').focus();
	$('#txt_emp_ruc').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_nomcom').focus(); return false;}
	});
	$('#txt_emp_nomcom').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_razsoc').focus(); return false;}
	});
	$('#txt_emp_razsoc').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_dir').focus(); return false;}
	});
	$('#txt_emp_dir').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_dir2').focus(); return false;}
	});
	$('#txt_emp_dir2').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_tel').focus(); return false;}
	});
	$('#txt_emp_tel').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_ema').focus(); return false;}
	});
	$('#txt_emp_ema').keypress(function(ev) {
		if(ev.keyCode==13){ $('#txt_emp_rep').focus(); return false;}
	});
	$('#txt_emp_rep').keypress(function(ev) {
		if(ev.keyCode==13){ $('#save_form').focus(); return false;}
	});
	
	
</script>