<?php
require('../cfg/res.php');
require('../cfg/cfg.php');
?>
<script type="text/javascript">
<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>
function _pais(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{
		busca_maes2('pais',document.getElementById('pais').value,'pais','pais_descri','');
		
	}
}

function _ciudad(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{
		busca_maes2('cdad',document.getElementById('ciudad').value,'ciudad','ciudad_descri','');
		
	}
}

function _referidox(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{
		busca_maes2('enti',document.getElementById('dper_txt_ref').value,'dper_txt_ref','dper_txt_ref_descri','');
		
	}

}

function guarda_dper(accion)
{ 

  	var n1=document.getElementById('dper_txt_n1').value;
	var n2=document.getElementById('dper_txt_n2').value;
	var a1=document.getElementById('dper_txt_a1').value;
	var a2=document.getElementById('dper_txt_a2').value;
	var c1=document.getElementById('dper_txt_c1').value;
 	var c2=document.getElementById('dper_txt_c2').value;
	var c3=document.getElementById('dper_txt_c3').value;
	var cn=document.getElementById('dper_txt_cn').value;
	var ref=document.getElementById('dper_txt_ref').value;
	var e1=document.getElementById('dper_txt_e1').value;
 	var t1=document.getElementById('dper_txt_t1').value;
	var ciudad=document.getElementById('ciudad').value;
	var pais=document.getElementById('pais').value;
 	var nik=document.getElementById('dper_txt_nik').value;
	var fn=document.getElementById('dper_txt_fn').value;
	var rs=document.getElementById('dper_txt_rs').value;
	var nc=document.getElementById('dper_txt_nc').value;

	var cix=document.getElementById('dper_txt_ci').value;
	var valx = cix.substring(2, 3);
	n1=n1.trim();
	
    if(n1.length<2 && valx < 6)

	{

		document.getElementById('dper_err_n1').innerHTML='*Obligatorio';
		return false;
	}
	else
	{

		document.getElementById('dper_err_n1').innerHTML='';
	}

	a1=a1.trim();
	if(a1.length<2 && valx < 6)
	{
		document.getElementById('dper_err_a1').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_err_a1').innerHTML='';
	}

	c1=c1.trim();
	if(c1.length<2)
	{
		c1='-';
		//document.getElementById('dper_err_c1').innerHTML='*Obligatorio';
		//return false;
	}
	else
	{
		document.getElementById('dper_err_c1').innerHTML='';
	}
	c2=c2.trim();
	if(c2.length<1)
	{
		c2='-';
		//document.getElementById('dper_err_c2').innerHTML='*Obligatorio';
		//return false;
	}
	else
	{
		document.getElementById('dper_err_c2').innerHTML='';
	}

	c3=c3.trim();
	if(c3.length<1)
	{
		c3='-';
		//document.getElementById('dper_err_c3').innerHTML='*Obligatorio';
		//return false;
	}
	else
	{
		document.getElementById('dper_err_c3').innerHTML='';
	}
	
	e1=e1.trim();
	if(e1.length<2)
	{
		e1=n1+'@'+a1+'.com';
		document.getElementById('dper_txt_e1').value=e1;
		//document.getElementById('dper_err_e1').innerHTML='*Obligatorio';
		//return false;
	}
	else
	{
		document.getElementById('dper_err_e1').innerHTML='';
	}
	t1=t1.trim();
	if(t1.length<2)
	{
		t1='000000';
		document.getElementById('dper_txt_t1').value=t1;
		//document.getElementById('dper_err_t1').innerHTML='*Obligatorio';
		//return false;
	}
	else
	{
		document.getElementById('dper_err_e1').innerHTML='';
	}
	
	nik=nik.trim();
	if(nik.length!=0)
	{
		//document.getElementById('dper_err_t1').innerHTML='*Obligatorio';
		//return false;
	}

	
		
		if(accion=='M')
		{
			guarda_dperc();
			
		}
			
		if(accion=='N')
		{	
			guarda_dperd();
		}
	
		
}

function limpia()
{


document.getElementById('dper_txt_ci').value='';
document.getElementById('dper_txt_n1').value='';
document.getElementById('dper_txt_n2').value='';
document.getElementById('dper_txt_a1').value='';
document.getElementById('dper_txt_a2').value='';
document.getElementById('dper_txt_c1').value='';
document.getElementById('dper_txt_c2').value='';
document.getElementById('dper_txt_c3').value='';
document.getElementById('dper_txt_cn').value='';
document.getElementById('dper_txt_e1').value='';
document.getElementById('dper_txt_t1').value='';
document.getElementById('dper_txt_nik').value='';
document.getElementById('dper_txt_fn').value='';
document.getElementById('dper_txt_rs').value='';
document.getElementById('dper_txt_nc').value='';
document.getElementById('dper_txt_ref').value='';
document.getElementById('pais').value='';
document.getElementById('ciudad').value='';
document.getElementById('dper_err_n1').innerHTML='';
document.getElementById('dper_err_n2').innerHTML='';
document.getElementById('dper_err_a1').innerHTML='';
document.getElementById('dper_err_a2').innerHTML='';
document.getElementById('dper_err_rs').innerHTML='';
document.getElementById('dper_err_nc').innerHTML='';
document.getElementById('dper_err_fn').innerHTML='';
document.getElementById('dper_err_nik').innerHTML='';
document.getElementById('pais_descri').innerHTML='';
document.getElementById('ciudad_descri').innerHTML='';
document.getElementById('dper_txt_ref_descri').innerHTML='';



}

function guarda_dperd()
{
	
	
	document.body.style.cursor='wait';
	var ci=document.getElementById('dper_txt_ci').value;
  	var n1=document.getElementById('dper_txt_n1').value;
	var n2=document.getElementById('dper_txt_n2').value;
	var a1=document.getElementById('dper_txt_a1').value;
	var a2=document.getElementById('dper_txt_a2').value;
	var c1=document.getElementById('dper_txt_c1').value;
 	var c2=document.getElementById('dper_txt_c2').value;
	var c3=document.getElementById('dper_txt_c3').value;
	var cn=document.getElementById('dper_txt_cn').value;
	var ref=document.getElementById('dper_txt_ref').value;
	var e1=document.getElementById('dper_txt_e1').value;
 	var t1=document.getElementById('dper_txt_t1').value;
	var ciudad=document.getElementById('ciudad').value;
	var pais=document.getElementById('pais').value;
 	var nik=document.getElementById('dper_txt_nik').value;
	var fn=document.getElementById('dper_txt_fn').value;
	var rs=document.getElementById('dper_txt_rs').value;
	var nc=document.getElementById('dper_txt_nc').value;
	fn=fecha_format(fn);
	
	var descri=a1+' '+a2+' '+n1+' '+n2;

	var error_dper='';
	$.ajax({
		url:'../lib/dper_d.php',
		type:'POST',
		data:{ci:ci,n1:n1,n2:n2,a1:a1,a2:a2,c1:c1,c2:c2,cn:cn,c3:c3,e1:e1,t1:t1,ref:ref,pais:pais,ciudad:ciudad,nik:nik,fn:fn,rs:rs,nc:nc,descri:descri},
		success:function(dato)
		{
			console.log(dato);
			document.body.style.cursor='auto';
			error_dper=$(dato).find("error").text();
			if(error_dper=='0')
			{
				alert('Datos Personales Ingresados');
				lista_enti();
				limpia();
			}
			else
			{
				alert('Ocurrio un Error al Registrar');
				
			}
		}, 
		error:function(objeto)
		{
			console.log(objeto);
			//alert('Archivo No Encontrado');
		}
	});
	//document.getElementById('dper_btn_n').disabled=false;
	document.body.style.cursor='auto';


}



function guarda_dperc()
{
	
	
	document.body.style.cursor='wait';
	var ci=document.getElementById('dper_txt_ci').value;
	var n1=document.getElementById('dper_txt_n1').value;
	var n2=document.getElementById('dper_txt_n2').value;
	var a1=document.getElementById('dper_txt_a1').value;
	var a2=document.getElementById('dper_txt_a2').value;
	var c1=document.getElementById('dper_txt_c1').value;
 	var c2=document.getElementById('dper_txt_c2').value;
	var c3=document.getElementById('dper_txt_c3').value;
	var cn=document.getElementById('dper_txt_cn').value;
	var ref=document.getElementById('dper_txt_ref').value;
	var e1=document.getElementById('dper_txt_e1').value;
 	var t1=document.getElementById('dper_txt_t1').value;
	var ciudad=document.getElementById('ciudad').value;
	var pais=document.getElementById('pais').value;
 	var nik=document.getElementById('dper_txt_nik').value;
	var fn=document.getElementById('dper_txt_fn').value;
	var rs=document.getElementById('dper_txt_rs').value;
	var nc=document.getElementById('dper_txt_nc').value;
	fn=fecha_format(fn);
	var descri=a1+' '+a2+' '+n1+' '+n2;

	$.ajax({
		url:'../lib/dper_c.php',
		type:'POST',
		data:{ci:ci,n1:n1,n2:n2,a1:a1,a2:a2,c1:c1,c2:c2,cn:cn,c3:c3,e1:e1,t1:t1,ref:ref,ciudad:ciudad,pais:pais,nik:nik,fn:fn,rs:rs,nc:nc,descri:descri},
		success:function(dato)
		{
			document.body.style.cursor='auto';
			if(dato=='0')
			{
				alert('Datos Personales Actualizados');
				limpia();
				lista_enti();
				document.getElementById('dper_txt_ci').disabled=false;
				document.getElementById('dper_btn_m').style.display='none';
				document.getElementById('dper_btn_c').style.display='none';
				document.getElementById('dper_btn_n').style.display='block';
			}
			else
			{
				console.log(dato);
			}
		}, 
		error:function(objeto)
		{
			console.log(objeto);
			//alert('Archivo No Encontrado');
		}
	});
	
	document.body.style.cursor='auto';


}

function edit_e(cie)
{
	limpia();
	$.ajax({
		url:'dper_e.php',
		async:false,
		type:'POST', 
		data:{ci:cie},
		beforeSend: function(){},
		success: function(dato){
				//document.getElementById('carga_h_enti').innerHTML=data;
				console.log(dato);
				document.getElementById('dper_txt_ci').value=cie;
				document.getElementById('dper_txt_n1').value=$(dato).find("n1").text();
				document.getElementById('dper_txt_n2').value=$(dato).find("n2").text();
				document.getElementById('dper_txt_a1').value=$(dato).find("a1").text();
				document.getElementById('dper_txt_a2').value=$(dato).find("a2").text();
				document.getElementById('dper_txt_rs').value=$(dato).find("rs").text();
				document.getElementById('dper_txt_nc').value=$(dato).find("nc").text();
				document.getElementById('dper_txt_fn').value=$(dato).find("fn").text();
				document.getElementById('dper_txt_nik').value=$(dato).find("nick").text();
				document.getElementById('dper_txt_c1').value=$(dato).find("c1").text();
				document.getElementById('dper_txt_c2').value=$(dato).find("c2").text();
				document.getElementById('dper_txt_cn').value=$(dato).find("cn").text();
				document.getElementById('dper_txt_c3').value=$(dato).find("c3").text();
				document.getElementById('dper_txt_e1').value=$(dato).find("e1").text();
				document.getElementById('dper_txt_t1').value=$(dato).find("t1").text();
				document.getElementById('dper_txt_ref').value=$(dato).find("ref").text();
				document.getElementById('pais').value=$(dato).find("pais").text();
				document.getElementById('ciudad').value=$(dato).find("ciudad").text();
				document.getElementById('ciudad_descri').innerHTML=$(dato).find("ciudad_descri").text();
				document.getElementById('dper_txt_ci').disabled=true;
				document.getElementById('dper_btn_m').style.display='block';
				document.getElementById('dper_btn_c').style.display='block';
				document.getElementById('dper_btn_n').style.display='none';
				
			},
		error: function(err_e){ console.log(err_e);},
		timeout: 60000
		
		
		
		});

}

function lista_enti()
{
	
	
	
	$.ajax({
		cache:false,
		url:'denti3.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{}, 
    	beforeSend: function(jqXHR, textStatus)
		{
				document.getElementById('carga_e_enti').innerHTML='Actualizando Datos...';
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
		
						document.getElementById('carga_e_enti').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('carga_e_enti').innerHTML='Not connect: Verify Network.';
           } else if (jqXHR.status == 404) {
               document.getElementById('carga_e_enti').innerHTML='Requested page not found [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('carga_e_enti').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('carga_e_enti').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
               document.getElementById('carga_e_enti').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('carga_e_enti').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('carga_e_enti').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
 
			}           
		},
		timeout:1200000
	});

}


function cancela_dper()
{
	document.getElementById('dper_txt_ci').disabled=false;
	document.getElementById('dper_btn_m').style.display='none';
	document.getElementById('dper_btn_c').style.display='none';
	document.getElementById('dper_btn_n').style.display='block';
	limpia();

}

</script>

<div align="left" id="cont_n_enti">
<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px;" >
<tr valign="top">
<td>
<!--+++++ -->
<table border="0" cellpadding="2" cellspacing="0" style=" font-size:12px; font-weight:bolder;">
<tr>
	<td>CI/RUC:</td>
    <td><input type="text" id="dper_txt_ci" class="dper_txt" maxlength="45"   title="CI /RUC"   /></td>
    <td><span id="dper_err_ci" class="dper_err"></span></td>
</tr>

<tr align="left">
	<td>PRIMER NOMBRE:</td>
    <td><input type="text" id="dper_txt_n1" class="dper_txt" maxlength="20"  /></td>
    <td width="50"><span id="dper_err_n1" class="dper_err"></span></td>
</tr>
<tr>
	<td>SEGUNDO NOMBRE:</td>
    <td><input type="text" id="dper_txt_n2" class="dper_txt" maxlength="20"  /></td>
    <td><span id="dper_err_n2" class="dper_err"></span></td>
</tr>
<tr>
	<td>APELLIDO PATERNO:</td>
    <td><input type="text" id="dper_txt_a1" class="dper_txt" maxlength="20"   /></td>
    <td><span id="dper_err_a1" class="dper_err"></span></td>
</tr>


<tr>
	<td>APELLIDO MATERNO:</td>
    <td><input type="text" id="dper_txt_a2" class="dper_txt" maxlength="20"   /></td>
    <td><span id="dper_err_a2" class="dper_err"></span></td>
</tr>

<tr>
	<td>RAZON SOCIAL:</td>
    <td><input type="text" id="dper_txt_rs" class="dper_txt" maxlength="49"   /></td>
    <td><span id="dper_err_rs" class="dper_err"></span></td>
</tr>

<tr>
	<td>NOMBRE COMERCIAL:</td>
    <td><input type="text" id="dper_txt_nc" class="dper_txt" maxlength="20"   /></td>
    <td><span id="dper_err_nc" class="dper_err"></span></td>
</tr>

<tr>
	<td>FECHA NAC.(aaaa-mm-dd):</td>
    <td><input type="date" id="dper_txt_fn" class="dper_txt" maxlength="20"   /></td>
    <td><span id="dper_err_fn" class="dper_err"></span></td>
</tr>

<tr>
	<td>PSEUDONIMO (NICK):</td>
    <td><input type="text" id="dper_txt_nik" class="dper_txt" maxlength="20"   /></td>
    <td><span id="dper_err_nik" class="dper_err"></span></td>
</tr>




</table>
<!--+++++ -->
</td>
<td>
<!--+++++ -->

<table border="0" cellpadding="2" cellspacing="0" style=" font-size:12px; font-weight:bolder;">

<tr>
	<td><input type="button" id="pais_btn" value="PAIS:" onClick="list_carga('pais','pais','pais_descri');" /></td>
    <td><input type="text" id="pais" onKeyDown="_pais(event);" /></td>
    <td><span id="pais_descri" style="font-weight:bold; height:25px;"></span></td>
</tr>

<tr>
	<td><input type="button" id="ciudad_btn" value="PROV /CIUDAD:" onClick="list_carga('cdad','ciudad','ciudad_descri');" /></td>
    <td><input type="text" id="ciudad" onKeyDown="_ciudad(event);" /> </td>
    <td><span id="ciudad_descri" style="font-weight:bold; height:25px;"></span></td>
</tr>

<tr>
	<td>CALLE 1 /CDLA. /EDIF.</td>
    <td><input type="text" id="dper_txt_c1" class="dper_txt" maxlength="20"   /></td>
    <td width="50"><span id="dper_err_c1" class="dper_err"></span></td>
</tr>

<tr>
	<td>CALLE 2 /MZ /PISO </td>
    <td><input type="text" id="dper_txt_c2" class="dper_txt" maxlength="20"    /></td>
    <td><span id="dper_err_c2" class="dper_err"></span></td>
</tr>

<tr>
	<td>NUM. /VILLA /DPTO</td>
    <td><input type="text" id="dper_txt_cn" class="dper_txt" maxlength="20"    /></td>
    <td><span id="dper_err_cn" class="dper_err"></span></td>
</tr>

<tr>
	<td>REFERENCIA(casa):</td>
    <td><input type="text" id="dper_txt_c3" class="dper_txt" maxlength="20"    /></td>
    <td><span id="dper_err_c3" class="dper_err"></span></td>
</tr>

<tr>
	<td>EMAIL:</td>
    <td><input type="text" id="dper_txt_e1" class="dper_txt" maxlength="45"    /></td>
    <td><span id="dper_err_e1" class="dper_err"></span></td>
</tr>

<tr>
	<td>TEL. CONVENCIONAL:</td>
    <td><input type="text" id="dper_txt_t1" class="dper_txt" maxlength="20"    /></td>
    <td><span id="dper_err_t1" class="dper_err"></span></td>
</tr>

<tr style=" <?php if(!mb_stristr('gnya.gmny.demo',$empr_codigo)){echo 'display:none;';}?>">
	<td><input type="button" id="pais_btn" value="REFERIDO X:" onClick="list_carga('enti','dper_txt_ref','dper_txt_ref_descri');" /></td>
    <td><input type="text" id="dper_txt_ref" class="dper_txt" onKeyDown="_referidox(event);" value="<?php echo $empr_ruc;?>" maxlength="20"    /></td>
    <td><span id="dper_txt_ref_descri"><?php echo $empr_nomcom;?></span></td>
</tr>

</table>


<!--+++++ -->



</td>
</tr>
</table>
</div>

<div>
<input type="button" value="Guardar" onclick="guarda_dper('N');" id="dper_btn_n"/>
<input type="button" value="Guardar" onclick="guarda_dper('M');" id="dper_btn_m" style="display:none;" />
<input type="button" value="Cancelar" onclick="cancela_dper();" id="dper_btn_c" style="display:none;" />
</div>

<div id="carga_e_enti"><?php require('../../_lib/denti3.php');?></div>
<div id="carga_h_enti"></div>

<div id="lista_temporal_contenedor" style=" display:none; padding:0px; margin:0px; background: #666; opacity:0.5; width:100%; min-height: 100%; height:auto !important;position: fixed;top:0;left:0; z-index:1;" ></div>
<div id="lista_cargador" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10;" ><img src="../img/ajax-loader.gif" /></div>    
<div id="lista_temporal" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10; overflow-y:scroll; min-height:50px; max-height:400px; width:100%;" ><img src="../img/ajax-loader.gif" /></div>    


