<?php session_start();
require('../cfg/cfg.php');
require('../cfg/res.php');
$pagina_descri='DIRECCIONES';
$pagina_nivel;
$pagina_tipo;


//mysql_query("SET NAMES 'utf8'");
$sql_enti='select *from enti00 where enti_codigo in (select enti from clie1 union select enti from vtas1 union select enti from comp1) order by enti_razsoc, enti_codigo';
//$sql_enti='select *from enti0 ';
//echo $sql_enti;
$res_enti=mysql_query($sql_enti,$link_vcrx);
$estilo='border-bottom:dotted 1px #000000;';
$acum=0;
?>

<!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=euc-jp">

<title><?php echo $empr_nombre.'-'.$_SESSION['user_vcrx_id'].'-'.$pagina_descri;?>  </title>
<link rel="stylesheet" href="http://vcrxol.com/_css/comun.css" type="text/css" />
<link rel="stylesheet" href="../css/comun2.css" type="text/css" />
<style>
body{ font-size:12px;}
.txt_adr{ width:100%;}
</style>
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript">
<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>
</script>
</head>
<body style="padding:0px; margin:0px;">
	<div style="height:5px; margin:-1px 0px 0px 0px; padding:0px;"><div id="barra_azul" style=" background:#06F; height:5px;"></div></div>
	<div align="center" >
	<div align="center"><?php include('../../_lib/cabecera2.php');?></div>
	<div align="center">

<div style="background:#ffffff; padding:5px; height:300px; overflow-y:scroll;">
<table width="100%" cellspacing="5" cellpadding="2" style="font-size:12px; border-collapse:collapse; ">
<tr>
	<th></th>
    <th>CODIGO</th>
    <th>DESCRIPCION</th>
    <th>PROVINCIA / CIUDAD</th>
    <th>DIRECCION</th>
</tr>
<?php while($r_enti=mysql_fetch_assoc($res_enti)){ ?>
<tr style=" <?php if($acum==2){echo $estilo;$acum=0;}else{$acum++;}?>">
	<td><input type="image" src="http://vcrxol.com/_img/address.png" width="20" onclick="direccion('<?php echo $r_enti['enti_codigo'];?>','<?php echo $r_enti['enti_descri'];?>');" /></td>
    <td><?php echo $r_enti['enti_codigo'];?></td>
	<td><?php echo $r_enti['enti_descri'];?></td>
	<td><?php echo $r_enti['prvc_descri'].' /'.$r_enti['cdad_descri'];?></td>
	<td><?php echo $r_enti['enti_direccion'];?></td>
        
</tr>
<?php }?>
</table>
</div>
<div id="direc_d"></div>
<script type="text/javascript">
function direccion(idx,nomx)
{
	//window.open('../lib/vradrs1.php?ci='+idx+'&nom='+nomx, this.target, 'width=300,height=400'); 
	//return false; 
	$.ajax({
		cache:false,
		url:'../lib/vradrs1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{ci:idx,nom:nomx},
    	beforeSend: function(jqXHR, textStatus)
		{
    	  /*
		  document.getElementById('frm_reg_error').innerHTML='procesando.....';
	      document.body.style.cursor='wait';
	      document.getElementById('reg_btn').style.cursor='wait';
		  document.getElementById('reg_btn').style.background='#C1FFFF';
	      document.getElementById('reg_btn').disabled=true;
		  */
                
		},
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('direc_d').innerHTML = 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')
	        {
    	    	
			}           
		},
		timeout:30000
			
	
	});
}
function delete_adr(idx,ci)
{
	

    if(!confirm("¿Seguro que desea Eliminar?")) {

        return false;

    }

	
	$.ajax({
		url:'../lib/vradrs2.php',
		type:'POST',
		data:{idx:idx,ci:ci},
		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(objeto)
		{
			console.log(objeto);
		}
	});
}

function add_adr(ci)
{
	 //if(!confirm("Desea Agregar Directorio?")) {return false;}

	var tel=document.getElementById('tel').value;
	var c1=document.getElementById('c1').value;
	var c2=document.getElementById('c2').value;
	var c3=document.getElementById('c3').value;
	var cn=document.getElementById('cn').value;
	var ciudad=document.getElementById('ciudad').value;
	var email=document.getElementById('email').value;
	var ext=document.getElementById('ext').value;
	var contacto=document.getElementById('contacto').value;
	tel=tel.trim();
	/*
        if(tel.length<6)
	
        {
		alert('Telefono de contacto requerido');
		document.getElementById('tel').focus();
		return false;
	}
*/
	$.ajax({
		url:'../lib/vradrs3.php',
		type:'POST', 
		async:true,
		data:{ci:document.getElementById('adrs_ci').value,tel:tel,c1:c1,c2:c2,c3:c3,cn:cn,ciudad:ciudad,email:email,ext:ext,contacto:contacto},
		success: function(dato)
		{
			console.log(dato);
			switch(dato)
			{
				case '0':
					//alert('Se Agrego');
					//document.getElementById(idx).style.display='none';
					document.getElementById('tel').value='';
					document.getElementById('c1').value='';
					document.getElementById('c2').value='';
					document.getElementById('c3').value='';
					document.getElementById('cn').value='';
					document.getElementById('ciudad').value='';
					document.getElementById('email').value='';
					document.getElementById('ext').value='';
					document.getElementById('contacto').value='';
					//window.location.reload();
					direccion(document.getElementById('adrs_ci').value,document.getElementById('adrs_nom').value);

				break;
				case '1':
					alert('Ocurrio Error de Conexion');
				break;
				case '500':
					alert('No Tiene Permiso');
				break;
				default:
					alert('Error');
				break;
			}
		},
		error:function(objeto)
		{
			console.log(objeto);
		}
	});
}

</script>