<?php 
session_start();
include('../cfg/cfg.php');
include('../cfg/res.php');
if(empty($_SESSION['user_vcrx_tipo']) || !isset($_SESSION['user_vcrx_tipo']))
{
	die('<a href="../salir.php">SU SESSION EXPIRO.</a>');
}

$pagina_descri='AUTORIZACIONES SRI ';
$pagina_nivel;
$pagina_tipo;


?>
<?php include('php_gene1.php'); ?>
<?php include('php_session.php');?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title><?php echo $empr_nombre .' - ' . $_SESSION['user_vcrx_descri'];?></title>
<link rel="stylesheet" href="http://vcrxol.com/css/ambiente.css"  type="text/css" />
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="../js/busca_maes.js"></script>
<style type="text/css">
body{background:#ffffff;}
.dper_txt{border:solid 1px #000000; border-radius:2px; padding:2px; margin:2px;}
.txt_adr{ width:100%;}
</style>
<script type="text/javascript">
<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>

function onload()
{
<?php if (isset($_GET['idx']) && !empty($_GET['idx'])){?>	
			document.getElementById('atrz').value='<?php echo $_GET['idx']; ?>';	
<?php } ?>	

<?php if (mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo']))){?>	
<?php }else{ ?>	
			document.getElementById('atrz').value='<?php echo $_SESSION['user_vcrx_id'];  ?>';	
			document.getElementById('atrz').disabled='disabled';	
			document.getElementById('atrz').tabindex='-1';	
			document.getElementById('atrz').onblur='';	
			document.getElementById('dper_txt_ref_btn').onclick='';	
<?php } ?>	
 _carga(document.getElementById('atrz').value,'1');

}
	
function numbloq(e,e2)
{
	var xnumbloq=document.getElementById(e2).value.toUpperCase();
		xvnum='0123456789';
		xnum='';
		for (i=0; i<xnumbloq.length;i++)
			{
				xcar=xnumbloq.substring(i,i+1);	
				if (xvnum.indexOf(xcar)>=0){xnum+=xcar;}
			}
		 	document.getElementById(e2).value=xnum;
}
	
	
	function _pais(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{
		busca_maes2('pais',document.getElementById('pais').value,'pais','pais_descri','');
		
	}
}

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


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 _zsub(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{busca_maes2('zsub',document.getElementById('enti').value,'enti','enti_descri','');}
}

function _csub(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{busca_maes2('csub',document.getElementById('dper_txt_csub').value,'dper_txt_csub','dper_txt_csub_descri','');}
}

function _vndd(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{busca_maes2('vndd',document.getElementById('dper_txt_vndd').value,'dper_txt_vndd','dper_txt_vndd_descri','');}
}

function _rcdd(e)
{
	if(e.keyCode==9 || e.keyCode==13)
	{busca_maes2('rcdd',document.getElementById('dper_txt_rcdd').value,'dper_txt_rcdd','dper_txt_rcdd_descri','');}
}

	
function valida_dper()
{ 

  var n1=document.getElementById('dper_txt_n1').value.toUpperCase().trim().replace('  ',' ');
	var n2=document.getElementById('dper_txt_n2').value.toUpperCase().trim().replace('  ',' ');
	var a1=document.getElementById('dper_txt_a1').value.toUpperCase().trim().replace('  ',' ');
	var a2=document.getElementById('dper_txt_a2').value.toUpperCase().trim().replace('  ',' ');
	var c1=document.getElementById('c1').value.toUpperCase().trim().replace('  ',' ');
 	var c2=document.getElementById('c2').value.toUpperCase().trim().replace('  ',' ');
	var c3=document.getElementById('c3').value.toUpperCase().trim().replace('  ',' ');
	var cn=document.getElementById('cn').value.toUpperCase().trim().replace('  ',' ');
	var ref=document.getElementById('dper_txt_ref').value.toUpperCase().trim().replace('  ',' ');
	var e1=document.getElementById('dper_txt_e1').value.toLowerCase().trim().replace('  ',' ');
 	var t1=document.getElementById('dper_txt_t1').value.trim().replace('  ',' ');
	var ciudad=document.getElementById('ciudad').value.toUpperCase().trim().replace('  ',' ');
	var pais=document.getElementById('pais').value.toUpperCase().trim().replace('  ',' ');
 	var nik=document.getElementById('dper_txt_nik').value.toUpperCase().trim().replace('  ',' ');
 	var struc=document.getElementById('dper_txt_struc').value.toUpperCase().trim().replace('  ',' ');
 	var pspt=document.getElementById('dper_txt_pspt').value.toUpperCase().trim().replace('  ',' ');
 	var conadis=document.getElementById('dper_txt_conadis').value.toUpperCase().trim().replace('  ',' ');
 	var sexo=document.getElementById('dper_txt_sexo').value.toUpperCase().trim().replace('  ',' ');
	var fn=document.getElementById('caduca').value;
	var rs=document.getElementById('dper_txt_rs').value.toUpperCase().trim().replace('  ',' ');
	var nc=document.getElementById('dper_txt_nc').value.toUpperCase().trim().replace('  ',' ');

	var cix=document.getElementById('atrz').value.trim().replace('  ',' ');
	var valx = cix.substring(2,3);
// 	n1=n1.trim();
	
    if(n1.length<2 && valx < 6)
	{
		document.getElementById('dper_txt_n1_err').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_txt_n1_err').innerHTML='';
	}

	a1=a1.trim();
	if(a1.length<2 && valx < 6)
	{
		document.getElementById('dper_txt_a1_err').innerHTML='*Obligatorio';
		return false;
	}
	else
	{
		document.getElementById('dper_txt_a1_err').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;
	}
}


function _limpia(ced)
{
if(ced=='1'){document.getElementById('atrz').value='';}

document.getElementById('atrz').value='';
document.getElementById('enti').value='';
document.getElementById('caduca').value='';
document.getElementById('docu').value='';
document.getElementById('ptoe').value='';
document.getElementById('desde').value='';
document.getElementById('hasta').value='';


}

function guarda_dper()
{
	
	//valida_dper();
	
	var atrz=document.getElementById('atrz').value;
	var enti=document.getElementById('enti').value;
	var caduca=document.getElementById('caduca').value;
	var docu=document.getElementById('docu').value;
	var ptoe=document.getElementById('ptoe').value;
	var desde=document.getElementById('desde').value;
	var hasta=document.getElementById('hasta').value;

	var descri='';

	
	if(atrz=="" || enti==""){alert('NO HAY DATOS');}
	else
	{	
	msgconfir='GUARDAR --> '+atrz+' - '+enti+' ?';
	if (confirm(msgconfir)) 
	{
	
	document.body.style.cursor='wait';
// 	document.getElementById('direc_error').innerHTML='';
	
	$.ajax({
		url:'natrz2.php',
		type:'POST',
		data:{atrz:atrz,enti:enti,caduca:caduca,docu:docu,ptoe:ptoe,desde:desde,hasta:hasta},
		success:function(dato)
		{
			alert('Datos Guardados OK');
			console.log(dato);
			document.body.style.cursor='auto';
// 			document.getElementById('direc_error').innerHTML=$(dato).find("error1").text()+$(dato).find("error2").text()+$(dato).find("error3").text();
			_carga(atrz,'');
		}, 
		error:function(objeto)
		{
			alert('ERROR al Guardar');
			console.log(objeto);
			
		}
	});
	
	document.body.style.cursor='auto';
	}
	}
}




function _carga(atrz,opc)
{
	console.log(atrz)
	$.ajax({
		url:'natrz3.php',
		async:false,
		type:'POST', 
		data:{atrz:atrz},
		beforeSend: function(){},
		success: function(dato){
				console.log(dato);
				document.getElementById('direc_d').innerHTML=dato;
				//if($(dato).find("error").text()!='0'){return false;}
				if(opc=='1')
				{
					_limpia('');
					
					document.getElementById('atrz').value=document.getElementById('hatrz').value;
					document.getElementById('enti').value=document.getElementById('henti').value;
					document.getElementById('caduca').value=document.getElementById('hcaduca').value;
				}
				
			},
		error: function(err_e){ console.log(err_e);},
		timeout: 60000
		});
			
// 				document.getElementById('ttel2').style.width=ancho+'px'; 

}



function _enti(e)
{
	console.log('***');
	if(e.keyCode==13)
	{
		//_edit_e(document.getElementById('atrz').value);
	}
		_carga(document.getElementById('atrz').value,'1');
	
}

function _fecha_formatobj(e){

	if(e.keyCode==13 || e.keyCode==9)
	{	
	var fn=document.getElementById('caduca').value;
	fn=fecha_format(fn);
	document.getElementById('caduca').value=fn;
	}

}

function _defa_adr(idx,ci)
{
	var ci=document.getElementById('atrz').value.toUpperCase().trim().replace('  ',' ');
  if(confirm("Establecer como Principal ?")) 
	{
	$.ajax({
		url:'../lib/vradrs4.php',
		type:'POST',
		data:{idx:idx,ci:ci},
		success: function(dato)
		{
			switch(dato)
			{
				case '0':
// 					document.getElementById(idx).style.display='none';
				break;
				case '1':
					//alert('Ocurrio Error de Conexion');
				break;
				case '500':
					alert('No Tiene Permiso');
				break;
				default:
					alert('Error');
				break;
			}
		},
		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')
	    {
//     	 window.location.reload();	
			}           
		},
	});
// 	guarda_dper();	
	}
// 	 window.location.reload();	
}



function _delete_atrd(idx)
{
  if(!confirm("Seguro que desea Eliminar?")) {return false;}
	
	$.ajax({
		url:'../lib/vratrd2.php',
		type:'POST',
		data:{idx:idx},
		success: function(dato)
		{
			switch(dato)
			{
				case '0':
					//alert('Se Elimino');
					document.getElementById(idx).style.display='none';
				break;
				case '1':
					//alert('Ocurrio Error de Conexion');
				break;
				case '500':
					alert('No Tiene Permiso');
				break;
				default:
					alert('Error');
				break;
			}
		},
		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')
	        {
    	    	
			}           
		},
	});
	
}




<?php if(isset($_GET['idx']) && !empty($_GET['idx'])){?>
// window.onload = function(e){ 
//  _carga('<?php echo $_GET['idx']; ?>','1');
// }
<?php }?>

<?php if ( !mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo'])) ) {?>
// window.onload = function(e){ 
//  _carga('<?php echo $_SESSION['user_vcrx_id']; ?>','1');
// }
<?php }?>

</script>

</head>

<body>
<div align="center">
<div>
<div align="center"><?php include('../../_lib/cabecera2.php');?></div>



<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>
	<?php  $pcaption='AUTORIZACION'; $pidtxt='atrz'; $plong=10; $ponblur=''; include('vrgettxt.php') ?>
</tr>
<tr >
	<?php  $pcaption='RUC'; $ptabla='enti'; $pidtxt='enti';  include('vrgetcod.php') ?>
</tr>
<tr>
	<?php  $pcaption='CADUCA'; $pidtxt='caduca';  include('vrgetfec.php') ?>
</tr>

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

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

</table>	
</td>


<td>

<table border="0" cellpadding="2" cellspacing="0" style=" font-size:12px; font-weight:bolder; <?php if (!mb_stristr('sist.supe.admi',$_SESSION['user_vcrx_tipo'])){echo 'display:none;';}?>">
</table>	

	
</td>	
	
<td>
<!--+++++ -->
<table border="0" cellpadding="2" cellspacing="0" style=" font-size:12px; font-weight:bolder; display:none;">
<tr>
	<td><input type="hidden" id="pais_btn" value="PAIS:" onClick="list_carga('pais','pais','pais_descri');" style="text-transform:uppercase;"/></td>
    <td><input type="hidden" id="pais" onkeydown="_pais(event);" class="dper_txt" style="text-transform:uppercase;"/></td>
    <td><span id="pais_descri" style="font-weight:bold; height:25px;"></span></td>
</tr>

<tr>
	<td><input type="hidden" id="ciudad_btn" value="PROV /CIUDAD:" onClick="list_carga('cdad','ciudad','ciudad_descri');" style="text-transform:uppercase;"/></td>
    <td><input type="hidden" id="ciudad" onkeydown="_ciudad(event);" class="dper_txt" style="text-transform:uppercase;"/> </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="hidden" id="c1" class="dper_txt" maxlength="20"  style="text-transform:uppercase;" /></td>
    <td width="50"><span id="dper_err_c1" class="dper_err" style="text-transform:uppercase;"></span></td>
</tr>

<tr>
<!-- 	<td>CALLE 2 /MZ /PISO </td> -->
    <td><input type="hidden" id="c2" class="dper_txt" maxlength="20"  style="text-transform:uppercase;"  /></td>
    <td><span id="dper_err_c2" class="dper_err" style="text-transform:uppercase;"></span></td>
</tr>

<tr>
<!-- 	<td>NUM. /VILLA /DPTO</td> -->
    <td><input type="hidden" id="cn" class="dper_txt" maxlength="20"   style="text-transform:uppercase;" /></td>
    <td><span id="dper_err_cn" class="dper_err" style="text-transform:uppercase;"></span></td>
</tr>

<tr>
<!-- 	<td>REFERENCIA(casa):</td> -->
    <td><input type="hidden" id="c3" class="dper_txt" maxlength="20"  style="text-transform:uppercase;"  /></td>
    <td><span id="dper_err_c3" class="dper_err" style="text-transform:uppercase;"></span></td>
</tr>

<tr>
<!-- 	<td>EMAIL:</td> -->
    <td><input type="hidden" id="dper_txt_e1" class="dper_txt" maxlength="45" style="text-transform:lowercase;"   /></td>
    <td><span id="dper_err_e1" class="dper_err" style="text-transform:lowercase;"></span></td>
</tr>

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


</table>


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


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

</table>

<?php if(mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo']))){ ?> <?php }?>
<input type="button" value="Guardar"    onclick="guarda_dper();"    id="dper_btn_g"/>
<input type="button" value="Limpiar"    onclick="_limpia('<?php if (mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo'])) ){echo '1';}?>');"    id="dper_btn_l"/>
<input type="image" width="20" src="http://vcrxol.com/_img/add_address.png" onclick="add_adr('<?php echo $_POST['ci'];?>');" style="display:none;" />

<div id="direc_error" style="height:20px; color:#F00;"></div>


	
<table width="100%" border="0" cellpadding="0" cellspacing="0"  style="border-collapse:collapse; background:#eee;">
<tr align="center" valign="bottom" style="border-top: solid 1px;border-bottom: solid 1px;font-size:12px;">
	<?php  $pcaption='DOCU'; $ptabla='docu'; $pobj=4;  include('vrgetcod.php') ?>
	<?php  $pcaption='PTOE';  $pidtxt='ptoe';  $pobj=2; $plong=6; $pdefa='001001'; include('vrgetnum.php') ?>
	<?php  $pcaption='DESDE';  $pidtxt='desde';  $pobj=2; $plong=9; $pdefa='0'; include('vrgetnum.php') ?>
	<?php  $pcaption='HASTA';  $pidtxt='hasta';  $pobj=2; $plong=9; $pdefa='0'; include('vrgetnum.php') ?>
	
<th><div style="width:20px;"></div></th>
</tr>
</table>

<div id="direc_d"></div>


<?php		
// $xwidth=40;	
require('lista_car.php');
?>	
<!-- 
<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>    
 -->



</div>
</div>

<input type="hidden" id="dper_hdd_ci" />
</body>

<script>
window.onload=onload();
</script>


</html>