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

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

// set meta tags
$meta_keywords = "search running stores";
$meta_description = "Do you want to search for shops in our online running store 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."ResourceStates");
?>
<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>Search For A Running Store</h1>

                <p>If you would like to search for a running store, 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 a treadmill, 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.</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>Technology, Community &amp; Education</h3>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Diagnostic Equipment Used</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <table width="100%" cellpadding="2" cellspacing="2"><?
                            $results = mysql_query("SELECT * FROM ".$prefix."RunshopsDiagnostics ORDER BY diagnostic_name ASC");

                            $i = 0;
                            echo("<tr>");
                            //echo("<input type=\"hidden\" name=\"diagnostics[]\" value=\"0\" >");
                            while ($row = mysql_fetch_array($results)) {
                                if(!($i%4)) echo "</tr><tr>";
                                echo("<td width=\"25%\"><input type=\"checkbox\" name=\"diagnostics[]\" value=\"$row[diagnostic_id]\" >$row[diagnostic_name]</td>\n");
                                $i++;
                            }
                            //if(!($i%4)) echo "</tr><tr>";
                            //echo("<td width=\"25%\"><input type=\"checkbox\" name=\"diagnostics[]\" 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">Running Shoe Brands</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <table width="100%" cellpadding="2" cellspacing="2">
                            <?

                            $results = mysql_query("SELECT * FROM ".$prefix."RunshopsShoes ORDER BY shoe_name ASC");

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

                            ?>
                            </table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Sock Brands</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <table width="100%" cellpadding="2" cellspacing="2">
                            <?
                            $results = mysql_query("SELECT * FROM ".$prefix."RunshopsSocks ORDER BY sock_name ASC");

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

                            ?>
                            </table>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Run Apparel Brands</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <table width="100%" cellpadding="2" cellspacing="2">
                            <?
                            $results = mysql_query("SELECT * FROM ".$prefix."RunshopsApparelRun ORDER BY apparel_run_name ASC");

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

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

                            $results = mysql_query("SELECT * FROM ".$prefix."RunshopsApparelTri ORDER BY apparel_tri_name ASC");

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

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

                            $results = mysql_query("SELECT * FROM ".$prefix."ResourceSwimgear ORDER BY swimgear_name ASC");

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

                            ?>
                            </table>
                          </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 ".$prefix."ResourceWetsuits ORDER BY 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[wetsuit_id]\" >$row[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"></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."ResourceStates AS gts
                            LEFT JOIN ".$prefix."ResourceRegions 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="runshops">
                            <input type="submit" value="Search" class="btn default">
                          </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>
