<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<title>Busqueda Chassis</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"];
$bcodigoprod = $_GET["cod"];
$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.gif" width="120" height="120"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">Buscar Seriado</font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>


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

    <tr>
      <td width="20%">Ingrese parte del Numero de Chassis :</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>
</form>
	<?
	if ($enviar!=3){
		$cont=0;
		if ( $textcodigo!="" )
			{
			$bsql = "SELECT * FROM seriado WHERE chassis LIKE '%$textcodigo%' AND num_salida=0 AND cod_producto = $bcodigoprod;";
			$resultado =mysql_query($bsql,$enlace);
			}
		else
			{
			$bsql = "SELECT * FROM seriado WHERE chassis LIKE 'a%' AND num_salida=0 AND cod_producto = $bcodigoprod;";
			$resultado =mysql_query($bsql,$enlace);
			}
		while (mysql_fetch_object ($resultado))
			{
			$bsql_marca=mysql_result($resultado, $cont, "marca");
			$bsql_modelo=mysql_result($resultado, $cont, "modelo");
			$bsql_motor=mysql_result($resultado, $cont, "motor");
			$bsql_chassis=mysql_result($resultado, $cont, "chassis");
			$bsql_color=mysql_result($resultado, $cont, "color");
			$bsql_ano=mysql_result($resultado, $cont, "ano");
			$bsql_peso_bruto=mysql_result($resultado, $cont, "peso_bruto");
			$bsql_combustible=mysql_result($resultado, $cont, "combustible");
			$bsql_descripcion=mysql_result($resultado, $cont, "descripcion");
	
			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="20%" align="center">Chassis</td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="center">Marca</td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="25%" align="center">Modelo</td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="20%" align="center">Color</td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="5%" align="center">Ver</td>
			</tr>
			<? 
				}
			?>
			<tr>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="8%" align="left"><?=$bsql_chassis;?></td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="12%" align="left"><?=$bsql_marca?></td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="20%" align="left"><?=$bsql_modelo?></td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="50%" align="left"><?=$bsql_color?></td>
				<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="10%" align="center"><a onClick="JavaScript:enviar('<?=$bsql_chassis;?>')"><IMG align=top  border=0 src="Images/ir.gif" style="cursor:pointer" title="Presione aqui para ver este seriado"></a></td>
		</tr>
		
		<?
		$cont=$cont+1;
		}
		?>
	</table>
	<?	}
	if($enviar==3)
		{
		$bsql_chassis = $_GET["chass"];
		$bsql = "SELECT * FROM seriado WHERE chassis LIKE '$bsql_chassis'";
		$resultado =mysql_query($bsql,$enlace);
		$cont=0;
		while (mysql_fetch_object ($resultado))
			{
			$bsql_marca=mysql_result($resultado, $cont, "marca");
			$bsql_modelo=mysql_result($resultado, $cont, "modelo");
			$bsql_motor=mysql_result($resultado, $cont, "motor");
			$bsql_chassis=mysql_result($resultado, $cont, "chassis");
			$bsql_color=mysql_result($resultado, $cont, "color");
			$bsql_ano=mysql_result($resultado, $cont, "ano");
			$bsql_peso_bruto=mysql_result($resultado, $cont, "peso_bruto");
			$bsql_combustible=mysql_result($resultado, $cont, "combustible");
			$bsql_descripcion=mysql_result($resultado, $cont, "descripcion");
			$cont=$cont+1;
			}
		?>
	<form id="form2" name="form2" method="post" action="actualiza_chassis.php?d=<?=$cant;?>" target="formulario">
	<div align="center">
<table width="95%" border="0">
    <tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Marca</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtmarca" id="txtmarca" style="border-width:0;width:100%" border="0" value="<?=$bsql_marca;?>">		
		</td>
	</tr>
    <tr>
    	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Modelo</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtmodelo" id="txtmodelo" style="border-width:0;width:100%" border="0" value="<?=$bsql_modelo;?>">		
		</td>
        </tr>
	<tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Motor</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtmotor" id="txtmotor" style="border-width:0;width:100%" border="0" value="<?=$bsql_motor;?>">		
		</td>
	</tr>
	<tr>
    	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Chassis</td>
    	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtchassis" id="txtchassis" style="border-width:0;width:100%" border="0" value="<?=$bsql_chassis;?>" readonly="1">		
		</td>
	</tr>
	<tr>
		<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Color</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtcolor" id="txtcolor" style="border-width:0;width:100%" border="0" value="<?=$bsql_color;?>">		
		</td>
	</tr>
	<tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">A&ntilde;o</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtano" id="txtano" style="border-width:0;width:100%" border="0" value="<?=$bsql_ano;?>" onKeyPress="return validanum(event)">		
		</td>
	</tr>
	<tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Peso Bruto Vehicular </td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtpeso" id="txtpeso" style="border-width:0;width:100%" border="0" value="<?=$bsql_peso_bruto;?>">		
		</td>
	</tr>
	<tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Combustible</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtcombustible" id="txtcombustible" style="border-width:0;width:100%" border="0" value="<?=$bsql_combustible;?>">		
		</td>
    </tr>
	<tr>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="30%" align="left">Descripci&oacute;n</td>
        <td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="60%" align="left">
            <input type="text" name="txtdescripcion" id="txtdescripcion" style="border-width:0;width:100%" border="0" value="<?=$bsql_descripcion;?>">		
		</td>
    </tr>
</table>
<table width="95%" border="0">
	<tr>
		<td><div align="center">
			<input type="button" name="Submit" value="Enviar" onclick="envi();">
		</div></td>
	</tr>
</table>
</div>
      
	</form>
<?
		}
	?>
<div align="center">
	<iframe name="formulario" src="blanco.htm" width=1px height=1px AllowTransparency="true" frameborder="0"></iframe>
</div>
<script language="Javascript">
<!--
var nav4 = window.Event ? true : false;
	<!-- Ingreso solo letras y espacio -->
function validanum(evt)
	{
	var key = nav4 ? evt.which : evt.keyCode;
	return (key < 13 || (key >= 48 && key <= 57));
	}

function enviar(cod)
	{
	document.form1.action = "buscachassis.php?id=<?=$cant?>&b=3&chass="+cod;
	document.form1.submit();
	}
function envi()
	{
	window.opener.document.getElementById("seriado[<? echo "$cant";?>]").value = '<?=$bsql_chassis?>';
	document.form2.submit();
	}
</script>
