<?PHP include("config.php");

// set the page title
$pagetitle = "Search The Database";

// set meta tags
$meta_keywords = "search retailers";
$meta_description = "Do you want to search for shops in our online multisport retailer database? Then use this form to enter your criteria.";

?>

<? include("include_common_head.php"); ?>
<?

//Array of states for use in the form

$state_list = mysql_query("SELECT * FROM gforum_TriathlonsStates");

?>


<body class="listings">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>

  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">
        <? include("include_breadcrumb.php"); ?>

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <? include("include_sidebar.php"); ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">

              <div class="clearfix">
                <h1><strong>Search For A Retailer</strong></h1>
                <p class="cont">If you would like to search for a retailer, please use the form below. None of the fields are mandatory. Checking no box in a field indicates you don't care if a shop has or does not have fitters on staff, a fit bike, or motion capture system, or any of the listed brands.  Checking regions selects all states in that region. Checking any state's box selects or deselects that state. All searches are "OR" based, so checking two boxes will find shops that, for example, use either an EXIT fit bike OR a Serotta size-cycle. The one exception is for certifications, where checking both boxes will find shops who have both Serotta & FIST certifications; you can use the "ANY" box to search for shops who have fitters with one or the other or both certifications.</p>

                <form enctype="multipart/form-data" action="search_X.php" method="post" name="searchform">
                    <p class="cont"><font color="red"><? echo $errmsg; ?></font></p>
                    <div class="dtable form">
                       <div class="drow">
                          <div class="dcell name">Name Search</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                             <input type="text" name="keyword" class="txt lngtext" />
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name"></div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <h3>Bike Fit</h3>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Fitters On Staff</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                              <table width="100%" cellpadding="2" cellspacing="2">
                                  <tr>
                                      <td width="25%"><input type="checkbox" name="fitters[]" value="fist"> F.I.S.T. Tri</td>
                                      <td width="25%"><input type="checkbox" name="fitters[]" value="fist_road"> F.I.S.T. Road</td>
                                      <td width="25%"><input type="checkbox" name="fitters[]" value="fist_advanced"> F.I.S.T. Advanced</td>
                                      <td width="25%"><input type="checkbox" name="fitters[]" value="serotta">BikeFit, BodyGeometry, Retul, Serotta, or Trek</td>
                                      <td width="25%"><input type="checkbox" name="fitters[]" value="any"> <strong>ANY</strong></td>
                                  </tr>
                              </table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Default Tri-Fit Methodology</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersMethods ORDER BY retailer_method_name ASC");

$i = 0;
echo("<tr>");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"methods[]\" value=\"$row[retailer_method_id]\" >$row[retailer_method_name]</td>\n");
    $i++;
}
echo("<td width=\"25%\"><input type=\"checkbox\" name=\"methods[]\" value=\"999\" ><strong>ANY</strong></td>\n");
$i++;
while($i<4) {
	echo("<td width=\"25%\">&nbsp;</td>");
	$i++;
}
if(!($i%4)) echo "</tr><tr>";

echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Fit-Bike Model(s) Used</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersFitbikes ORDER BY retailers_fitbike_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"fitbikes[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"fitbikes[]\" value=\"$row[retailers_fitbike_id]\" >$row[retailers_fitbike_name]</td>\n");
    $i++;
}
if(!($i%4)) echo "</tr><tr>";
echo("<td width=\"25%\"><input type=\"checkbox\" name=\"fitbikes[]\" value=\"999\" ><strong>ANY</strong></td>\n");
echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Motion-Capture Systems</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersMotioncapture ORDER BY retailers_motioncapture_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"motioncapture[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"motioncapture[]\" value=\"$row[retailers_motioncapture_id]\" >$row[retailers_motioncapture_name]</td>\n");
    $i++;
}
if(!($i%4)) echo "</tr><tr>";
echo("<td width=\"25%\"><input type=\"checkbox\" name=\"motioncapture[]\" value=\"999\" ><strong>ANY</strong></td>\n");
echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name"></div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <h3>Brands</h3>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">eCommerce Online Shopping Cart</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                             <input type="checkbox" name="ecommerce" value="1"> Yes
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Mail order via</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2">
<tr><td width="25%"><input type="checkbox" name="mailorder_ecommerce" value="1"> eCommerce</td>
<td width="25%"><input type="checkbox" name="mailorder_phone" value="1"> phone </td>
<td width="25%">&nbsp; </td>
<td width="25%">&nbsp; </td>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Local delivery</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2">
<tr><td width="25%"><input type="checkbox" name="local_ecommerce" value="1"> eCommerce</td>
<td width="25%"><input type="checkbox" name="local_phone" value="1"> phone </td>
<td width="25%">&nbsp; </td>
<td width="25%">&nbsp; </td>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Advanced order for in-store pickup</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2">
<tr><td width="25%"><input type="checkbox" name="pickup_ecommerce" value="1"> eCommerce</td>
<td width="25%"><input type="checkbox" name="pickup_phone" value="1"> phone </td>
<td width="25%">&nbsp; </td>
<td width="25%">&nbsp; </td>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Spoke Alliance Member</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                             <input type="checkbox" name="spoke" value="1"> Yes
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Wetsuits</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersWetsuits ORDER BY retailers_wetsuit_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"wetsuits[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"wetsuits[]\" value=\"$row[retailers_wetsuit_id]\" >$row[retailers_wetsuit_name]</td>\n");
    $i++;
}
//if(!($i%4)) echo "</tr><tr>";
//echo("<td width=\"25%\"><input type=\"checkbox\" name=\"wetsuits[]\" value=\"0\" >Any</td>\n");
echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Bikes</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersBikes ORDER BY retailers_bike_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"bikes[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"bikes[]\" value=\"$row[retailers_bike_id]\" >$row[retailers_bike_name]</td>\n");
    $i++;
}
//if(!($i%4)) echo "</tr><tr>";
//echo("<td width=\"25%\"><input type=\"checkbox\" name=\"bikes[]\" value=\"0\" >Any</td>\n");
echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Custom Frames</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_RetailersCustoms ORDER BY retailers_custom_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"customs[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"customs[]\" value=\"$row[retailers_custom_id]\" >$row[retailers_custom_name]</td>\n");
    $i++;
}
//if(!($i%4)) echo "</tr><tr>";
//echo("<td width=\"25%\"><input type=\"checkbox\" name=\"customs[]\" value=\"0\" >Any</td>\n");
echo("</tr>");

?>
</table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name"></div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <h3>Location</h3>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Region</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2">
<? 
$regions = array();
$regionsql = "SELECT gts.statetag AS statetag, gtr.regionlong AS regionlong
FROM gforum_TriathlonsStates AS gts
LEFT JOIN gforum_TriathlonsRegions AS gtr
ON gts.regionid = gtr.regionid
ORDER BY gtr.regionlong";

$region_list = mysql_query($regionsql);

//use loop for check box array
while($row = mysql_fetch_array($region_list)){
   if (!is_array($regions[$row[regionlong]])) { $regions[$row[regionlong]] = array(); }
   array_push($regions[$row[regionlong]], $row[statetag]);
}

$i = 0;
echo "<tr>";
foreach($regions AS $region => $statetag) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td><input type=\"checkbox\" name=\"region\" value=\"$region\" onClick=\"javascript: checkUncheck(this,'".implode("', '", $statetag)."');\">$region</td>\n");
    $i++;
  
}

?>
</tr>
</table>

<p><em>Selecting a region will select all states in that region. You can then deselect or select any additional states. Only the selected states will be included in your search. Leaving all boxes blank will select races in all states.</em></p>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">State</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2">
<? //use loop for check box array
$i = 0;
echo "<tr>";
while($row = mysql_fetch_array($state_list)){
   if(!($i%4)) echo "</tr><tr>";
   echo "<td><input type='checkbox' id='states' name='states[]' value=\"$row[statetag]\"> $row[statelong]</td>\n";
   $i++;
}
?>
</tr>
</table>
<p><em>Leave blank to select all.</em></p>
                          </div>
                       </div>
                       <div class="drow actions">
                          <div class="dcell name"></div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                              <input type="hidden" name="search_form" value="retailers">
                              <input type="submit" value="Search" class="btn">
                          </div>
                       </div>
                    </div>
                </form>

              </div><!-- end col-2/3 -->

            </div><!-- end grid -->
          </div><!-- end content -->
        </section>

      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>
