<? include("../../../header_subnivel3.php");
include("../../../conexion3.php");include("../../../funciones.php");
/*mysql_connect ("localhost", "root","") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("interteam");*/

?>
<link rel="stylesheet" type="text/css" href="../../../style.css" media="all" />

<script language="Javascript">

function preguntar(inst1,dato){

eliminar=confirm("Do you really want to delete it ? " + dato);

if (eliminar)

window.location.href = inst1; 
}

</script>

<script> 

function ponPrefijo(pref,name,fax,tel,email,idcto,login){ 
	  asign(parent.document.getElementById('txtcustomsagent'),pref)
	  asign(parent.document.getElementById('txtcustomscontact'),name)
      asign(parent.document.getElementById('txtcustomsfax'),tel)
	  asign(parent.document.getElementById('txtcustomstel'),fax)
      asign(parent.document.getElementById('txtcustomsemail'),email)
	  asign(parent.document.getElementById('txtidaa'),idcto)
	  asign(parent.document.getElementById('txtlogin'),login)
	  if(parent.document.getElementById('customsagentsBox')){
	  parent.document.getElementById('customsagentsBox').close() 
	  }
} 

function ponref(pref){ 

    this.document.form12.txtbusca.value =pref

		this.document.form12.submit();

}  



</script> 
<div align="justify" style="line-height:18px;margin-top:-44px; position:absolute;width: 1160px; height:100%;background:url(../../../images/mundo.jpg) ">
<br /><span style="color:#00AF4B">Search Customs Agent &raquo;</span><br /><br />



 
    <table width="314" border="0">
    <form action="searchcustomsagent.php" method="post" name="form12" id="form12">

      <tr> 

        <td width="116">Search 

          by </td>

        <td width="253"><select name="txtbuscapor" id="txtbuscapor" class="aa">

            <option value="socialreason" <?=$_POST['txtbuscapor']=='socialreason' ? "selected='selected'" : ''?>>
            Company Name</option>

            <option value="nickname" <?= ($_POST['txtbuscapor']=='nickname' or $_POST['txtbuscapor']=='') ? "selected='selected'" : ''?>>Nick Name </option>

            <option value="invoicename" <?=$_POST['txtbuscapor']=='invoicename' ? "selected='selected'" : ''?>>Invoice Name</option>

            <option value="city" <?=$_POST['txtbuscapor']=='city' ? "selected='selected'" : ''?>>City</option>

            <option value="rfc" <?=$_POST['txtbuscapor']=='rfc' ? "selected='selected'" : ''?>>RFC</option>

            <option value="creditOceanfreights" <?=$_POST['txtbuscapor']=='creditOceanfreights' ? "selected='selected'" : ''?>>Credit Oceanfreights</option>

            <option value="creditlocalcharges" <?=$_POST['txtbuscapor']=='creditlocalcharges' ? "selected='selected'" : ''?>>Credit Local Charges</option>

          </select></td>

      </tr>

      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr> 

        <td>Search:</td>

        <td><input name="txtbusca" type="text" id="txtbusca" value="<?=$_POST[txtbusca]?>"></td>

      </tr>

      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr> 

        <td colspan="2"><input type="submit" name="Submit" value="Search">
          
        </td>

      </tr>
      
</form>

	  <tr>
        <td colspan="2">
        <form action="customsagentexpint.php">
        <input type="submit" name="Submit2" value="Back" >
        </form>
        </td>
      </tr>
    </table>

    

  

</form>

<p> 

  <?

$txtbusca=$_POST['txtbusca'];

$txtbuscapor=$_POST['txtbuscapor'];
$txtbuscapor=($txtbuscapor=='' ? 'nickname' : $txtbuscapor);


//echo "SELECT * FROM customagentexpint where $txtbuscapor like '$txtbusca%' order by nickname limit 50" ;
//echo mysql_error();

$cond='';
$cond.= ($_GET[txtsocialreason]!='' ? ($cond!='' ? ' or ' : '') .' socialreason like "%'.$_GET[txtsocialreason].'%" ' : '');
$cond.= ($_GET[txtnickname]!='' ? ($cond!='' ? ' or ' : '') .' nickname like "%'.$_GET[txtnickname].'%" ' : '');

if($cond!=''){
	$resulta= mysql_query("SELECT * FROM customagentexpint where ".$cond." order by nickname limit 50"); 
}else{
	$resulta = mysql_query("SELECT * FROM customagentexpint where $txtbuscapor like '%$txtbusca%' order by nickname limit 50"  ); 
}

//echo "SELECT * FROM customagentexpint where ".$cond." order by nickname limit 50";


if ($row = mysql_fetch_array($resulta)){ 

?>
<br>
<table align="left" width="70%"  class="tablas_con_bordes_" style="font-family:Arial, Helvetica, sans-serif; font-size:11px" >
<?

//echo "<table border = '1' align=\"center\"  bordercolorlight=\"#0000FF\" bgcolor=\"#CCFFFF\" > \n"; 

$i=0;

printf("<TR class='yellow'><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Option</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Company Name</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Nick Name</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">RFC</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Address</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">ZIP (CP)</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">City</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Tel</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Fax</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Email</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Web Site</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Delete</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Change</TD><TD><strong><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">Contacts</TD></TR>");



do {

	$i=$i+1; 

echo "<tr \n";

echo "          <LABEL \n";

echo "        <TD \n";

//impresion

//ponPrefijo(pref)

//echo "      <td><input name=\"che\" type=\"button\" id=\"che\" onClick=\"ponref(document.form1.txtmarcasynumeros1.value )\" value=\"Agregar\" > " ;

echo "  <input name=\"Button2\" type=\"Button\" onClick=\"ponPrefijo('$txtsocialreason')\" value=\"Aceptar\">";

printf("<TR class='comun'><td> <input name=\"Buttonf$i\" type=\"Button\" onClick=\"ponPrefijo('" . utf8_encode($row["socialreason"]) . "','" . utf8_encode($rowc["name"]) . "','" . $rowc["tel"] . "','" . $rowc["fax"] . "','" . $rowc["email"] . "')\" value=\"Tariff EXPO\"></td><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><a href=\"javascript:preguntar('borracustomagentexpint.php?id=%s','')\">Delete</a></TD><TD><a href=\"cambiocustomagentexpint.php?id=%s\">Change</a></TD><TD><a href=\"customsagentcontactdetails.php?id=%s\">Administrate</a></TD></TR>",utf8_encode($row["socialreason"]),utf8_encode($row["nickname"]),$row["rfc"],$row["direction"],$row["cp"],$row["city"],$row["tel1"],$row["fax"],"<a href=\"mailto:" . $row["email"] . "\">" . $row["email"] . "</a>",$row["observations"],$row["id"],$row["id"],$row["id"]);



echo "        <TD \n";



$txtidc=$row["id"];

$resultc = mysql_query("SELECT * FROM contact  where id = '$txtidc' and section ='CUSTOM' order by name, function"); 

while ($rowc = mysql_fetch_array($resultc)){ 
$dat = data("select usuario from usuarioslpv where id = '".$rowc["idcto"]."'");
$login = $dat[0];
echo "        <TR>";

printf("<TR class='comun'>
	   <td> 
	   <input name=\"Buttonf$i\" type=\"Button\" onClick=\"ponPrefijo('" . $row["socialreason"] . "','" . $rowc["name"] . "','" . $rowc["tel"] . "','" . $rowc["fax"] . "','" . $rowc["email"] . "','".$rowc["idcto"]."','".$login."')\" value=\"Select\">
	   </td>
	   <td></td>
	   <TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD>
	   <TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD><TD><font size=\"1\" face=\"Arial, Helvetica, sans-serif\">%s</TD></TR>",$rowc["name"],$rowc["function"],$rowc["tel"],$rowc["fax"],$rowc["movil"],$rowc["nextel"],$rowc["email"]);





}



//echo "  ;

//echo "<td><input name=\"ches$i\" type=\"button\" id=\"ches$i\" onClick=\"ponref()\" value=\"Subir\"></TD>";

echo "      </TR>";



   } while ($row = mysql_fetch_array($resulta)); 



   echo  "</table>" ;





}

else

{

if ($txtbusca!="")

{

echo "</p>";

echo "<p align=\"center\"><strong><font color=\"#FF0000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Not Found $txtbusca</p>";

echo "</p>";

}

}

?>


</div>