<?
ini_set('error_reporting', 1);
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
$id_bodega = $_SESSION['ss_bodega'];

?>
<title>Busqueda Producto</title>
<style type="text/css">
<!--
.Estilo15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
.Estilo17 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #00ff00; }
-->
</style>
<?

$cant = $_GET["id"];
$enviar = $_GET["b"];
if ($enviar=="")
	{
	$enviar="1";
	}
include "../conex.php";
?>
<table width="100%"align="center" border="0">
  <tr>
    <td width="25%"><div align="center"><img src="../Images/logo.png" width="120" height="120"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">Buscar Producto</font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>


<form name="form1" method="post" action="busqueda.php?id=<?=$cant?>&b=<? echo "2";?>">
  <table width="100%"align="center" border="0">

    <tr>
      <td width="20%">Ingrese parte de la descripci&oacute;n :</td>
      <td width="65%"><label>
        <input name="textcodigo" type="text" size="65">
      </label></td>
      <td width="15%"><label>
        <input name="enviar" type="submit" id="enviar" value="Buscar">
      </label></td>
    </tr>
  </table>
    <div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000080"><span lang="es-cl"><b>
   		<a onClick="JavaScript:post_letra('A');" style="cursor:pointer">A</a>
 		<a onClick="JavaScript:post_letra('B');" style="cursor:pointer">B</a>
 		<a onClick="JavaScript:post_letra('C');" style="cursor:pointer">C</a>
		<a onClick="JavaScript:post_letra('D');" style="cursor:pointer">D</a>
		<a onClick="JavaScript:post_letra('E');" style="cursor:pointer">E</a>
		<a onClick="JavaScript:post_letra('F');" style="cursor:pointer">F</a>
		<a onClick="JavaScript:post_letra('G');" style="cursor:pointer">G</a>
		<a onClick="JavaScript:post_letra('H');" style="cursor:pointer">H</a>
		<a onClick="JavaScript:post_letra('I');" style="cursor:pointer">I</a>
		<a onClick="JavaScript:post_letra('J');" style="cursor:pointer">J</a>
		<a onClick="JavaScript:post_letra('K');" style="cursor:pointer">K</a>
		<a onClick="JavaScript:post_letra('L');" style="cursor:pointer">L</a>
		<a onClick="JavaScript:post_letra('M');" style="cursor:pointer">M</a>
		<a onClick="JavaScript:post_letra('N');" style="cursor:pointer">N</a>
		<a onClick="JavaScript:post_letra('O');" style="cursor:pointer">O</a>
		<a onClick="JavaScript:post_letra('P');" style="cursor:pointer">P</a>
		<a onClick="JavaScript:post_letra('Q');" style="cursor:pointer">Q</a>
		<a onClick="JavaScript:post_letra('R');" style="cursor:pointer">R</a>
		<a onClick="JavaScript:post_letra('S');" style="cursor:pointer">S</a>
		<a onClick="JavaScript:post_letra('T');" style="cursor:pointer">T</a>
		<a onClick="JavaScript:post_letra('U');" style="cursor:pointer">U</a>
		<a onClick="JavaScript:post_letra('V');" style="cursor:pointer">V</a>
		<a onClick="JavaScript:post_letra('W');" style="cursor:pointer">W</a>
		<a onClick="JavaScript:post_letra('X');" style="cursor:pointer">X</a>
		<a onClick="JavaScript:post_letra('Y');" style="cursor:pointer">Y</a>
		<a onClick="JavaScript:post_letra('Z');" style="cursor:pointer">Z</a>
		<br></b></span></font> </div>
</form>
	<?
	$cont=0;
	$caract=$_GET["caracter"];
	if (isset($caract)) 
		{
		$bsql = "SELECT saldo, codigo, descripcion, precio, peso FROM productos WHERE descripcion LIKE '$caract%' AND empresa=$id_empresa ORDER BY descripcion ASC";
		$resultado =mysql_query($bsql,$enlace);
		}
	else if ( $textcodigo!="" )
		{
		$bsql = "SELECT saldo, codigo, descripcion, precio, peso FROM productos WHERE descripcion LIKE '%$textcodigo%' AND empresa=$id_empresa ORDER BY descripcion ASC";
		$resultado =mysql_query($bsql,$enlace);
		}
	else
		{
		$bsql = "SELECT saldo, codigo, descripcion, precio, peso FROM productos WHERE descripcion LIKE '%' AND empresa=$id_empresa ORDER BY descripcion ASC";
		$resultado =mysql_query($bsql,$enlace);
		}
		
		
	while (mysql_fetch_object ($resultado))
		{
		$saldo=mysql_result($resultado, $cont, "saldo");
		$peso=mysql_result($resultado, $cont, "peso");
		$cp=mysql_result($resultado, $cont, "codigo");
		$des=mysql_result($resultado, $cont, "descripcion");
		$pre=mysql_result($resultado, $cont, "precio");
		
		if ($cont==0)
			{
		?>
		<table width="95%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="12%" align="center">Saldo</td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="12%" align="center">Precio ($)</td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="16%" align="center">Código</td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="50%" align="center">Descripción</td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="10%" align="center">Enviar</td>
		</tr>
		<? 
			}
		?>
		<tr>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="12%" align="right"><?=$saldo;?></td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="12%" align="right"><?=$pre;?></td>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="16%" align="left"><?=$cp;?></td>
		<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="50%" align="left"><?=$des?></td>
		<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="10%" align="center"><a onClick="JavaScript:enviar('<? echo "$cp";?>','<? echo "$des";?>','<? echo "$pre";?>','<? echo "$saldo";?>','<? echo "$peso";?>')"><IMG align=top  border=0 src="../Images/ir.gif" style="cursor:pointer" title="Presione aqui para enviar este código"></a></td>
	</tr>
	
	<?
	$cont=$cont+1;
	}
	?>
</table>



	<script languaje="javascript">
	
	
	function post_letra(letra)
	{
	
	document.form1.action = "busqueda.php?id="+<?=$cant?>+"&b="+<? echo "2";?>+"&caracter="+letra;
	document.form1.submit();
	}
	
	
	function enviar(cod,des,pre,saldo,peso)
		{
        window.opener.document.getElementById("auxsaldo[<? echo "$cant";?>]").value = saldo;
		window.opener.document.getElementById("codigo[<? echo "$cant";?>]").value = cod;
		window.opener.document.getElementById("precio[<? echo "$cant";?>]").value = pre;
		window.opener.document.getElementById("peso[<? echo "$cant";?>]").value = peso;
		window.opener.document.getElementById("detalle[<? echo "$cant";?>]").value = des;	
		window.opener.document.getElementById("desc[<? echo "$cant";?>]").value = 0;	
		window.close();
		window.opener.document.getElementById("codigo[<? echo "$cant";?>]").focus();
		window.opener.document.getElementById("cantidad[<? echo "$cant";?>]").focus();
		}
	</script>
