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

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

// set meta tags
$meta_keywords = "search fitters";
$meta_description = "Do you want to search for fitters in our online bike fitter 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 ".$prefix."FittersStates");

?>


<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 class="content-title"><strong>Search For A Fitter</strong></h1>

                <p class="cont">If you would like to search for a fitter, please use the form below. None of the fields are mandatory. Checking no box in a field indicates you don't care if a fitter has or does not have certifications, a fit bike, or motion capture system. 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 fitters 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 fitters who have ALL of the checked certifications; you can use the "ANY" box to search for fitters who have any certification.</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">Has Portfolio Link</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
							<input type="checkbox" name="portfolio" value="1">Portfolio Link in Profile
                          </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_FittersMethods ORDER BY fitter_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[fitter_method_id]\" >$row[fitter_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 Certifications:</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_FittersCertifications ORDER BY fitter_certification_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=\"certifications[]\" value=\"$row[fitter_certification_id]\" >$row[fitter_certification_name]</td>\n");
    $i++;
}
if(!($i%4)) echo "</tr><tr>";
echo("<td width=\"25%\"><input type=\"checkbox\" name=\"certifications[]\" value=\"999\" ><strong>ANY</strong></td>\n");
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_FittersFitbikes ORDER BY fitter_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[fitter_fitbike_id]\" >$row[fitter_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_FittersMotioncapture ORDER BY fitter_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[fitter_motioncapture_id]\" >$row[fitter_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">Brand Friendly</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<table width="100%" cellpadding="2" cellspacing="2"><?

$results = mysql_query("SELECT * FROM gforum_FittersBrandFriendly ORDER BY fitter_brand_name ASC");

$i = 0;
echo("<tr>");
//echo("<input type=\"hidden\" name=\"brandfriendly[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    if(!($i%4)) echo "</tr><tr>";
    echo("<td width=\"25%\"><input type=\"checkbox\" name=\"brandfriendly[]\" value=\"$row[fitter_brand_id]\" >$row[fitter_brand_name]</td>\n");
    $i++;
}
if(!($i%4)) echo "</tr><tr>";
echo("<td width=\"25%\"><input type=\"checkbox\" name=\"brandfriendly[]\" 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>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 ".$prefix."FittersStates AS gts
LEFT JOIN ".$prefix."FittersRegions 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="fitter">
                            <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>
