<?php
 session_start();
 include("emenux.php");
 require "funciones.php";
 //------INI-Coneccion Local
 require ("conecta.php");
 //------INI-Coneccion Local
 //Recibe descripcion
 $descripcio=sacacomilla(codsql($_POST['descripcio']));
 $codb=sacacomilla(codsql($_POST['codigo']));
 $codbarra=sacacomilla(codsql($_POST['codigob']));
 if (strlen($_POST['descripcio'])>0  ){
 
 $_SESSION['sqlb']= "SELECT m07005.STOCK, m07001.COD_INTERNO, m07001.COD_BARRA, m07001.GLOSA, 
                      m07001.PRECIO,m07005.STOCKCC
FROM         m07001 INNER JOIN
                      m07005 ON m07001.COD_INTERNO = m07005.COD_INTERNO
WHERE     (m07001.GLOSA LIKE '%$descripcio'   )
ORDER BY m07001.GLOSA;";
 }
  if (strlen($_POST['codigo'])>0  ){
 
 $_SESSION['sqlb']= "SELECT m07005.STOCK, m07001.COD_INTERNO, m07001.COD_BARRA, m07001.GLOSA, 
                      m07001.PRECIO,m07005.STOCKCC
FROM         m07001 INNER JOIN
                      m07005 ON m07001.COD_INTERNO = m07005.COD_INTERNO
WHERE     (m07001.COD_INTERNO LIKE '%$codb'   )
ORDER BY m07001.GLOSA;";
 }
 if (strlen($_POST['codigob'])>0  ){
 
 $_SESSION['sqlb']= "SELECT m07005.STOCK, m07001.COD_INTERNO, m07001.COD_BARRA, m07001.GLOSA, 
                      m07001.PRECIO,m07005.STOCKCC
FROM         m07001 INNER JOIN
                      m07005 ON m07001.COD_INTERNO = m07005.COD_INTERNO
WHERE     (m07001.COD_BARRA LIKE '%$codbarra'  )
ORDER BY m07001.GLOSA;";
 } 
 $cons=$_SESSION['sqlb'];
 $resb=mysql_query($cons,$con) or die(mysql_error());
 // contador de resultados en "0";
 $cant=0;
 if (mysql_num_rows($resb)>0){
   while ($filab = mysql_fetch_row($resb)){
    $cant++;
   }//while
  }//fin si
  
 //ver si hay datos en el carro 
 $nick=$_SESSION['nick'];
 $sqlcc="select * from m02004 where llave='$nick'";
 $rescc=mysql_query($sqlcc,$con) or die(mysql_error());
 $contcc=0;
 if (mysql_num_rows($rescc)>0){
  while($filac=mysql_fetch_row($rescc)){//while
   $contcc++;
  }//while
 }
?>
<!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>

<TITLE>Resultado de busqueda</TITLE>

<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {
	color: #FFFFFF;
	font-weight: bold;
}
body,td,th {
	color: #000000;
}
body {
	background-color: #FFFFFF;
}
.Estilo4 {
	font-family: "Courier New", Courier, mono;
	font-size: 16px;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function popup(STOCK_MIN,COD_INTERNO,COD_BARRA,GLOSA,PRECIO){ 
  open("agrega.php?STOCK_MIN=" + STOCK_MIN + "&COD_INTERNO=" + COD_INTERNO + "&COD_BARRA=" + COD_BARRA + "&GLOSA=" + GLOSA + "&PRECIO=" + PRECIO,800,600);

}
function l2(cod){
 window.open("http://www.automotriz-vemol.cl/l2.php?cod=" + cod);
}//fin funcion l2
</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></HEAD>
<BODY>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE width="715" 
              border=0 cellPadding=0 cellSpacing=0 bordercolor="#595959">
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top>&nbsp;</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD height="100%" align=left vAlign=top><form id="form1" name="form1" method="post" action="">
                  <table width="100%" border="1" cellpadding="0" cellspacing="1" bordercolor="#000000" class="LeftMenu">
                      <tr>
                        <td colspan="5" scope="col"><div align="center"><strong><span class="MainMenuHead">Resultado de Busqueda:<?php echo $cant ?></strong> <a href="carro.php">carro</a> </div></td>
                        </tr>

                      <tr>
                        <td width="6%" height="24" class="m0l0oout Estilo1" scope="row"><div align="center">Stock</div></td>
						<?php
						 if ($_SERVER['HTTP_HOST']=="www.automotriz-vemol.cl"){
						  echo "<td width='6%' height='24' class='m0l0oout Estilo1' scope='row'><div align='center'>C.Central</div></td>";
						 }
						?>
                        <td width="19%" class="m0l0oout" scope="row"><div align="center" class="Estilo1">
                          <div align="left">Cod_interno</div>
                        </div></td>                        
                        <td width="50%" class="m0l0oout Estilo1" scope="row"><div align="left">Glosa</div></td>
                        <td width="7%" class="m0l0oout" scope="row"><div align="left" class="Estilo1">Precio</div></td>
                      </tr>
					  <?php
					   //Definimos los colores a usar
					   $color0 = "#A4B4C1";
					   $color1 = "#D5E7FB";
					   $color2 = "#E8F2FC";
					   $color3 = "#E0FAC5";
					   $color = $color1;
					   $sqlbusca=$_SESSION['sqlb'];
					   $resb=mysql_query($sqlbusca,$con);
					   if (mysql_num_rows($resb)>0){
					    while ($filab = mysql_fetch_row($resb)){
						$stock=$filab[0];
						$codin=$filab[1];
						$codba=$filab[2];
						$glosa=sacacomilla($filab[3]);
						//$glosa=$filab[3];
						$preci=$filab[4];
						$stockcc=$filab[5];
						 // empezando una tabla html
						 echo "<tr style=\"background-color:$color\" onMouseOver=\"this.style.backgroundColor='$color3'\" onMouseOut=\"this.style.backgroundColor='$color'\" height='34' >";						 
						 echo "<td><a href=\"javascript:popup('$stock','$codin','$codba','$glosa','$preci')\"><acronym title=\"Agregar al Carro Codigo: ". $codin . "\" class='Estilo4'>$stock</acronym></a></td>";
						 if ($_SERVER['HTTP_HOST']=="www.automotriz-vemol.cl"){
						  echo "<td><a href=\"javascript:popup('$stock','$codin','$codba','$glosa','$preci')\"><acronym title=\"Agregar al Carro Codigo: ". $codin . "\" class='Estilo4'>$stockcc</acronym></a></td>";
						 }
						 echo "<td><a href=\"javascript:popup('$stock','$codin','$codba','$glosa','$preci')\"><acronym title=\"Agregar al Carro\" class='Estilo4'>$codin</acronym></a></td>";
						 //echo "<td class='Estilo3'>$codba</td>";
						 echo "<td class='Estilo4'>$glosa</td>";
						 echo "<td align='right'><a href=\"javascript:l2('$codin')\" class='Estilo4' >" . number_format($preci,0,".",",")."</a></td>";
						 echo "</tr>";
						 if ($color == $color1){
						  $color = $color2;
						  }else{
						  $color = $color1;
						 }
						}//while
					   }//fin si 
					  ?>
                      <tr>
                        <td colspan="5" scope="row"><label>
                          <div align="center" class="LeftMenu"><acronym><a href="M0205001.php">Volver a Buscar<br />
</a></acronym>
                            <?php if($contcc>0){
						  echo "<a href=\"carro.php\">Usted tiene ". $contcc." Articulos sin Cerrar</a>";
						  }
						  ?>
                          </div>
                          </label></td>
                        </tr>
                      <tr>
                        <th colspan="5" scope="row"><label></label></th>
                        </tr>
                    </table>
                </form>
                  <p class="Estilo4">&nbsp;</p>                  
                  <p><a href="buscar"></a> </p></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD height=8>&nbsp;</TD>
                <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>      
	  <script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
</TABLE>
</BODY>
<?php
 //------FIN-Coneccion Local
 mysql_close($con)
 //------FIN-Coneccion Local
 ?>
</HTML>