<?
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'];
?>
<?
$donde = $_GET["d"];
$cod_prod = $_GET["cod"];
include "../conex.php";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Nuevo Producto</title>
<style type="text/css">
<!--
body {
	background-color: #CCCCCC;
	margin-left: 0px;
	margin-top: 3px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.Estilo7 {
	font-size: small;
	color: #000099;
}
.Estilo11 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; color: #000099; }
.Estilo13 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
	text-decoration: underline;
}
.Estilo14 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
}
.titulos2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #003366;
	background-color: #CCCCCC;
	font-style: normal;
	font-weight: bold;
}
.botones {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	height:26px;
}
-->
</style>

</head>

<table width="100%"align="center" border="0">
  <tr>
    <td width="25%"><div align="center"><img src="Images/logo.gif" width="120" height="120"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">Nuevo Producto </font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>
<body vlink="#2293ff" alink="#2293ff" link="#2293ff" onLoad="validacodigo();">
<form name="form1" method="post" action="guardae_producto.php">
<div align="left" class="titulos2" style="font-size:12px">
<input name="txtcodigo" type="text" id="txtcodigo" value="<?=$sql_codigo?>" readonly="1" size="40" style="visibility:hidden">
  <table width="90%" border="1" align="center">
	 <tr>
      <td>Descripción</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtdescripcion" type="text" id="txtdescripcion" size="40" value="<?=$sql_descripcion?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Precio (Con IVA) </td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtprecio" type="text" id="txtprecio" size="40" value="<?=$sql_precio?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	   <td>Saldo</td>
      <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtsaldo" type="text" id="txtsaldo" size="40" value="<?=$sql_saldo?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Unidad de Medida </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="40%">
			<?
			$sql_umed = "SELECT * FROM unidad_medida ORDER BY descripcion";
			$res_umed = mysql_query($sql_umed,$enlace);
			$cont=0;
			?>
              <select name="lstum" id="lstum" style="width:267px">
			  <?
			  while (mysql_fetch_object ($res_umed))
				{
				$sql_umed_cod = mysql_result($res_umed, $cont, "codigo");
				$sql_umed_nom = mysql_result($res_umed, $cont, "nomenclatura");
				$sql_umed_des = mysql_result($res_umed, $cont, "descripcion");
				if ($sql_unidad_medida==$sql_umed_cod){
			?>
                <option value="<?=$sql_umed_cod?>" selected="selected"><? echo $sql_umed_des." (".$sql_umed_nom.")";?></option>
			<?
					}
				else
					{
			?>
                <option value="<?=$sql_umed_cod?>"><? echo $sql_umed_des." (".$sql_umed_nom.")";?></option>
			<?
					}
				$cont = $cont+1;
			}
			?>
              </select>            </td>
            <td width="60%">&nbsp;&nbsp;<a onClick="JavaScript:PopWindow('<? echo "1";?>')"><IMG align="middle" border="0" src="../Images/modificar.gif" style="visibility:hidden;cursor:pointer" title="Presione aqui para buscar producto" width="16" height="16"></a></td>
          </tr>
        </table></td>
    </tr>
	  <td>Costo (Con IVA) </td>
        <td height="1px">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcosto" type="text" id="txtcosto" size="40" value="0" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Proveedor</td>
      <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="40%">
						<?
			$sql_prov = "SELECT * FROM nombres WHERE proveedor = 'True' ORDER BY razon_social";
			$res_prov = mysql_query($sql_prov,$enlace);
			$cont=0;
			?>
              <select name="lstproveedor" id="lstproveedor" style="width:267px">
			  <?
			  while (mysql_fetch_object ($res_prov))
				{
				$sql_prov_cod = mysql_result($res_prov, $cont, "rut");
				$sql_prov_des = mysql_result($res_prov, $cont, "razon_social");
				if ($sql_proveedor==$sql_prov_cod){
			?>
                <option value="<?=$sql_prov_cod?>" selected="selected"><? echo $sql_prov_des;?></option>
			<?
					}
				else
					{
			?>
                <option value="<?=$sql_prov_cod?>"><? echo $sql_prov_des;?></option>
			<?
					}
				$cont = $cont+1;
			}
			?>
              </select>			</td>
            <td width="60%">&nbsp;&nbsp;<a onClick="JavaScript:PopWindow('<? echo "3";?>')"><IMG align="middle" border="0" src="../Images/modificar.gif" style="visibility:hidden;cursor:pointer;" title="Presione aqui para buscar producto" width="16" height="16"></a></td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Observaciones</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtobs" id="txtobs" type="text" size="40" value="<?=$sql_observaciones?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>C&oacute;digo Fabricante </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcodfabricante" type="text" size="40" value="<?=$sql_cod_fabricante?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>C&oacute;digo Equivalente Proveedor </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcodeqprov" id="txtcodeqprov" type="text" size="40" value="<?=$sql_cod_eq_prov?>"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Unidades</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtunidades" type="text" size="40" value="<?=$sql_unidades?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Caja</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtcaja" type="text" size="40" value="<?=$sql_caja?>" onKeyPress="return valida(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Vencimiento Producto </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="ven_prod" type="checkbox" id="ven_prod" value="1" <? if ($sql_ven_prod_param==1) { ?> checked="checked" <? }?>></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Producto Seriado </td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>

			<select name="lstser" id="lstser" style="width:267px">
            <option value="0" <? if ($sql_prod_ser_param==0) { ?>selected="selected" <? }?>>Sin Seriado</option>
			<option value="1" <? if ($sql_prod_ser_param==1) { ?>selected="selected" <? }?>>Seriado Especial</option>
			<option value="2" <? if ($sql_prod_ser_param==2) { ?>selected="selected" <? }?>>Seriado Simple</option>
            </select></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Peso</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtpeso" id="volumen" type="text" size="40" value="<?=$sql_peso?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td>Volumen</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtvolumen" id="volumen" type="text" size="40" value="<?=$sql_volumen?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	 <tr>
      <td>Impuestos 1</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtimpuestos1" type="text" size="40" value="<?=$sql_impuestos1?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
	 <tr>
      <td>Impuestos 2</td>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><input name="txtimpuesto2" type="text" size="40" value="<?=$sql_impuesto2?>" onKeyPress="return valida2(event);"></td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
    </tr>
  </table>
  
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center">
        <label>
        <input type="button" name="Submit" value="Guardar" onClick="enviar();">
        </label>
      </div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>
</form>
<script language="javascript">
var nav4 = window.Event ? true : false;
<!-- Ingreso solo letras -->
function valida(evt){
var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
	}
function valida2(evt){
var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57) || key==46);
	}


function validacodigo()
	{
	if (document.form1.txtsaldo.value!=0) 
		{ 
		document.form1.txtsaldo.readOnly=1;
		}
	else
		{ 
		document.form1.txtsaldo.readOnly=0;
		}

	}
function enviar()
	{
	if (document.form1.txtdescripcion.value=='')
		{
		alert('Ingrese Descripcion');
		document.form1.txtdescripcion.focus();
		return false;
		}
	if (document.form1.txtprecio.value=='')
		{
		alert('Ingrese Precio');
		document.form1.txtprecio.focus();
		return false;
		}
	if (document.form1.txtsaldo.value=='')
		{
		alert('Ingrese Saldo');
		document.form1.txtsaldo.focus();
		return false;
		}
	if (document.form1.txtcosto.value=='')
		{
		alert('Ingrese Costo');
		document.form1.txtcosto.focus();
		return false;
		}
	if (document.form1.txtunidades.value=='')
		{
		alert('Ingrese Unidades');
		document.form1.txtunidades.focus();
		return false;
		}		
	if (document.form1.txtcaja.value=='')
		{
		alert('Ingrese Caja');
		document.form1.txtcaja.focus();
		return false;
		}		
	if (document.form1.txtpeso.value=='')
		{
		alert('Ingrese Peso');
		document.form1.txtpeso.focus();
		return false;
		}
	if (document.form1.txtvolumen.value=='')
		{
		alert('Ingrese Volumen');
		document.form1.txtvolumen.focus();
		return false;
		}
	document.form1.submit();

	}
</script>