<?php
require('../cfg/res.php');
require('../../_lib/select.php');
$sql_enti='select *from enti0 where enti_codigo="'.$_SESSION['user_vcrx_id'].'"';



$res_enti=mysql_query($sql_enti,$link_vcrx);

	$n1='';
	$n2='';
	$a1='';
	$a2='';
	$fn='';
	$nik='';
	$c1='';
	$c2='';
	$c3='';
	$c4='';
	$cn='';
	$e1='';
	$t1='';
	$t2='';
	$ref='';
	$pai='';
	$ciu='';
	$cod='';
	$struc='';
	

if(mysql_num_rows($res_enti)!=0)
{
$n1=mysql_result($res_enti,0,'enti_nom1');
$n2=mysql_result($res_enti,0,'enti_nom2');
$a1=mysql_result($res_enti,0,'enti_ape1');
$a2=mysql_result($res_enti,0,'enti_ape2');
$fn=mysql_result($res_enti,0,'enti_fechanac');
$nik=mysql_result($res_enti,0,'enti_nickname');
$c1=mysql_result($res_enti,0,'enti_calle1');
$c2=mysql_result($res_enti,0,'enti_calle2');
$c3=mysql_result($res_enti,0,'enti_calle3');
$c4=mysql_result($res_enti,0,'enti_callen');
$cn=mysql_result($res_enti,0,'enti_callen');
$e1=mysql_result($res_enti,0,'enti_email');
$t1=mysql_result($res_enti,0,'enti_telefono');
$ref=mysql_result($res_enti,0,'enti_referidox');
$pai=mysql_result($res_enti,0,'enti_pais');
$ciu=mysql_result($res_enti,0,'enti_cdad');
$cod=mysql_result($res_enti,0,'enti_codigo');
$struc=mysql_result($res_enti,0,'enti_struc');

//$t2=mysql_result($res_enti,0,'enti_');

}

?>
<div align="left">
<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 align="left">
	<td><span>PRIMER NOMBRE:</span></td>
    <td><input type="text" id="dper_txt_n1" class="dper_txt" maxlength="20" value="<?php echo $n1;?>" /></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" value="<?php echo $n2;?>"  /></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" value="<?php echo $a1;?>"  /></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" value="<?php echo $a2;?>"  /></td>
    <td><span id="dper_err_a2" class="dper_err"></span></td>
</tr>

<tr>
	<td>FECHA DE NACIMIENTO(aaaa-mm-dd):</td>
    <td><input type="date" id="dper_txt_fn" class="dper_txt" maxlength="20" value="<?php echo $fn;?>"  /></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" value="<?php echo $nik;?>"  /></td>
    <td><span id="dper_err_nik" class="dper_err"></span></td>
</tr>

<tr>
	<td>DIRECTOR:</td>
    <td>
		<input type="text" id="dper_txt_ref" class="dper_txt" maxlength="45"  value="<?php echo $ref;?>" <?php if(!empty($ref)){echo 'disabled="disabled"';}?> title="Nombre director /CI /email /" />
		<input type="hidden" id="ref_hdd" />
    </td>
    <td><span id="dper_err_ref" class="dper_err"></span></td>
</tr>

<tr>
	<td>CODIGO:</td>
    <td>
		<input type="text" id="dper_txt_cod" class="dper_txt" maxlength="45"  value="<?php echo $cod;?>" <?php if(!empty($ref)){echo 'disabled="disabled"';}?> title="CI" />
		
    </td>
    <td><span id="dper_err_ref" class="dper_err"></span></td>
</tr>


<tr>
	<td>ESTATUS RUC:</td>
    <td>
		<select id="dper_txt_struc">
        	<option value="-" <?php if($struc!='A' && $struc!='S'){ echo 'selected="selected"';} ?> >N/A</option>
            <option value="A" <?php if($struc=='A'){ echo 'selected="selected"';} ?> >Activo</option>
            <option value="S" <?php if($struc=='S'){ echo 'selected="selected"';} ?> >Suspendido</option>
        </select>
		
    </td>
    <td><span id="dper_err_ref" 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>PAIS:</td>
    <td>
    	<?php
			$pais=new select();
		?>
        <select id="pais" name="pais"  style="font-size:10px;border: #535353 solid 1px;">
        <?php $pais->select_simple('../cfg/res.php',$pai,'select pais_codigo,pais_descri from pais0 order by pais_tipo');?>
        </select>
     </td>
    <td></td>
</tr>
<tr>
	<td>PROV /CIUDAD:</td>
    <td>
    	<?php
			$ciudad=new select();
		?>
        <select id="ciudad" name="ciudad"  style="font-size:10px;border: #535353 solid 1px;">
        <?php $ciudad->select_simple('../cfg/res.php',$ciu,'select cdad_codigo,concat(prvc_descri," /",cdad_descri)as cdad_descri from cdad00');?>
        </select>
     </td>
    <td></td>
</tr>

<tr>
	<td>CALLE 1 /CDLA. /EDIF.</td>
    <td><input type="text" id="dper_txt_c1" class="dper_txt" maxlength="20" value="<?php echo $c1;?>"   /></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" value="<?php echo $c2;?>"   /></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" value="<?php echo $cn;?>"   /></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" value="<?php echo $c3;?>"   /></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"  value="<?php echo $e1;?>"  /></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"  value="<?php echo $t1;?>"  /></td>
    <td><span id="dper_err_t1" class="dper_err"></span></td>
</tr>


</table>


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



</td>
</tr>
</table>
</div>
<!--
<tr>
	<td>TEL. CELULAR:</td>
    <td><input type="text" id="dper_txt_t2" class="dper_txt" maxlength="20"  value="<?php echo $t2;?>"  /></td>
    <td><span id="dper_err_t2" class="dper_err"></span></td>
</tr>
-->


<input type="button" value="Guardar" onClick="guarda_dper();" id="dper_btn"/>
<script type="text/javascript">
function guarda_dper()
{ 

  	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 c4=document.getElementById('dper_txt_c4').value;
	 var cn=document.getElementById('dper_txt_cn').value;
	var e1=document.getElementById('dper_txt_e1').value;
 	var t1=document.getElementById('dper_txt_t1').value;
	var ref=document.getElementById('dper_txt_ref').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 ref_h='';
	var struc=document.getElementById('dper_txt_struc').value;
	n1=n1.trim();
	if(n1.length<2)
	{

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

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

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

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



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

	c3=c3.trim();
	if(c3.length<1)
	{
		document.getElementById('dper_err_c3').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_err_c3').innerHTML='';
	}



	e1=e1.trim();
	if(e1.length<2)
	{
		document.getElementById('dper_err_e1').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_err_e1').innerHTML='';
	}



	t1=t1.trim();
	if(t1.length<2)
	{
		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;
	}

	ref=ref.trim();
/*
	if(ref.length<2)
	{
		document.getElementById('dper_err_ref').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_err_ref').innerHTML='';
	}
	*/
	document.getElementById('dper_btn').disabled=true;
	document.body.style.cursor='wait';

	if(ref.length!=0)
	{
		var	errorx;
		$.ajax({
		cache:false,
		url:'../lib/busca_maesb.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{tabl:'enti',valo:ref},
    	beforeSend: function(jqXHR, textStatus)
		{
    	  
	      document.body.style.cursor='wait';
	      
                
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			errorx=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              console.log('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
               console.log('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               console.log('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               console.log('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   alert('Servidor no Responde');
           } else if (exception === 'abort') {
               console.log('Ajax request aborted.');
           } else {
               console.log('Uncaught Error: ' + jqXHR.responseText);
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success')
	        {
    	    	if(errorx!='0')
				{
					document.body.style.cursor='auto';
					var cadena = errorx.toString();
					var pos = cadena.indexOf("/");
					var codigo=cadena.substr(0,pos);
					var descri=cadena.substr(pos+1);

					document.getElementById('dper_txt_ref').value=codigo;
					document.getElementById('dper_err_ref').innerHTML=descri;
					
					//++codigo++ del referidor
					guarda_dperb(n1,n2,a1,a2,c1,c2,cn,c3,e1,t1,codigo,ciudad,pais,nik,fn,struc);
					//console.log(codigo);
				}
				else
				{
					document.getElementById('dper_err_ref').innerHTML='*Referidor Incorrecto';
					return false;
				
				} 
				

			}
			          
		},
		timeout:30000
	});

	}
	else
	{
		document.getElementById('dper_btn').disabled=false;
		document.body.style.cursor='auto';
		guarda_dperb(n1,n2,a1,a2,c1,c2,cn,c3,e1,t1,ref_h,ciudad,pais,nik,fn,struc);
		
		
	}
}

function guarda_dperb(n1,n2,a1,a2,c1,c2,cn,c3,e1,t1,ref,ciudad,pais,nik,fn,struc)
{
	document.getElementById('dper_btn').disabled=true;
	document.body.style.cursor='wait';

	$.ajax({
		url:'../lib/dper_g.php',
		type:'POST',
		data:{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,struc:struc},
		success:function(dato)
		{
			document.getElementById('dper_btn').disabled=false;
			document.body.style.cursor='auto';
			if(dato=='0')
			{
				alert('Datos Personales Actualizados');
			}
			else
			{
				console.log(dato);
			}
		}, 
		error:function(objeto)
		{
			console.log(objeto);
			//alert('Archivo No Encontrado');
		}
	});
	document.getElementById('dper_btn').disabled=false;
	document.body.style.cursor='auto';


}
 
</script>