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

?>
<!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_id'];?> - Crear Extensiones</title>
<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/busca_ficha.js');?>
function codigo()
{ 
	var codigo=document.getElementById('codigo').value;
	if(codigo!='' && codigo!=' ')
	{
		busca_maes2('item',document.getElementById('codigo').value,'codigo','codigo_descri','');
		if(document.getElementById('codigo_descri').innerHTML!='N/A' && document.getElementById('codigo_descri').innerHTML!='')
		{
			get_ficha();
		}
	}
}

function codigo_k(e)
{
	if(e.keyCode==13)
	{
		codigo();
	}
}

function get_ficha()
{
	busca_ficha('item',document.getElementById('codigo').value,'mrca','mrca_descri','');
	//busca_maes2('mrca',document.getElementById('mrca_descri').innerHTML,'mrca_descri','mrca_descri2','');
	busca_ficha('item',document.getElementById('codigo').value,'lsub','lsub_descri','');
	//busca_maes2('lsub',document.getElementById('lsub_descri').innerHTML,'lsub_descri','lsub_descri2','');
	busca_ficha('item',document.getElementById('codigo').value,'modelo','modelo_descri','');
	busca_ficha('item',document.getElementById('codigo').value,'kldd','kldd_descri','');
	document.getElementById('ext_cont').style.display='table-row';
	ext_lista();
}
function guarda_ext()
{
	var error='ext_error';
	var codigo=document.getElementById('codigo').value;
	var ext=document.getElementById('ext').value;
		$.ajax({
		cache:false,
		url:'vrnewext2.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{codigo:codigo,ext:ext}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	                  
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
			var urlx="fitem.php?idx="+codigo;
			if(dato=='0')
			{
				ext_lista();
				window.open(urlx);
				//window.open(urlx, "ficha item", "directories=no, location=no, menubar=yes, scrollbars=yes, statusbar=yes, tittlebar=yes");
			}
			else
			{
				document.getElementById(error).innerHTML=dato;
			}
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if(document.getElementById(error))
		   {
				

				if (jqXHR.status === 0) {
				document.getElementById(error).innerHTML='Not connect: Verify Network.';
				} else if (jqXHR.status == 404) {
				document.getElementById(error).innerHTML='Requested page not found [404]';
				} else if (jqXHR.status == 500) {
				document.getElementById(error).innerHTML='Internal Server Error [500].';
				} else if (exception === 'parsererror') {
				document.getElementById(error).innerHTML='Requested JSON parse failed.';
				} else if (exception === 'timeout') {
				document.getElementById(error).innerHTML='Servidor no Responde';
				} else if (exception === 'abort') {
				document.getElementById(error).innerHTML='Ajax request aborted.';
				} else {
				document.getElementById(error).innerHTML='Uncaught Error: ' + jqXHR.responseText;
				}
		   }
		   else
		   {
			
				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') {
	               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:300000
	});

}

function ext_lista()
{
	var error='ext_error';
		$.ajax({
		cache:false,
		url:'../lib/vrnewext3.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{idx:document.getElementById('codigo').value}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	                  
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('ext_list').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if(document.getElementById(error))
		   {
				

				if (jqXHR.status === 0) {
				document.getElementById(error).innerHTML='Not connect: Verify Network.';
				} else if (jqXHR.status == 404) {
				document.getElementById(error).innerHTML='Requested page not found [404]';
				} else if (jqXHR.status == 500) {
				document.getElementById(error).innerHTML='Internal Server Error [500].';
				} else if (exception === 'parsererror') {
				document.getElementById(error).innerHTML='Requested JSON parse failed.';
				} else if (exception === 'timeout') {
				document.getElementById(error).innerHTML='Servidor no Responde';
				} else if (exception === 'abort') {
				document.getElementById(error).innerHTML='Ajax request aborted.';
				} else {
				document.getElementById(error).innerHTML='Uncaught Error: ' + jqXHR.responseText;
				}
		   }
		   else
		   {
			
				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') {
	               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:300000
	});

}
</script>

</head>

<body>
<div align="center" >
	<div align="center">

<?php include('../../_lib/cabecera2.php');?>
    
    


<table>
	<tr>
		<td><input type="button" value="CODIGO:" onclick="codigo();" style="font-family:'Courier New', Courier, monospace;" /> </td>
        <td><input type="text" id="codigo" onKeyDown="codigo_k(event);" placeholder="codigo" style="border: solid 1px #000; width:110px; padding-left:2px;" /></td>
        <td><span id="codigo_descri" style="font-weight:bold; height:25px; width:500px;"></span></td>
	</tr>
	<tr>
		
        <td><div id="kldd"  style="font-family:'Courier New', Courier, monospace;">TEJIDO</div></td>
        <td><span id="kldd_descri"></span></td>
        <td></td>
	</tr>
	<tr>
		<td><span id="lsub" style="font-family:'Courier New', Courier, monospace;">L_SUB</span></td>
        <td><span id="lsub_descri" style="font-weight:bold; height:25px; width:500px;"></span><span id="lsub_descri2"></span></td>
        <td></td>
	</tr>
	<tr>
		
        <td><div id="mrca"  style="font-family:'Courier New', Courier, monospace;">MARCA</div></td>
        <td><span id="mrca_descri">-</span><span id="mrca_descri2"></span></td>
        <td></td>
	</tr>
	<tr style="display:none">
		<td><span id="modelo" style="font-family:'Courier New', Courier, monospace;"> MODELO  </span> </td>
        <td><span id="modelo_descri" style="font-weight:bold; height:25px; width:500px;"></span></td>
        <td></td>
	</tr>

	<tr id="ext_cont" style="display:none;">
		<td><span id="lsub" style="font-family:'Courier New', Courier, monospace; width:30px;">EXT</span></td>
        <td><input type="text" id="ext" placeholder="ext"  style="width:25px;" /></td>
        <td><input type="button" value="Guardar" onclick="guarda_ext();" /></td>
	</tr>

</table>
<div id="ext_error"></div>
<div id="ext_list"></div>
</div>
</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>    

</body>
</html>