<?php session_start();
require('../cfg/cfg.php');
require('../cfg/res.php');
include('php_gene1.php');
$pagina_descri='CODIGOS DE ';
$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'];?> - Codigos</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/fecha_format.js');?>
function tejido_()
{
	list_carga('kldd','tejido','tejido_descri');	
}
function tejido()
{
		var tejido=document.getElementById('tejido').value;
		
		if(tejido=='' || tejido==' ')
		{
			return false;
		}
	
		busca_maes2('kldd',document.getElementById('tejido').value,'tejido','tejido_descri','');
}

function lsubl()
{
		var lsubl=document.getElementById('lsubl').value;
		
		if(lsubl=='' || lsubl==' ')
		{
			return false;
		}
	
		busca_maes2('lsub',document.getElementById('lsubl').value,'lsubl','lsubl_descri','');
}

function lsubl_()
{
	list_carga('lsub','lsubl','lsubl_descri');	
}

function marca_()
{
	list_carga('mrca','marca','marca_descri');	
}



function marca()
{
		var marca=document.getElementById('marca').value;
		
		if(marca=='' || marca==' ')
		{
			return false;
		}
	
		busca_maes2('mrca',document.getElementById('marca').value,'marca','marca_descri','');
}

</script>
<script type="text/javascript">
function ncode()
{

var descri=document.getElementById('descri').value;
var tejido=document.getElementById('tejido').value;
var lsubl=document.getElementById('lsubl').value;
var marca=document.getElementById('marca').value;
var nchk=document.getElementsByClassName('cl_code').length-1;
var sq_code='';
var aux=0;

document.getElementById('loader').style.display='block';
document.getElementById('code_error').innerHTML='';
for(i=0;i<=nchk;i++)
{
	if(document.getElementsByClassName('cl_code').item(i).checked)
	{
		if(aux==0)
		{sq_code+='("*+abc+*'+'","'+document.getElementById('descri').value+'","'+document.getElementById('tejido').value+'","'+document.getElementById('lsubl').value+'","'+document.getElementById('marca').value+'")';		}
	
		sq_code+=',(';
		sq_code+='"*+abc+*'+document.getElementsByClassName('cl_code').item(i).value+'","'+document.getElementById('descri').value+'","'+document.getElementById('tejido').value+'","'+document.getElementById('lsubl').value+'","'+document.getElementById('marca').value+'"';
		sq_code+=')';
		aux=1;
	}
}
	
		$.ajax({
			cache:false,
			url:'vrcode2.php',
			datatype: "text",
	   	async:false,
			type:'POST',
			data:{descri:descri,tejido:tejido,lsubl:lsubl,marca:marca,sq_code:sq_code}, 
	   	beforeSend: function(jqXHR, textStatus)
			{
			}, 
		
			success:function(dato, textStatus, jqXHR)
			{
				document.getElementById('loader').style.display='none';
				document.getElementById('code_error').innerHTML=dato;
				
				if(dato!='Ocurrio un error al registar los datos')
				{
					var urlx="fitem.php?idx="+dato;
					window.open(urlx);
					//window.open(urlx, "ficha item", "directories=no, location=no, menubar=yes, scrollbars=yes, statusbar=yes, tittlebar=yes");
					limpia();			
				}
				
			},
			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') {
    			   alert('Servidor no Responde');
    	       } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
	           } else {
    	           console.log('Uncaught Error: ' + jqXHR.responseText);
	           }
			}, 
	    	complete:function(jqXHR, textStatus)
    		{  console.log(textStatus);
				if(textStatus==='success')
	      {
				}           
			},
			timeout:96000
			});

}
	
function limpia()
{
	document.getElementById('descri').value='';
	document.getElementById('tejido').value='';
	document.getElementById('lsubl').value='';
	document.getElementById('marca').value='';
	var nchk=document.getElementsByClassName('cl_code').length-1;	
	for(i=0;i<=nchk;i++)
	{
		document.getElementsByClassName('cl_code').item(i).checked=false;
	}

}
</script>	
</head>

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


<table>
<tr valign="top">
	<td width = "10%">
    <table>
    	<tr >
					<?php $pcaption='DESCRIPCION'; $pidtxt='descri'; $plong=40;  include('vrgettxt.php'); ?>
       </tr>
    	<tr >
					<?php $pcaption='TEJIDO'; $pidtxt='tejido'; $plong=20;  include('vrgettxt.php'); ?>
       </tr>
    	<tr >
					<?php $pcaption='LINEA'; $ptabla='lsub'; $pidtxt='lsubl'; $plong=20;  include('vrgetcod.php'); ?>
       </tr>
			
	    	<tr >
					<?php $pcaption='MARCA'; $ptabla='mrca'; $pidtxt='marca';   include('vrgetcod.php'); ?>
       </tr>
			
			<tr >
				<td>
					<?php $pcaption='GRABAR'; $ponclick='ncode()';   include('vrbutton.php'); ?>
				</td>
				
       </tr>
	
			<tr>
<td>
         <div style=" height:40px;">
				<div id="loader" style="display:none;">Procesando...</div>
				</div>
				<div id="code_error"></div>
</td>				
			</tr>


		</table>
    
    
    </td>

<?php for ($i = 0; $i < 10; $i++) { ?>
		<?php 
		$talla_sql='select *from tlla0 WHERE LEFT (tlla_codigo, 1)="'.$i.'"';
		$talla_res=mysql_query($talla_sql,$link_vcrx);
		?>
		<?php if(mysql_num_rows($talla_res)!=0) { ?>
		<td width="5%">
		<?php while($talla_r=mysql_fetch_assoc($talla_res)){?>
			<table width="100%">
			<tr>
				<?php $pcaption=$talla_r['tlla_descri']; $pclass="cl_code"; $pvalue=$talla_r['tlla_codigo'];  include('vrchkbox.php'); ?>
			</tr>
			</table>
		<?php } ?>
		</td>
		<?php } ?>
<?php } ?>
	
</tr>
</table>


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