<?
ini_set('error_reporting', 1);
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
?>
<title>Busqueda Cliente</title>
<style type="text/css">
<!--
.Estilo15 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
-->
</style>
<?

$cant = $_GET["id"];
$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.png" width="120" height="120"></div></td>
	<td width="50%"><div align="center"><strong><font size="6">Buscar Cliente </font></strong></div></td>
    <td width="25%">&nbsp;</td>
  </tr>
</table>


<form name="form1" method="post" action="buscacliente.php?b<? echo "2";?>">
  <table width="79%"align="center" border="0">

    <tr>
      <td width="20%">Razon social:</td>
      <td width="65%"><label>
        <input name="txtcli" type="text" id="txtcli" size="65">
      </label></td>
      <td width="15%"><label>
        <input name="enviar" type="submit" id="enviar" value="Buscar">
      </label></td>
    </tr>
  </table>
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000080"><span lang="es-cl"><b>
   		<a onClick="JavaScript:post_letra('A');" style="cursor:pointer">A</a>
 		<a onClick="JavaScript:post_letra('B');" style="cursor:pointer">B</a>
 		<a onClick="JavaScript:post_letra('C');" style="cursor:pointer">C</a>
		<a onClick="JavaScript:post_letra('D');" style="cursor:pointer">D</a>
		<a onClick="JavaScript:post_letra('E');" style="cursor:pointer">E</a>
		<a onClick="JavaScript:post_letra('F');" style="cursor:pointer">F</a>
		<a onClick="JavaScript:post_letra('G');" style="cursor:pointer">G</a>
		<a onClick="JavaScript:post_letra('H');" style="cursor:pointer">H</a>
		<a onClick="JavaScript:post_letra('I');" style="cursor:pointer">I</a>
		<a onClick="JavaScript:post_letra('J');" style="cursor:pointer">J</a>
		<a onClick="JavaScript:post_letra('K');" style="cursor:pointer">K</a>
		<a onClick="JavaScript:post_letra('L');" style="cursor:pointer">L</a>
		<a onClick="JavaScript:post_letra('M');" style="cursor:pointer">M</a>
		<a onClick="JavaScript:post_letra('N');" style="cursor:pointer">N</a>
		<a onClick="JavaScript:post_letra('O');" style="cursor:pointer">O</a>
		<a onClick="JavaScript:post_letra('P');" style="cursor:pointer">P</a>
		<a onClick="JavaScript:post_letra('Q');" style="cursor:pointer">Q</a>
		<a onClick="JavaScript:post_letra('R');" style="cursor:pointer">R</a>
		<a onClick="JavaScript:post_letra('S');" style="cursor:pointer">S</a>
		<a onClick="JavaScript:post_letra('T');" style="cursor:pointer">T</a>
		<a onClick="JavaScript:post_letra('U');" style="cursor:pointer">U</a>
		<a onClick="JavaScript:post_letra('V');" style="cursor:pointer">V</a>
		<a onClick="JavaScript:post_letra('W');" style="cursor:pointer">W</a>
		<a onClick="JavaScript:post_letra('X');" style="cursor:pointer">X</a>
		<a onClick="JavaScript:post_letra('Y');" style="cursor:pointer">Y</a>
		<a onClick="JavaScript:post_letra('Z');" style="cursor:pointer">Z</a>
		<br></b></span></font> </div>
</form>
	<?
	$cont=0;
	$caract=$_GET["caracter"];	
	if (isset($caract)) 
		{
		$sql_bc = "SELECT * FROM nombres, sucursales WHERE sucursales.razon_social LIKE '$caract%' AND nombres.cliente = 'True' AND nombres.rut =sucursales.rut ORDER BY sucursales.razon_social ASC";
		$res_bc =mysql_query($sql_bc,$enlace);
		}
	else if ( $txtcli!="" )
		{
		$sql_bc = "SELECT * FROM nombres, sucursales WHERE sucursales.razon_social LIKE '%$txtcli%' AND nombres.cliente = 'True' AND nombres.rut =sucursales.rut ORDER BY sucursales.razon_social ASC";
	$res_bc = mysql_query($sql_bc,$enlace);
		}
	else
		{
		$sql_bc = "SELECT * FROM nombres, sucursales WHERE sucursales.razon_social LIKE '%' AND nombres.cliente = 'True'  AND nombres.rut =sucursales.rut ORDER BY sucursales.razon_social ASC";
	$res_bc = mysql_query($sql_bc,$enlace);
		}
	while (mysql_fetch_object ($res_bc))
		{
		$bc_rut = mysql_result($res_bc, $cont, "sucursales.rut");
		$bc_rsuc = mysql_result($res_bc, $cont, "sucursales.sucursal");
		$bc_rsoc = mysql_result($res_bc, $cont, "sucursales.razon_social");
		if ($cont==0)
			{
		?>
		<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
			<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="17%" align="center">
				R.U.T.			</td>
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="55%" align="center">
				Razón Social			</td>
       

<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="6%" align="center">
				Enviar			</td>
		</tr>
        
		<? 
			}
		?>
		<tr>
	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="17%" align="right">
				<?=$bc_rut;?></td>
<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="55%" align="left">
		  <?=$bc_rsoc;?>  <?=$bc_rsuc;?></td> 
             
	<td class="Estilo15" style="border:double; border-width:3px; border-color:#0F0F0F" width="6%" align="center">
			<a onClick="JavaScript:enviar('<?=$bc_rut;?>','<?=$bc_rsuc;?>')">
			<IMG align=top  border=0 src="../Images/ir.gif" style="cursor:pointer" title="Presione aqui para enviar este código">			</a>		</td>
	</tr>
	
	<?
	$cont=$cont+1;
	}
	?>
</table>



<script languaje="javascript">
	
	function post_letra(letra)
	{
	document.form1.action = "buscacliente.php?b="+<? echo "2";?>+"&caracter="+letra;
	document.form1.submit();
	}
	function enviar(rut,suc)
		{
		window.opener.document.form1.txtrut.value = rut;
		window.opener.document.form1.txtsucursal.value = suc;
		window.opener.document.form1.txtrut.focus();
		window.opener.document.form1.txtrsoc.focus();
		window.close();
		}
	</script>
