<?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='CODIGOS '.$_GET['maes'];
$pagina_nivel;
$pagina_tipo;
$ptabla=strtolower($_GET['maes']);

// $item_sql='alter table item0 add column item_irbp varchar(9)';
// console.log( $item_sql);
// $item_res=mysql_query($item_sql,$link_vcrx);


?>

<!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()
{
// 	document.getElementById('codigo').disabled='disabled';	
// 	document.getElementById('codigo').tabindex='-1';	
	
<?php if (isset($_GET['idx']) && !empty($_GET['idx'])){?>	
	document.getElementById('codigo').value='<?php echo $_GET['idx']; ?>';	
	document.getElementById('codigo').disabled='disabled';	
	document.getElementById('codigo').tabindex='-1';	
<?php } ?>	

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

  var descri=document.getElementById('descri').value;
  var tipo=document.getElementById('tipo').value;
  var status=document.getElementById('status').value;
	var modelo=document.getElementById('modelo').value;
	var numpart=document.getElementById('numpart').value;
	var ean=document.getElementById('ean').value;
 	var umdd=document.getElementById('umdd').value;
 	var lado=document.getElementById('lado').value;
 	var clor=document.getElementById('clor').value;
 	var tlla=document.getElementById('tlla').value;
 	var kldd=document.getElementById('kldd').value;

  if(descri.length==0 )
	{
		document.getElementById('descri').value=modelo ;
	}

	document.getElementById('status_error').innerHTML='';
  if(status.length==0 )
	{
		document.getElementById('status_error').innerHTML='*Obligatorio';
		return false;
	}

	document.getElementById('modelo_error').innerHTML='';
  if(modelo.length==0 )
	{
		document.getElementById('modelo_error').innerHTML='*Obligatorio';
		return false;
	}

}


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

document.getElementById('status').value='';
document.getElementById('modelo').value='';
document.getElementById('numpart').value='';
document.getElementById('ean').value='';
document.getElementById('umdd').value='';
document.getElementById('kldd').value='';
document.getElementById('tlla').value='';
document.getElementById('descri').value='';
document.getElementById('tipo').value='';
document.getElementById('cair').value='';
document.getElementById('irbp').value='';
document.getElementById('ice').value='';
document.getElementById('iva').value='';
document.getElementById('lado').value='';
document.getElementById('clor').value='';



}

function guarda_dper(maes)
{
	
	valida_dper();
	
	
  var codigo=document.getElementById('codigo').value;
  var descri=document.getElementById('descri').value;
  var tipo=document.getElementById('tipo').value;
  var status=document.getElementById('stat').value;
	
// 	if(rs=="" && status==""){alert('NO HAY DATOS');}
	if(1==1)
	{	
	msgconfir='GRABAR --> '+codigo+' - '+descri+' ?';
	if (confirm(msgconfir)) 
	{
	console.log('grabando');
	document.body.style.cursor='wait';

		
	$.ajax({
		url:'nmaes2.php',
		type:'POST',
		data:{maes:maes,codigo:codigo,descri:descri,tipo:tipo,status:status},
		success:function(dato)
		{
			alert($(dato).find("msj1").text());
// 			alert($(dato).find("msj2").text());
			document.getElementById('codigo').value=$(dato).find("codigo").text()
			_carga(document.getElementById('codigo').value,'1');
		}, 
		error:function(objeto)
		{
			alert('ERROR al Grabar');
		}
	});
	
	document.body.style.cursor='auto';
	}
	}
}




function _carga(codigo,opc)
{
	
	
	$.ajax({
		url:'nmaes3.php',
		async:false,
		type:'POST', 
		data:{codigo:codigo},
		beforeSend: function(){},
		success: function(dato){
				
				document.getElementById('direc_d').innerHTML=dato;
				//if($(dato).find("error").text()!='0'){return false;}
				if(opc=='1')
				{
					_limpia('');
					
					document.getElementById('tipo').value=document.getElementById('htipo').value;
					document.getElementById('status').value=document.getElementById('hstatus').value;
					document.getElementById('modelo').value=document.getElementById('hmodelo').value;
					document.getElementById('numpart').value=document.getElementById('hnumpart').value;
					document.getElementById('ean').value=document.getElementById('hean').value;
					document.getElementById('descri').value=document.getElementById('hdescri').value;
					document.getElementById('tlla').value=document.getElementById('htlla').value;
					document.getElementById('kldd').value=document.getElementById('hkldd').value;
					document.getElementById('umdd').value=document.getElementById('humdd').value;
					document.getElementById('cair').value=document.getElementById('hcair').value;
					document.getElementById('cair_descri').value=document.getElementById('hcaird').value;
					document.getElementById('irbp').value=document.getElementById('hirbp').value;
					document.getElementById('ice').value=document.getElementById('hice').value;
					document.getElementById('iva').value=document.getElementById('hiva').value;
					document.getElementById('lado').value=document.getElementById('hlado').value;
					document.getElementById('clor').value=document.getElementById('hclor').value;
					//document.getElementById('ciudad_descri').innerHTML=$(dato).find("ciudad_descri").text();
				}
				
			},
		error: function(err_e){ console.log(err_e);},
		timeout: 60000
		
		
		
		});
			
				//document.getElementById('tel2').style.width=document.getElementById('tel2').offsetWidth+'px';
				//document.getElementById('text2').style.width=document.getElementById('ext2').offsetWidth;
}



function _item(e)
{
	if(e.keyCode==13)
	{
		//_edit_e(document.getElementById('codigo').value);
	}
		_carga(document.getElementById('codigo').value,'1');
	
}

function _fecha_formatobj(e){

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

}

function _defa_adr(idx,ci)
{
	var ci=document.getElementById('codigo').value;
  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_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(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>

<?php
		include('../cfg/res.php');
		$plong=1;
		$sql_getcod='describe '.$ptabla.'0';
		$res_getcod=mysql_query($sql_getcod,$link_vcrx);
		if(!mysql_error($link_vcrx))	
		{
			$plong=mysql_result($res_getcod,0,'type');
			$plong=str_replace(')','',$plong);
			$plong=str_replace('varchar(','',$plong);
			$plong=str_replace('char(','',$plong);
		}	
?>
	
<body>
<div align="center">
<div>
<div align="center"><?php include('../../_lib/cabecera2.php');?></div>


<table align = "left" border="0" width="50%" cellpadding="0" cellspacing="0" style="font-size:12px;" >
<tr valign="top">

	<?php $pcaption='CODIGO'; $pidtxt='codigo'; $ponblur='_item(event)';  include('vrgettxt.php'); ?>
<!-- 	<td><input type="button" id="codigo_btn" value="CODIGO :" onClick="" /></td>
  <td><input autofocus type="text" id="codigo" class="dper_txt" maxlength="13" onkeyup="numbloq(event,'codigo')" title="CODIGO" value="<?php if ( !mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo'])) ) { echo $_SESSION['user_vcrx_id'];}else if(isset($_GET['idx']) && !empty($_GET['idx'])){ echo $_GET['idx']; }?>"    <?php if ( mb_stristr('admi.sist.supe',strtolower($_SESSION['user_vcrx_tipo'])) ) {echo ' onkeypress="_item(event);" ';}else{echo 'disabled="disabled"';}?>      /></td>
  <td><span id="dper_err_codigo" class="dper_err"></span></td>
 -->
	<?php $pcaption='DESCRIPCION'; $pidtxt='descri'; $plong=40; include('vrgettxt.php'); ?>
</tr>
</table>
<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='TIPO'; $pidtxt='tipo'; $plong=4; include('vrgettxt.php'); ?>
</tr>
<tr>
	<?php $pcaption='STATUS'; $ptabla='stat'; $pdefa='-'; $plong=2; include('vrgetcod.php'); ?>
</tr>



</table>
</td>	
<td>
<!--+++++ -->
<table border="0" cellpadding="2" cellspacing="0" style=" font-size:12px; font-weight:bolder;display:none;">
	
<tr>
	<?php $pcaption='LINEA'; $ptabla='tipo';  $pdefa='GENE-GENE'; $plong=9; include('vrgetcod.php'); ?>
</tr>

<tr align="left">
	<?php $pcaption='MARCA'; $ptabla='status'; $pdefa='GENE'; $plong=4; include('vrgetcod.php'); ?>
</tr>
<tr>
	<?php $pcaption='MODELO'; $pidtxt='modelo'; $plong=20; include('vrgettxt.php'); ?>
</tr>
<tr>
	<?php $pcaption='# PARTE'; $pidtxt='numpart'; $plong=20; include('vrgettxt.php'); ?>
</tr>
<tr>
	<?php $pcaption='E.A.N.'; $pidtxt='ean'; $plong=13; include('vrgetnum.php'); ?>
</tr>
<tr>
	<?php $pcaption='COD.AUX.'; $pidtxt='codigov'; $plong=13; include('vrgettxt.php'); ?>
</tr>



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

<td>
</td>


<td>

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

	
	
</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('<?php echo $_POST['maes'];?>');"    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="top" style="border-top: solid 1px;border-bottom: solid 1px;font-size:12px;">

<th>
	<?php $pcaption='IMAGEN'; $pidtxt='imagen';$plong=20;$pobj=2;   include('vrgettxt.php'); ?> 
</th>

<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_codigo" />


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

</html>