<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = 'index.php';
		</script>
		<? 
		exit();
		}
?>
<?
include "../conex.php";
$rut_cliente_buscar = $_GET["rutc"];
$sql_bc = "SELECT * FROM nombres, comunas WHERE nombres.rut = '$rut_cliente_buscar' AND comunas.cod_comuna=nombres.comuna";
	$res_bc = mysql_query($sql_bc,$enlace);
	if(mysql_fetch_object($res_bc))
		{
		$bc_estado = mysql_result($res_bc, $cont, "nombres.cliente");
		$bc_rut = mysql_result($res_bc, $cont, "rut");
		$bc_rsoc = mysql_result($res_bc, $cont, "razon_social");
		$bc_dire = mysql_result($res_bc, $cont, "direccion");
		$bc_mail = mysql_result($res_bc, $cont, "email");
		$bc_ciud = mysql_result($res_bc, $cont, "ciudad");
		$bc_act = mysql_result($res_bc, $cont, "rubro_giro");
		$bc_comu = mysql_result($res_bc, $cont, "nombres.comuna");
		$bc_reg = mysql_result($res_bc, $cont, "nombres.region");
		$bc_fono = mysql_result($res_bc, $cont, "fono1");
		$bc_fax = mysql_result($res_bc, $cont, "fax");
		}
?>
	<script languaje="javascript">
	
	function rellenaCombo(formulario)
      {
        with (window.opener.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'); 
          alert (region);
          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;  
        }
	}
	if ('<? echo $bc_estado;?>'=='True'){
		window.opener.document.form1.txtrsoc.value = '<? echo $bc_rsoc;?>';
		window.opener.document.form1.txtdireccion.value = '<? echo $bc_dire;?>';
		window.opener.document.form1.txtemail.value = '<? echo $bc_mail;?>';
		window.opener.document.form1.txtciudad.value = '<? echo $bc_ciud;?>';
		window.opener.document.form1.txtactividad.value = '<? echo $bc_act;?>';
		window.opener.document.form1.lstcom.disabled = false;
		window.opener.document.form1.lstreg.value = '<? echo $bc_reg;?>';
		window.opener.document.form1.txtcom.value='<? echo $bc_comu;?>';	
		window.opener.document.form1.txtfono.value = '<? echo $bc_fono;?>';
		window.opener.document.form1.txtfax.value = '<? echo $bc_fax;?>';
		window.opener.valval();
		}
	else if ('<? echo $bc_estado;?>'=='False'){
		window.opener.document.form1.txtrut.value ='';
		window.opener.document.form1.txtrsoc.value = '';
		window.opener.document.form1.txtdireccion.value = '';
		window.opener.document.form1.txtemail.value = '';
		window.opener.document.form1.txtciudad.value = '';
		window.opener.document.form1.txtactividad.value = '';
		window.opener.document.form1.lstreg.value = '';
		window.opener.document.form1.txtcom.value='';	
		window.opener.document.form1.txtfono.value = '';
		window.opener.document.form1.txtfax.value = '';
		alert("El Rut ingresado no corresponde a un proveedor");
		}
		window.close();
		
	</script>
