<?php
 session_start();
 include("emenux.php");
 require "funciones.php";
 require ("conecta.php"); 
// include ("emenux.php"); 
 $tipod=$_POST['hdrdbut'];
 $cod_tipo_d=$_POST['hdrdbut'];
 $numero="";
 //********************************
 //********************************
 //********************************
 //********************************
 //asigna folio
 if ($tipod=="01"){//==>factura
  $maxf=1988;
  }
  if ($tipod=="02"){//==>boleta
  $maxf=15205;
  } 
  if ($tipod=="03"){//guia
  $maxf=0; 
  } 
  if ($tipod=="04"){//guia
  $maxf=0; 
  }  
 //********************************
 //********************************
 //********************************
 //********************************
 $sqlf="select max(numero) from m02005 where cod_tipo_d='$tipod' and numero<16000;";
 $resf=mysql_query($sqlf,$con);
 if (mysql_num_rows($resf)>0){
  while ($filaf=mysql_fetch_row($resf)){
   if ($filaf[0]*1>$maxf*1){
    $maxf=($filaf[0]*1);
	}
  }//wend  
 }//fin si 
 //*****************fin asigna folio
 $numerof=$maxf+1;
 $usuario=$_SESSION['nick'];
 $sqlbf="select * from folios where tipo='$tipod' and numero='$numerof';";
 $resbf=mysql_query($sqlbf,$con) or die(mysql_error());
 if (mysql_num_rows($resbf)> 0){ // %%
  $msgbf="Folio ocupado, favor modificar";
  }else{
   $sqlgf="insert into folios (tipo,numero,usuario) values ('$tipod','$numerof','$usuario');";
   $resgf=mysql_query($sqlgf,$con);// or die(mysql_error());
  }// %%
 $fecha=date("Ymd");
 
 $rut=$_POST['rut'];
 if (strlen($rut)==8){
  $rut="0" . $rut;
 }
 $nombre="";
 $giro="";
 $direccion="";
 $cod_comuna="";
 
 $sw=$_POST['hdsw'];
 $sw2=$_POST['hdsw'];
 $cont=0;
 $error2= "0";
 $recomendacion2="0";
 if ($sw=="buscarut"){
  $tipocliente="nuevo";
  $sqlb="select * from m02001 where rut = '$rut' ;";
  $resb=mysql_query($sqlb,$con);
  if (mysql_num_rows($resb)>0){ 
   //$sw="encontrado";
   $sw2="encontrado";
   $tipocliente="antiguo";
   while ($filab = mysql_fetch_row($resb)){
    $nombre=$filab[1];
	$giro=$filab[5];
    $direccion=$filab[2];
    $codcomuna=$filab[3];
	$codciu=$filab[10];
	$fono=$filab[4];
    }//while
   }else{
    $error2= "rut no encontrado.";
    $recomendacion2="->Agregar.";
	$tipocliente="nuevo";
   }//fin si   
  }//fin de buscar
 
 if (strlen($codcomuna)==0){$codcomuna="5406";}
 if (strlen($cod_tipo_d)==0){$cod_tipo_d="01";} 
 //**************************************************
 //**************************************************
 //GRABACION DE ITEMES SELECCIONADOS
 $totalf=$_POST['hdcont'];
 $nick=$_SESSION['nick'];
 $stot=0; 
 //$secl2="recibel2.php?tipo=$tipod";
 $secl2="http://www.automotriz-vemol.cl/recibel2.php?tipo=$tipod&final=$totalf";
  for ($i=1;$i<=$totalf;$i++){
   $icheck="check" . $i;
   $check[$i]=$_POST[$icheck];
   $icodigo="hd" . $i;
   $codigo[$i]=$_POST[$icodigo];
   $codc=$codigo[$i];
   $icant="hdcant" . $i;
   $cant[$i]=$_POST[$icant];
   $ipre="hdpre" . $i;
   $pre[$i]=$_POST[$ipre];   
   if($check[$i]=="checkbox"){
    $final2++;
    $stot=$stot + ($pre[$i]*$cant[$i]);
    $code=$codigo[$i];
	$secl2=$secl2 . "&cod" ."$i=" .  $codigo[$i] . "&can" . "$i=" .  $cant[$i] . "&pre" . "$i=" . $pre[$i];	
    $sqle="update m02004 set estado='1' where llave='$nick' and cod_interno='$codc';";
    $rese=mysql_query($sqle,$con) or die(mysql_error());
   }
  }//for
  $secl2=$secl2 . "&final=" . $final2;
  if ($sw <> "buscarut"){
   $_SESSION['entradal2']=$secl2;	 
  }	
  $cadenal2=$_SESSION['entradal2'];
  if (isset($_POST['hdcont'])){
   $neto=round($stot/1.19);
   $iva=$stot-$neto;
   $total=$neto + $iva;
  }else{
   $neto=$_POST['neto'];
   $iva=$_POST['iva']; 
   $total=$_POST['total'];
  }
?>
<!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>Finalizando Pedido</TITLE>
<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function buscar(){
   open("popupB.php?nombre=" + document.form1.rut.value ); 
 }
function ponecomuna(){
 document.form1.hdcom.value=document.form1.cmbcom.value;
 }
function ponecomuna(){
 document.form1.hdcom2.value=document.form1.cmbcom2.value;
 } 
function buscarut(){  
 if (event.keyCode==13 || event.keyCode==9 ){
  if (modulo11(document.form1.rut.value)!= -1){
   document.form1.hdsw.value="buscarut";
   document.form1.action="M0205002.php";
   document.form1.method="post";
   document.form1.neto.disabled=false;
   document.form1.iva.disabled=false;
   document.form1.stotal.disabled=false;
   document.form1.submit(); 
   }else{
    window.alert("el rut ingresado es incorrecto");
   }//fin modulo11
  }
}//fin funcion

function ponetipo(){
 document.form1.hdtipod.value=document.form1.cmbtipod.value;
}
function valida(){  
 if (document.form1.cmbtipod.value!="02"  &&  document.form1.cmbtipod.value!="04" ){
 if (document.form1.rut.value.length > 0){
  err=0;
  document.form1.hdsw.value="grabar";
  if (modulo11(document.form1.rut.value)==-1  ){
   window.alert("El rut ingresado es incorrecto" );
   err=1;
   document.form1.rut.style.backgroundColor="#FFFFCC";
   document.form1.rut.focus();  
   }  
  if (document.form1.nombre.value.length==0){
   err=1;
   window.alert("debe ingresar nombre");
   document.form1.nombre.style.backgroundColor="#FFFFCC";
   document.form1.nombre.focus();
   } 
  if (document.form1.direccion.value.length==0){
   err=1;
   window.alert("debe ingresar direccion");
   document.form1.direccion.style.backgroundColor="#FFFFCC";
   document.form1.direccion.focus();
   }  
  if (document.form1.cpago.value=="00"){
   err=1;
   window.alert("debe ingresar forma de pago");
   document.form1.cpago.style.backgroundColor="#FFFFCC";
   document.form1.cpago.focus()
  } 
  
  if ((document.form1.cpago.value=="002" || document.form1.cpago.value=="010") && document.form1.fechac.lenght != 10){
   //err=1;
   //window.alert("debe ingresar cheque y fecha del mismo");
   //document.form1.fechac.style.backgroundColor="#FFFFCC";
   //document.form1.fechac.focus()
  }
  if (err==0){
   //ocupamos instrucciones de ponedirecto()
   //***************************************
   document.form1.neto.value=Math.round(document.form1.total.value/1.19);
   document.form1.iva.value=document.form1.total.value - document.form1.neto.value; 
   var dif = (document.form1.stotal.value - document.form1.neto.value);
   document.form1.d1.value=(dif*100)/document.form1.neto.value;
   //***********************************************************
   document.form1.numero.disabled=false;
   document.form1.neto.disabled=false;
   document.form1.iva.disabled=false;
   document.form1.stotal.disabled=false;
   document.form1.action="grabaventa.php"
   document.form1.method="post";
   //window.alert(document.form1.numero.disabled=false);
   //*******************************
   actl2();
   document.form1.submit();   
   }else{
    window.alert("debe ingresar correctamente datos solicitados");
   }  
 }//fin si  
 }else{ //boleta o guia interna
  //window.alert(document.form1.numero.value);
  err=0;  
  if ((document.form1.cpago.value=="002" || document.form1.cpago.value=="010") && (document.form1.fechac.value.length != 10)){
   //err=1;
   //window.alert(document.form1.fechac.value.length);
   //window.alert(document.form1.cpago.value);
   //window.alert("debe ingresar cheque y fecha del mismo");
   //document.form1.fechac.style.backgroundColor="#FFFFCC";
   //document.form1.fechac.focus()
  }else{
   //err=0;
  }
  if (err==0){
   document.form1.numero.disabled=false;
   document.form1.neto.disabled=false;
   document.form1.iva.disabled=false;
   document.form1.stotal.disabled=false;
   document.form1.action="grabaventa.php"
   document.form1.method="post"; 
   //*************************
   actl2(); 
   document.form1.submit();  
   }
 }
}  
function ponedesc(){
 if (event.keyCode==13){
 document.form1.neto.value=document.form1.stotal.value-Math.round((document.form1.stotal.value* document.form1.d1.value/100)); 
 document.form1.iva.value=Math.round(document.form1.neto.value*0.19);
 document.form1.total.value=(document.form1.neto.value *1) + (document.form1.iva.value*1);
 }
}
function ponecpago(){
 var a = new String();
 a=document.form1.cpago.options[document.form1.cpago.selectedIndex].text; 
 if( a.substr(0,6)=="CHEQUE" ){
  document.form1.cheque.disabled=false;
  document.form1.banco.disabled=false;
  document.form1.fechac.disabled=false;
  document.form1.cheque.focus();
 }
 //window.alert(document.form1.cpago.value);
}//fin ponecpago
function ponecheque(){
 if (event.keyCode==13){
  document.form1.banco.focus();
 }
}
function ponebanco(){
 if (event.keyCode==13){
  document.form1.fechac.focus();
 }
}
function ponedirecto(){
 if (event.keyCode==13){
 document.form1.neto.value=Math.round(document.form1.total.value/1.19);
 document.form1.iva.value=document.form1.total.value - document.form1.neto.value; 
 var dif = (document.form1.stotal.value - document.form1.neto.value);
 document.form1.d1.value=(dif*100)/document.form1.neto.value;
 }
}
function actl2(){ 
 window.open("<?php echo  $cadenal2 ?>" + "&rut=" + document.form1.rut.value + "&numero=" + document.form1.numero.value);
}
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {color: #0000FF}
.Estilo2 {color: #FF0000}
-->
</style>
</HEAD>
<BODY <?php
 if ($sw=="buscar"){
  echo "onload='javascript:(document.form1.nombre.focus())'";
  }
 if ($sw=="grabar" || $sw=="eliminar"){
  echo "onload='javascript:(document.form1.rut.focus())'";
  } 
 if ($sw=="encontrado" ){
  echo "onload='javascript:(document.form1.cmdgra.focus())'";
  }  
  ?>>
  <form id="form1" name="form1" method="post" action="m0205002.php">
<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 src="images/xc_left.gif" alt="Inicio" width=24 
                  height=22 
                  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 cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD vAlign=top align=left width=180 height=18>&nbsp;</TD>
                <TD width=12 height=18>&nbsp;</TD>
                <TD width="461" height=18 class=MainMenuHead><div align="left">Proceso de Venta :</div></TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD vAlign=top align=left width=180 height="100%">
                  <TABLE cellSpacing=0 cellPadding=0 width="150" border=0>
                    <TBODY>
                    <TR>
                      <TD width=10 valign="top"><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD width=4>&nbsp;</TD>
                      <TD class=LeftMenu noWrap><p>Acciones de Venta:<br />
                        -&gt;<a href="carro.php">Ver Carro de Compra.</a><br />
                          -&gt;<a href="M0205001.php">Volver a buscar Articulos</a> <br />
                          </p>
                        </TD>
                    </TR>
                    <tr>
                      <td valign="top"><img 
                        src="images/xc_dotgrey.gif" width="10" height="12" /></td>
                      <td>&nbsp;</td>
                      <td class="LeftMenu" nowrap="nowrap">Alertas:<br />                        <span class="Estilo2"><?php echo $msgbf ?><br />
                            </span></td>
                    </tr>
                    <tr>
                      <td valign="top"><img 
                        src="images/xc_dotgrey.gif" width="10" height="12" /></td>
                      <td>&nbsp;</td>
                      <TD class=LeftMenu noWrap>Se recomienda:<span class="Estilo1"><br />
                          <?php echo $recomendacion2 ?></span></TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=12 height="100%">&nbsp;</TD>
                <TD class=contentcell vAlign=top align=middle width=461 
                height="100%"><table width="90%" border="0" cellspacing="0" cellpadding="0">
				 <tr>
                    <th width="16%" scope="col"><div align="right" class="Emphasize">Tipo:</div></th>
                    <th width="33%" scope="col"><div align="left">
                        <?php
									$sqltip="select * from m02006 order by 2;";
									$restip=mysql_query($sqltip,$con) or die(mysql_error())  ;				
								?>
                        <select name="cmbtipod" id="cmbtipod" onchange="ponetipo()">
                          <?php 
									while ($filatip=mysql_fetch_row($restip)){
									if ($filatip[0]==$cod_tipo_d){
				                  	echo "<option value=$filatip[0] selected='selected'>$filatip[1]</option>";
									}else{
									 //echo "<option value=$filatip[0]>$filatip[1]</option>";
									 }//si
									}
								?>
                        </select>
                        <input name="hdtipod" type="hidden" id="hdtipod" value="<?php echo $cod_tipo_d ?>"/>
                        <input name="hdsw" type="hidden" id="hdsw" value="nada" />
                    </div></th>
                    <th width="15%" scope="col"><div align="right"><span class="Emphasize">Numero:</span></div></th>
                    <th width="36" colspan="2" scope="col"><div align="left">
                      <input name="numero" type="text" id="numero"  value="<?php echo $numerof ?>" size="11" maxlength="10" disabled="disabled" >
                      <label>
                      <input name="habnum" type="button" id="habnum" value="Corrige" onclick="javascript:document.form1.numero.disabled=false;document.form1.numero.focus();" />
                                  </label>
                    </div></th>
                  </tr>

                  <tr>
                    <th scope="row"><div align="right" class="Emphasize">Fecha:</div></th>
                    <td><div align="left">
                      <input name="fecha" type="text" id="fecha" value="<?php if (strlen($fecha)==8) echo editafecha($fecha); ?>" size="10" maxlength="10"/>
                    </div></td>
                    <td><div align="right"><span class="Emphasize">Vendedor:</span></div></td>
                    <td colspan="2"><div align="left">
                      <input name="usuario" type="text" id="usuario" value="<?php echo $usuario ?>" size="11" maxlength="10"/>
                    </div></td>
                  </tr>

                  <tr>
                    <th scope="row"><label>
                        <div align="right" class="Emphasize">Rut:</div>
                        </label></th>
                    <td colspan="4"><div align="left">
                      <input name="rut" type="text" id="rut" value="<?php echo $rut ?>" size="10" maxlength="9" onkeydown="buscarut();" />
                      <img src="images/i.p.search.gif" alt="Buscar Rut" width="22" height="18" longdesc="Buscar Rut" onclick="buscar()" /></div></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                        <div align="right" class="Emphasize">Nombre:</div>
                        </label></th>
                    <td colspan="4"><div align="left">
                      <input name="nombre" type="text" id="nombre" value="<?php echo $nombre ?>" size="50" maxlength="100" />
                    </div></td>
                  </tr>
                  <tr>
                    <td scope="row"><label>
                        <div align="right" class="Emphasize">Giro:</div>
                        </label></td>
                    <td colspan="4"><div align="left">
                        <input name="giro" type="text" id="giro" value="<?php echo $giro ?>" size="50" maxlength="100" />
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                        <div align="right" class="Emphasize">Direcci&oacute;n:</div>
                      </label></th>
                    <td colspan="4"><div align="left">
                      <input name="direccion" type="text" id="direccion" value="<?php echo $direccion ?>" size="50" maxlength="100" />
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><div align="right" class="Emphasize">Comuna:</div></th>
                    <td colspan="2">
                          <div align="left">
                            <?php
									$sqlcom="select * from m01003 order by 2;";
									$rescom=mysql_query($sqlcom,$con) ;				
								?>
                                <select name="cmbcom" id="cmbcom" onchange="ponecomuna()">
                                  <?php 
									while ($fila=mysql_fetch_row($rescom)){
									if ($fila[0]==$codcomuna){
				                  	echo "<option value=$fila[0] selected='selected'>$fila[1]</option>";
									}else{
									 echo "<option value=$fila[0]>$fila[1]</option>";
									 }//si
									}
								?>
                                  </select>                      
                            <input name="hdcom" type="hidden" id="hdcom" value="<?php echo $codcomuna ?>"/>
                                </div></td>
                    <td><div align="right" class="Emphasize">Ciudad:</div></td>
                    <td><?php
									$sqlcom="select * from m01003 order by 2;";
									$rescom=mysql_query($sqlcom,$con) ;				
								?>
                      <select name="cmbcom2" id="cmbcom2" onchange="poneciudad()">
                        <?php 
									while ($fila=mysql_fetch_row($rescom)){
									if ($fila[0]==$codciu){
				                  	echo "<option value=$fila[0] selected='selected'>$fila[1]</option>";
									}else{
									 echo "<option value=$fila[0]>$fila[1]</option>";
									 }//si
									}
								?>
                                </select>
                      <input name="hdcom2" type="hidden" id="hdcom2" value="<?php echo $codcomuna ?>"/>
                      <input name="hdtipocliente" type="hidden" id="hdtipocliente" value="<?php echo $tipocliente ?>"/></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                        <div align="right" class="Emphasize">Telefono:</div>
                        </label></th>
                    <td height="25" colspan="4"><div align="left">
                      <input name="telefono" type="text" id="telefono" align="right"  value="<?php echo $fono ?>" size="11" maxlength="10" />
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                      <div align="right" class="Emphasize">Sub total:</div></th>
                    <td colspan="4"><input name="stotal" type="text" id="stotal" align="right"  value="<?php echo $neto ?>" size="11" maxlength="10" disabled/></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                        <div align="right" class="Emphasize">%DESC.1:</div>
                        </label></th>
                    <td colspan="4"><div align="left">                      <label> </label>
                      <div align="right" class="Emphasize">
                        <div align="left">
                            <input name="d1" type="text" id="d1" value="0" size="5" maxlength="2" onkeydown="ponedesc()"/>
                        </div>
                      </div>                    
                       </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><label>
                        <div align="right"><span class="Emphasize">Neto</span>:</div>
                        </label></th>
                    <td colspan="4"><div align="left">
                      <input name="neto" type="text" id="neto" value="<?php echo $neto ?>" size="11" maxlength="10" disabled/>
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><div align="right"><span class="Emphasize">IVA</span>:</div></th>
                    <td colspan="4"><div align="left">
                      <input name="iva" type="text" id="iva" value="<?php echo $iva ?>" size="11" maxlength="10" disabled />
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><div align="right"><span class="Emphasize">Total:</span></div></th>
                    <td colspan="4"><div align="left">
                      <input name="total" type="text" id="total2" value="<?php echo $total ?>" size="11" maxlength="10" onkeydown="ponedirecto();" />
                    </div></td>
                  </tr>
                  <tr>
                    <th scope="row"><div align="right"><span class="Emphasize">Cond.Pago:</span></div></th>
                    <td colspan="2"><div align="left">
					<select name="cpago" id="cpago" onchange="ponecpago()" >
					<option value='00'>Seleccione una</option>
				    <?php
					   $sqlcp="select * from m01002 order by 2;";
					   $rescp=mysql_query($sqlcp,$con);
					   while ($filacp=mysql_fetch_array($rescp)){ 					  
					    echo "<option value=$filacp[0]>$filacp[1]</option>";
						}
					  ?>
                      </select>
                    </div></td>
                    <td><div align="right"><span class="Emphasize">&nbsp;&nbsp;&nbsp;&nbsp;N.cheq. </span></div>                      <span class="Emphasize"><label></label>
                    </span></td>
                    <td><input name="cheque" type="text" disabled="disabled" id="cheque" size="15" maxlength="15" onkeydown="ponecheque()"/></td>
                  </tr>
                  <tr>
                    <th scope="row">&nbsp;&nbsp;
                      <div align="right"><span class="Emphasize">Banco:</span></div></th>
                    <td colspan="2"><input name="banco" type="text" disabled="disabled" id="banco" size="25" maxlength="15"  onkeydown="ponebanco()"/></td>
                    <td><div align="right"><span class="Emphasize">&nbsp;Fecha. </span></div>                      <span class="Emphasize"><label></label>
                    </span></td>
                    <td><input name="fechac" type="text" disabled="disabled" id="fechac" size="15" maxlength="15" /></td>
                  </tr>
                  <tr>
                    <th colspan="5" scope="row">&nbsp;</th>
                  </tr>
                  <tr>
                    <th colspan="5" scope="row"><input name="cmdgra" type="button" id="cmdgra" value="Grabar" onclick="valida()" />
                      <input name="cmcan" type="button" id="cmcan" value="Cancelar" onclick="eliminar()"/> <input name="hdrdbut" type="hidden" id="hdrdbut" value="<?php echo $tipod ?>" />                      </th>
                  </tr>
                </table></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD width=180 height=8>&nbsp;</TD>
                <TD width=12 height=8>&nbsp;</TD>
                <TD width="461" height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
      <p>&nbsp;</p></TD></TR></TBODY>
	  <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>
</form>  
</BODY>
<?php
	mysql_close($con);
?>
</HTML>