<?php require('../cfg/res.php'); ?>
<script type="text/javascript">
function lista()
{
	var xtabla=document.getElementById('tabla').value;
	xtabla=xtabla.trim();
	if(xtabla.length==0)
	{
		document.getElementById('error_list').innerHTML='Tabla no Valida';
		return false;
	}
	else
	{
		document.getElementById('error_list').innerHTML='';
	}	
	
	
	
	$.ajax({
		cache:false,
		url:'../lib/vrcod1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{tabla:document.getElementById('tabla').value}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
		
						document.getElementById('cod_list').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('cod_list').innerHTML='Not connect: Verify Network.';
           } else if (jqXHR.status == 404) {
               document.getElementById('cod_list').innerHTML='Requested page not found [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('cod_list').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('cod_list').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   document.getElementById('cod_list').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('cod_list').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('cod_list').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
 
			}           
		},
		timeout:60000
	});

}

function status(tabla,codigo,accion)
{
	
	$.ajax({
		cache:false,
		url:'../lib/vrcod3.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{tabla:tabla,codigo:codigo,accion:accion}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			if(dato==='0')
			{
				lista();
			}
			else
			{
				document.getElementById('error_list').innerHTML=dato;
			}
		

		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('cod_list').innerHTML='Not connect: Verify Network.';
           } else if (jqXHR.status == 404) {
               document.getElementById('cod_list').innerHTML='Requested page not found [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('cod_list').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('cod_list').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   document.getElementById('cod_list').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('cod_list').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('cod_list').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
 
			}           
		},
		timeout:60000
	});

}

function graba()
{
	var xtabla=document.getElementById('tabla').value;
	var ycodigo='';
	ycodigo=document.getElementById('cod_n_codigo').value;
	var xdescri=document.getElementById('descri').value;
	
	console.log(ycodigo);
	xtabla=xtabla.trim();
	//xcodigo=xcodigo.trim();
	xdescri=xdescri.trim();
	
	if(xtabla.length==0)
	{
		document.getElementById('error_list').innerHTML='Tabla no Valida';
		return false;
	}
	else
	{
		document.getElementById('error_list').innerHTML='';
	}
	
/*	
	if(xcodigo.length==0)
	{
		document.getElementById('error_list').innerHTML='Codigo no Valido';
		return false;
	}
	else
	{
		document.getElementById('error_list').innerHTML='';
	}
*/	

/*
	if(descri.length==0)
	{
		document.getElementById('error_list').innerHTML='Descri no Valido';
		return false;
	}
	else
	{
		document.getElementById('error_list').innerHTML='';
	}
*/	


	console.log(ycodigo);
	
	$.ajax({
		cache:false,
		url:'../lib/vrcod2.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{tabla:xtabla,codigo:ycodigo.toUpperCase(),descri:xdescri.toUpperCase()}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			if(dato==='0')
			{
				lista();
			}
			else
			{
				document.getElementById('error_list').innerHTML=dato;
			}
			
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('error_list').innerHTML='Not connect: Verify Network.';
           } else if (jqXHR.status == 404) {
               document.getElementById('error_list').innerHTML='Requested page not found [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('error_list').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('error_list').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   document.getElementById('error_list').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('error_list').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('error_list').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
 
			}           
		},
		timeout:60000
	});
	
	
}

</script>
<table width="321">

<tr>
	<td width="62">TABLA</td>
    <td width="247"><input type="text" id="tabla"  />
    <input type="button" value="Ver" onClick="lista();">
    </td>
</tr>

<tr>
	<td>CODIGO</td>
    <td><input type="text" id="cod_n_codigo" value="" maxlength="12"  /></td>
</tr>

<tr>
	<td>DESCRI</td>
    <td><input type="text" id="descri" value="" maxlength="49" /></td>
</tr>

</table>
<input type="button" value="Grabar" onclick="graba();">
<div id="error_list"></div>

<div id="cod_list"></div>
