<?
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 = $_POST["lstbodega"];	
include("../conex.php");
$sqlbb="SELECT * FROM bodega WHERE Id=$id_bodega";
	$res_bb = mysql_query($sqlbb,$enlace);
	if(mysql_fetch_object($res_bb))	$sql_bodega = mysql_result($res_bb,0 ,"descripcion");

?>
<?

include("../css/mascara_fecha.js");
?>
<!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=iso-8859-1" />
<title>Nota de Venta</title>
</head>
<?

$cant = "1";
$flag=0;
/********************************** Datos Empresa *********************************************************************/
$sql_empresa = "SELECT * FROM empresa, comunas WHERE comunas.cod_comuna = empresa.comuna AND id=$id_empresa";
	$res_empresa = mysql_query($sql_empresa,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_empresa))
		{
		$empresa_rut=mysql_result($res_empresa, $row, "rut_empresa");
		$empresa_nombre=mysql_result($res_empresa, $row, "nombre");
		$empresa_direccion=mysql_result($res_empresa, $row, "direccion");
		$empresa_ciudad=mysql_result($res_empresa, $row, "ciudad");
		$empresa_comuna=mysql_result($res_empresa, $row, "comunas.comuna");
		$empresa_actividad=mysql_result($res_empresa, $row, "actividad");
		$empresa_rut_representante=mysql_result($res_empresa, $row, "rut_representante");
		$empresa_nombre_representante=mysql_result($res_empresa, $row, "nombre_representante");
		$row=$row+1;
		}
	/********************************** Descuentos *********************************************************************/
	$cal_descuento=($txtsubtotal-$txttotal);
	/************************************************** Saca id tipo dcto ***********************************************/	
	$sql_dcto = "SELECT id FROM tipo_dcto WHERE descripcion = 'FACTURA' AND empresa = $id_empresa";
	$res_dcto = mysql_query($sql_dcto,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_dcto))
		{
		$id_tipo_dcto=mysql_result($res_dcto, $row, "id");
		$row=$row+1;
		}
	/************************************************** sacar valor de iva ***********************************************/	
	$sql_par = "SELECT valor FROM parametros WHERE descripcion = 'IVA'";
	$res_par = mysql_query($sql_par,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_par))
		{
		$par_iva=mysql_result($res_par, $row, "valor");
		$row=$row+1;
		}
	/************************************************** calculo neto e iva ***********************************************/	
	
	$sql_total = ($txttotal*$par_iva);
	$sql_iva=(int)$sql_total;
	$r=($sql_total-intval($sql_total))*10;
	$r=(int)$r;
	if ($r>=5)
		{
		$sql_iva+=1;
		$sql_neto = $txttotal-$sql_iva; 
		}
	else
		{
		$sql_neto = $txttotal-$sql_iva;
		}
		$sql_total = $sql_neto + $sql_iva;
	/************************************************** sacar numero boleta *********************************************/		
	/************************************************** sacar tipo dcto *********************************************/		
	$sql_dcto = "SELECT id, correlativo FROM tipo_dcto WHERE descripcion = 'NOTA VENTA' AND empresa = $id_empresa";
	$res_dcto = mysql_query($sql_dcto,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_dcto))
		{
		$id_tipo_dcto = mysql_result($res_dcto, 0, "id");
		$sql_num_bol = mysql_result($res_dcto,0 ,"correlativo");
		$sql_num_bol = $sql_num_bol + 1;
		$row=$row+1;
		}
	$sql_num_nv = $sql_num_bol;

?>

<script type="text/javascript" src="../css/validarut.js"></script>
<body onLoad="fun_descuento();">
<form id="form1" name="form1" method="post" action="">
<input name="txtvalser" type="text" id="txtvalser" style="visibility:hidden" size="1" />
<table width="640" align="center" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="60px"><div align="center"><img src="Images/logo.gif" width="60px" height="60px"></div></td>
	<td width="580px"><div align="left"><font size="1">
		<?=$empresa_nombre?><br>
		<?=$empresa_direccion?><br>
		<?=$empresa_ciudad;?>

		</font></div>
	</td>
    <td width="20%">&nbsp;</td>
  </tr>
</table>


<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr> 
		<td width="10%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"></font></strong></div></td>
		<td width="20%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"></font></strong></div></td>
		<td width="40%"><div align="center"><strong><font color="#000000" face="Arial, Helvetica, sans-serif">NOTA DE VENTA Nº <?=$sql_num_bol?></font></strong></div></td>
		<td width="20%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"></font></strong></div></td>
		<td width="10%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif"></font></strong></div></td>
    </tr>
</table><br>
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td width="100">Fecha:</td>
		<td width="157">
			<input name="txtfecha" type="text" style="border-width:0;" value="<?=$fecha?>" size="23" readonly="1">
	  </td>
		<td width="23">&nbsp;</td>
		<td width="82">&nbsp;</td>
		<td width="308">&nbsp;</td>
	</tr>
	<tr>
		<td width="100">R.U.T.</td>
		<td width="157">
			<input name="txtrut" type="text" onBlur="comprueba()"  onKeyPress="return valida(event)" size="23" maxlength="12"/>
	  </td>
		<td width="23" align="left"><a onClick="JavaScript:PopWindow('buscacliente.php')">
			<IMG align="middle" border="0" src="Images/modificar.gif" style="cursor:pointer" title="Presione aqui para buscar cliente" width="16" height="16"></a>		</td>
		<td width="82" align="right"><div align="left">Señor: &nbsp;</div></td>
		<td width="308">
		  <input name="txtrsoc" id="txtrsoc" type="text" size="44" onKeyPress="validaenter(event,1);" />
		</td>           
  </tr>
<tr>
		<td width="100">E-Mail</td>
		<td width="157">
			<input name="txtemail" id="txtemail" type="text" size="23" onKeyPress="validaenter(event,2);">
		</td>
		<td width="23">&nbsp;</td>
		<td width="82" align="right">
			<div align="left">Actividad: &nbsp;		
	        </div></td>
		<td width="308">
			<input name="txtactividad" id="txtactividad" type="text" size="44" onKeyPress="validaenter(event,3);">
		</td>
	</tr>
<tr>
		<td width="100">Fono: </td>
		<td width="157"><input name="txtfono" id="txtfono" type="text" size="23" onKeyPress="validaenter(event,6);" /></td>
		<td width="23">&nbsp;</td>
		<td width="82" align="right"><div align="left">Regi&oacute;n: &nbsp;</div></td>
		<td width="308"><select name="lstreg" onChange="rellenaCombo('form1');" style="width:290px">
        <option value="null" selected>SELECCIONE REGION
          	<?
			$cons_region = mysql_query("SELECT * FROM regiones;", $enlace);
 			$cont=0;
			while ( mysql_fetch_object ($cons_region) ) 
 			{
 				$ides=mysql_result($cons_region, $cont, "Cod_Region");
  				$nombres=mysql_result($cons_region, $cont, "Region");
  				echo "              <option value=\"".$ides."\">".$nombres."\n";
  				$cont = $cont + 1;
 			}
			?>
      </select></td>
</tr>
	<tr>
		<td width="100">Fax:</td>
		<td width="157"><input name="txtfax" id="txtfax" type="text"  size="23" onKeyPress="validaenter(event,7);" /></td>
		<td width="23">&nbsp;</td>
		<td width="82" align="right"><div align="left">Comuna:&nbsp;		</div></td>
		<td width="308"><select name="lstcom" disabled="disabled" style="width:290px">
        <option value="null">SELECCIONE COMUNA
        </select></td>
	</tr>
	<tr>
		<td width="100">Iva Retenido:</td>
		<td width="157"><input name="txtivar" id="txtivar" type="text" size="23" onKeyPress="return validan(event);" /></td>
		<td width="23">&nbsp;</td>
		<td width="82" align="right"><div align="left">Ciudad:&nbsp;		</div></td>
		<td width="308"><input name="txtciudad" id="txtciudad" type="text" size="44" onKeyPress="validaenter(event,4);" /></td>
	</tr>
		<tr>
		<td width="100">N&ordm; Dcto: </td>
		<td width="157"><input type="text" name="txtndcto" size="23" readonly="1" onKeyPress="return validan(event);" value="<?=$sql_num_nv;?>" onBlur="fun_vndcto()" /></td>
		<td width="23">&nbsp;</td>
		<td width="82" align="right"><div align="left">Direcci&oacute;n:</div></td>
		<td width="308"><input name="txtdireccion" id="txtdireccion" type="text" size="44" onKeyPress="validaenter(event,5);" /></td>
	</tr>
	
	
		<tr>
		<td width="94">Zona</td>
		<td width="148">
		  <?
			$sql_umed = "SELECT * FROM zona ORDER BY descripcion";
			$res_umed = mysql_query($sql_umed,$enlace);
			$contb=0;
			?>
              <select name="lstzona" id="lstzona" style="width:166px;">
			  <?
			  while (mysql_fetch_object ($res_umed))
				{
				$sql_umed_cod = mysql_result($res_umed, $contb, "id");
				$sql_umed_nom = mysql_result($res_umed, $contb, "descripcion");
			?>
                <option value="<?=$sql_umed_cod?>"><? echo $sql_umed_nom;?></option>
			<?
				$contb = $contb+1;
			}
			?>
              </select>		
		</td>
		<td width="26">&nbsp;</td>
		<td width="86" align="right"><div align="left">Vendedor:</div></td>
		<td width="286"><?
			$sql_umed ="SELECT id , nombres AS descripcion FROM vendedor ORDER BY nombres ASC";
			$res_umed = mysql_query($sql_umed,$enlace);
			$contb=0;
			?>
              <select name="lstvendedor" id="lstvendedor" style="width:100%;">
			  <?
			  while (mysql_fetch_object ($res_umed))
				{
				$sql_umed_cod = mysql_result($res_umed, $contb, "id");
				$sql_umed_nom = mysql_result($res_umed, $contb, "descripcion");
			?>
                <option value="<?=$sql_umed_cod?>"><? echo $sql_umed_nom." (".$sql_umed_cod.")";?></option>
			<?
				$contb = $contb+1;
			}
			?>
              </select>		
		</td>
	</tr>
	<tr>
		<td width="94">Bodega</td>
		<td width="148">
		  <input type="text" name="txtbodega" id="txtbodega" size="23" readonly="1" value="<?=$sql_bodega;?>"/>
		</td>
		<td width="26">&nbsp;</td>
		<td width="86" align="right"><div align="left"></div></td>
		<td width="286">&nbsp;</td>
	</tr>
</table>

<br>
<table width="640" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
	<tr bgcolor="#000000"> 
		<td width="8%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Cant.</font></strong></div></td>
		<td width="12%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">C&oacute;digo</font></strong></div></td>
		<td width="35%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Detalle</font></strong></div></td>
		<td width="16%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Nº Chassis</font></strong></div></td>
		<td width="5%"><div align="center"></div></td>
		<td width="12%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Precio</font></strong></div></td>
		<td width="12%"><div align="center"><strong><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Total $</font></strong></div></td>
    </tr>
<? 
$cant = "1";
$cant_real=0;
while ($cant<=$cnt)
	{
	if ($total[$cant]>0)
		{
		$cant_real+=1;
		/********************************** Verifica Seriado *********************************************************************/
	$sql_bpro = "SELECT * FROM productos WHERE codigo = $codigo[$cant]";
	$res_bpro = mysql_query($sql_bpro,$enlace);
	$row=0;
	while (mysql_fetch_object ($res_bpro))
		{
		$bpro_seriado = mysql_result($res_bpro, $row, "producto_seriado_param");
		$row=$row+1;
		}
		
		?>
		
		
		
		<tr> 
			<td><div align="left">
			    <input name="cantidad[<? echo "$cant_real";?>]" id="cantidad[<? echo "$cant_real";?>]" type="text" value="<? echo "$cantidad[$cant]";?>" readonly="1" style="border-width:0;width:100%" border="0">
			</div></td>
			<td><div align="left">
				  <input name="codigo[<? echo "$cant_real";?>]" id="codigo[<? echo "$cant_real";?>]" type="text" value="<? echo "$codigo[$cant]";?>" readonly="1" style="border-width:0;width:100%" border="0">
			</div></td>
			<td><div align="left">  
				<input name="detalle[<? echo "$cant_real";?>]" id="detalle[<? echo "$cant_real";?>]" type="text" value="<? echo "$detalle[$cant]";?>" readonly="1" style="border-width:0;width:100%" border="0">
			</div></td>
			<td><div align="left">  
			
				<input name="seriado[<? echo "$cant_real";?>]" id="seriado[<? echo "$cant_real";?>]" type="text" <? if ($bpro_seriado==0){?> readonly="1"<? }?> style="border-width:0;width:100%" border="0" onBlur="busca_seriado('<? echo "$cant_real";?>');">
			</div></td>
			
			<td width="5%" align="center"><? if ($bpro_seriado==1){?>
				<script language="javascript">
				document.form1.txtvalser.value="1";
				</script>
				<a onClick="JavaScript:PopWindow2('<? echo "$cant_real";?>')">
				<IMG align="middle" border="0" src="Images/modificar.gif" style="cursor:pointer" title="Presione aqui para buscar el número de chassis" width="16" height="16">
			</a><? }else{?>&nbsp;<? }?></td>
			  
			<td><div align="right">
				<input name="precio[<? echo "$cant_real";?>]" id="precio[<? echo "$cant_real";?>]" type="text"value="<? echo "$precio[$cant]";?>" readonly="1" style="border-width:0;text-align:right;width:100%" border="0">
			</div></td>
				
			<td><div align="right">
				<input name="total[<? echo "$cant_real";?>]" id="total[<? echo "$cant_real";?>]" type="text" value="<? echo "$total[$cant]";?>" readonly="1" style="border-width:0;text-align:right;width:100%" border="0">
			</div></td>
		</tr>
		<? 
		}
	$cant=$cant+1;
	}
	?>
	
</table>
<br>
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
	  	<td width="5%">&nbsp;</td>
	  	<td width="5%">&nbsp;</td>
		<td width="35%">&nbsp;</td>
		<td width="40%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">SUB TOTAL</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
        $<input name="sql_subtotal" id="sql_subtotal" type="text" size="9" value="<?=$txtsubtotal?>" readonly="1" style="border-width:0; text-align:right" border="0">
        </font></div></td>
    </tr>
	<tr>
	  	<td width="5%">&nbsp;</td>
	  	<td width="5%">&nbsp;</td>
		<td width="35%">&nbsp;</td>
		<td width="40%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">DESCUENTO</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
        $<input name="sql_descuento" id="sql_descuento" type="text" size="9" value="<?=$cal_descuento;?>" readonly="1" style="border-width:0; text-align:right" border="0">
        </font></div></td>
    </tr>
	<tr>
	  	<td width="5%">&nbsp;</td>
	  	<td width="5%">&nbsp;</td>
		<td width="35%">&nbsp;</td>
		<td width="40%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">NETO</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
        $<input name="sql_neto" id="sql_neto" type="text" size="9" value="<?=$sql_neto?>" readonly="1" style="border-width:0; text-align:right" border="0">
        </font></div></td>
    </tr>
	<tr>
		<td width="5%">&nbsp;</td>
		<td width="5%">&nbsp;</td>
		<td width="35%">&nbsp;</td>
		<td width="40%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">IVA</font></strong></div></td>
		<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
		  $<input name="sql_iva" id="sql_iva" type="text" size="9" value="<?=$sql_iva?>" readonly="1" style="border-width:0;text-align:right" border="0">
	    </font></div></td>
    </tr>
	<tr>
		<td width="5%">&nbsp;</td>
		<td width="5%">&nbsp;</td>
		<td width="35%">&nbsp;</td>
	  	<td width="40%"><div align="right"><strong><font color="#333333" face="Arial, Helvetica, sans-serif">TOTAL </font></strong></div></td>
	  	<td width="15%"><div align="right"><font color="#333333" face="Arial, Helvetica, sans-serif">
	    $<input name="sql_total" id="sql_total" type="text" size="9" value="<?=$sql_total?>" readonly="1" style="border-width:0;text-align:right" border="0">
      </font></div></td>
    </tr>
</table>

<table width="640px" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
	  	<td width="100%" align="center">
			<input type="button" name="correo" id="correo" value="Enviar por correo" onClick="fun_mail();" />
	  		<input type="button" name="Imprimir" id="imprimir" value="Imprimir" onClick="fun_imprimir();" />
			<input type="button" name="guardar" id="guardar" value="Guardar" onClick="fun_guardar();" />
			<input type="button" name="salir" id="salir" value="Salir" onClick="fun_salir();" /></td>
	</tr>
</table>
<input name="txtcom" type="text" id="txtcom" style="visibility:hidden" size="1" />
<input name="txtguardado" type="text" id="txtguardado" style="visibility:hidden" size="1" value="0"/>
<input name="txtcompser" type="text" id="txtcompser" style="visibility:hidden" size="1" />
<input name="txtdes" type="text" id="txtdes" value="<?=$cal_descuento;?>" style="visibility:hidden" size="1" />
<input name="lstzona2" type="text" id="lstzona2" style="visibility:hidden" size="1"/>
<input name="lstvendedor2" type="text" id="lstvendedor2" style="visibility:hidden" size="1"/>
<input name="lstbodega" type="text" id="lstbodega" style="visibility:hidden" size="1" value="<?=$id_bodega;?>" />
</form>
</body>
</html>
<script>
var nav4 = window.Event ? true : false;
<!-- Ingreso solo numeros y k K - . -->
function valida(evt)
	{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57) || (key == 107) || (key == 75) || (key == 45) || (key == 46));
	}
function validan(evt)
	{
	var key = nav4 ? evt.which : evt.keyCode;
	if (key==13) document.form1.txtrsoc.focus()
	return (key <= 13 || (key >= 48 && key <= 57) || (key == 46));
	}
function validaenter(evt, donde)
	{
	var key = nav4 ? evt.which : evt.keyCode;
	if (key==13&& donde==1) document.form1.txtemail.focus();
	if (key==13&& donde==2) document.form1.txtactividad.focus();
	if (key==13&& donde==3) document.form1.txtciudad.focus();
	if (key==13&& donde==4) document.form1.txtdireccion.focus();
	if (key==13&& donde==5) document.form1.txtfono.focus();
	if (key==13&& donde==6) document.form1.txtfax.focus();
	if (key==13&& donde==7) document.form1.menubol4.focus();
	}
function PopWindow(pagina)
	{
	if (pagina=='buscacliente.php')
		{
		window.open(pagina,'TEST','width=682,height=550,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=70,left=300');
		}
	else
		{
		window.open(pagina,'TEST','width=1,height=1,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=70,left=300');
		}
	}
function PopWindow2(cant)
	{
	window.open('buscachassis.php?id='+cant+'&cod='+document.getElementById("codigo["+cant+"]").value,'TEST','width=682,height=550,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=70,left=300');
	}
function comprueba()
	{
	if (Rut(document.form1.txtrut.value)) PopWindow('compruebaf.php?rutc='+document.form1.txtrut.value);
	}
	
function fun_guardar()
	{
	if (document.form1.txtguardado.value==0)
		{
		var answer = confirm ("¿Esta correcto el numero de documento?, \n Si presiona cancelar podra modificar el numero de documento");
		if (answer)
			{
			if (document.form1.txtrut.value!='' && document.form1.txtrsoc.value!='' && document.form1.txtdireccion.value!='' && document.form1.txtciudad.value!='' && document.form1.lstcom.value!= 'null')
				{
				if (document.form1.txtvalser.value=='1'){
					if (document.getElementById("seriado[1]").value==''){
						alert('Ingrese el numero de chassis');
						return false;
						}
					else{
						document.form1.action="notaventa/contado.php?cnt=<?=$cnt?>";
						document.form1.target="_blank";
						document.form1.submit();
						document.form1.txtguardado.value=1;
						}
					}
				else{
					document.form1.action="notaventa/contado.php?cnt=<?=$cnt?>";
					document.form1.target="_blank";
					document.form1.submit();
					document.form1.txtguardado.value=1;
					}
				}
			else
				{
				alert('Ingrese todos los datos del cliente');
				return false;
				}
			}
		else
			{
			document.form1.txtndcto.readOnly = false;
			document.form1.txtndcto.focus();
			return false;
			}
		}
	else
		{
		alert('Este documento ya ha sido guardado');
		return false;
		}
	}
function rellenaCombo(formulario)
    {
        with (document.forms[formulario]) 
        {
          var region = lstreg[lstreg.selectedIndex].value; 
          var n = lstcom.length;  
          
          lstcom.disabled = false;  
          
          for (var i = 0; i < n; ++i)
            lstcom.remove(lstcom.options[i]); 
          
          lstcom[0] = new Option("SELECCIONE CIUDAD", 'null'); 
          
          if (region != 'null')  
          {
   <?php
   
    $cons_region = mysql_query("SELECT * FROM regiones;", $enlace);
    $cont=0;
    while ( mysql_fetch_object ($cons_region) )
    {
     $reg = mysql_result($cons_region, $cont, "Cod_Region");
   ?>
            if (region == '<?php echo $reg;?>')
            {
    <?php
    
      $cons_comuna = mysql_query("SELECT * FROM comunas WHERE region = ".$reg." ORDER BY comuna;", $enlace);
      $cont2=0;
      while ( mysql_fetch_object ($cons_comuna) )
      {
       $id_comuna = mysql_result($cons_comuna, $cont2, "cod_comuna");
       $comuna = mysql_result($cons_comuna, $cont2, "comuna");
    ?>
              lstcom[lstcom.length] = new Option("<?php echo $comuna;?>", '<?php echo $id_comuna;?>');
    <?php
    
	   	$cont2 = $cont2 + 1;
      }
    ?>
            }
   <?php
   
   		$cont = $cont + 1;
    }
   ?>
            lstcom.focus();  
          }
          else  
          {
            lstcom.disabled = true;  
            lstreg.focus(); 
          }
          
          lstcom.selectedIndex = 0;  
        }
	}
function valval()
	{
	var reg=document.form1.lstreg.value;
	var largoven,largozona,i;
	rellenaCombo('form1');
	document.form1.lstcom.value=document.form1.txtcom.value;
	largoven=document.form1.lstvendedor.length;
	largozona=document.form1.lstzona.length;
	for (i=0;i<largozona;i++)
		{
		if (document.form1.lstzona[i].value==document.form1.lstzona2.value)
			{
			document.form1.lstzona.selectedIndex=i;
			}
		}
	for (i=0;i<largoven;i++)
		{
		if (document.form1.lstvendedor[i].value==document.form1.lstvendedor2.value)
			{
			document.form1.lstvendedor.selectedIndex=i;
			}
		}
	}
function fun_salir()
	{
	if (document.form1.txtguardado.value==0)
		{
		var answer = confirm ("No ha guardado la nota de venta, ¿Desea guardarla?\n Si preciona cancelar saldra sin guardar");
		if (answer)
			{
			fun_guardar();
			}
		else
			{
			window.top.open('index.php','Ventas','toolbar=1,location=0,resizable=1,scrollbars=1,width=1250px,height=900px');
			window.top.open('','_parent','');window.top.close();
			}
		}
	else
		{
		var answer = confirm ("¿Seguro desea salir?");
		if (answer)
			{
			window.top.open('','_parent','');window.top.close();
			}
		}
	}
function fun_mail()
	{
	if(document.form1.txtemail.value=="")
		{
		alert ("Ingrese correo");
		document.form1.txtemail.focus();
		return false;
		}
	form1.action="notaventa/correo.php?cnt=<?=$cont?>";
	document.form1.target="_blank";
	form1.submit();
	}	
function fun_descuento()
	{
	var total,i,j,cant1, codigo1, descrip1, precio1, total1, cnt;
	total = <?=$cant_real;?>;
	for (i=1;i<=total;i++){
		for (j=1;j<=(total-1);j++){
			cnt=(j+1);
			if ( Number(document.getElementById("total["+j+"]").value) > Number(document.getElementById("total["+cnt+"]").value))
				{
				
				cant1=document.getElementById("cantidad["+cnt+"]").value;
				codigo1=document.getElementById("codigo["+cnt+"]").value;
				descrip1=document.getElementById("detalle["+cnt+"]").value;
				precio1=document.getElementById("precio["+cnt+"]").value;
				total1=document.getElementById("total["+cnt+"]").value;
				document.getElementById("cantidad["+cnt+"]").value=document.getElementById("cantidad["+j+"]").value;
				document.getElementById("codigo["+cnt+"]").value=document.getElementById("codigo["+j+"]").value;
				document.getElementById("detalle["+cnt+"]").value=document.getElementById("detalle["+j+"]").value;
				document.getElementById("precio["+cnt+"]").value=document.getElementById("precio["+j+"]").value;
				document.getElementById("total["+cnt+"]").value=document.getElementById("total["+j+"]").value;
				document.getElementById("cantidad["+j+"]").value=cant1;
				document.getElementById("codigo["+j+"]").value=codigo1;
				document.getElementById("detalle["+j+"]").value=descrip1;
				document.getElementById("precio["+j+"]").value=precio1;
				document.getElementById("total["+j+"]").value=total1;
				}
			}
		}
	}
function fun_imprimir()
	{
	document.form1.imprimir.style.visibility="hidden";
	document.form1.salir.style.visibility="hidden";
	document.form1.correo.style.visibility="hidden";
	window.print();
	document.form1.imprimir.style.visibility="visible";
	document.form1.salir.style.visibility="visible";
	document.form1.correo.style.visibility="visible";
	}
function busca_seriado(donde)
	{
	if (document.getElementById("seriado["+donde+"]").value!=''){
		PopWindow('busca_seriado.php?d='+document.getElementById("seriado["+donde+"]").value+'&cod='+document.getElementById("codigo["+donde+"]").value);
	    setTimeout('funcion_compser('+donde+');',1000);
		}
	}
function funcion_compser(donde)
	{
	var flag = document.form1.txtcompser.value;
	flag = document.form1.txtcompser.value;
		if (flag==0)
			{
			var answer = confirm ("El número de chassis que ingreso no existe \n(Presione cancelar para ingresar otro chassis \no aceptar para crear uno nuevo)");
			if (answer)
				{
				
				document.getElementById("seriado["+donde+"]").value='';
				window.open('nuevoseriado.php?d='+donde,'TEST','width=682,height=550,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=70,left=300');
				}
			else
				{
				document.getElementById("seriado["+donde+"]").value='';
				//document.getElementById("seriado["+donde+"]").focus();
				}
			}
		if (flag==2)
			{
			
			var answer = confirm ("El Seriado asociado al número de chassis que ingreso no esta completo \n(Presione cancelar para ingresar otro chassis \no aceptar para completar el existente)");
			if (answer)
				{
				var mod_chassis = document.getElementById("seriado["+donde+"]").value;
				window.open('editaseriado.php?c='+mod_chassis+'&d='+donde,'TEST','width=682,height=550,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=70,left=300');
				}
			else
				{
				document.getElementById("seriado["+donde+"]").value='';
				//document.getElementById("seriado["+donde+"]").focus();
				}
			}

	}
function funcion_salir()
	{
	window.top.open('','_parent','');window.top.close();
	}
</script>


