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

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

// set meta tags
$meta_keywords = "search triathlons";
$meta_description = "Do you want to search for triathlons in our online multisport calendar? 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 class="content-title"><strong>Search For A Race</strong></h1>

                <p class="cont">If you would like to search for a race, please use the form below. None of the fields are mandatory. Checking no box "selects all." Checking regions selects all states in that region. Checking any state's box selects or deselects that state.<br /><br />Our keyword search is new and very crude. It is not meant to be Google. It's not very forgiving of misspellings, etc. Please feel free to contact us with any feedback.</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" />
                             <p><em>This will become the primary ordering of results, THEN date. This will search all races within the past 365 days and all future races. To search back beyond that, you need to manually override the date range below.</em></p>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Date Override</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
                            <input type="checkbox" name="futuredates" value="1"> Yes
                            <p><em>overrides keyword search default and allows you to use the date boxes below. Also resets default search to start with today's date.</em></p>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Start Date</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<select name="aftermonth">
<option value="0">Month
<option value="01">January
<option value="02">February
<option value="03">March
<option value="04">April
<option value="05">May
<option value="06">June
<option value="07">July
<option value="08">August
<option value="09">September
<option value="10">October
<option value="11">November
<option value="12">December
</select>
<select name="afterday">
<option value="0">Day
<? for ($i = 1; $i <= 31; $i++) { echo ("<option value='".sprintf('%02d', $i)."'>$i"); } ?>
</select>
<select name="afteryear">
	<option value="0">Year
	<? $year = date( "Y", strtotime("+6 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-6 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-18 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-30 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-42 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
</select> <em>Leave blank for today's date</em>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">End Date</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<select name="beforemonth">
<option value="0">Month
<option value="01">January
<option value="02">February
<option value="03">March
<option value="04">April
<option value="05">May
<option value="06">June
<option value="07">July
<option value="08">August
<option value="09">September
<option value="10">October
<option value="11">November
<option value="12">December
</select>
<select name="beforeday">
<option value="0">Day
<? for ($i = 1; $i <= 31; $i++) { echo ("<option value='".sprintf('%02d', $i)."'>$i"); } ?>
</select>
<select name="beforeyear">
	<option value="0">Year
	<? $year = date( "Y", strtotime("+6 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-6 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-18 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-30 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
	<? $year = date( "Y", strtotime("-42 months") ); ?>
        <option value="<? echo($year); ?>"><? echo($year); ?>
</select>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Race Type</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<input type="checkbox" name="type[]" value="1"> Triathlon
<input type="checkbox" name="type[]" value="2"> Duathlon
<input type="checkbox" name="type[]" value="3"> Other 
<em>Leave blank to select all.</em>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Race distance</div>
                          <div class="dcell divider"></div>
<input type="checkbox" name="points[]" value="1"> Sprint
<input type="checkbox" name="points[]" value="2"> International
<input type="checkbox" name="points[]" value="3"> Half
<input type="checkbox" name="points[]" value="4"> Ultra
<em>Leave blank to select all.</em>
                          <div class="dcell value">
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Bike Surface Type</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<input type="checkbox" name="bike_surface[]" value="0"> Road
<input type="checkbox" name="bike_surface[]" value="1"> Offroad 
<input type="checkbox" name="bike_surface[]" value="2"> Gravel 
<em>Leave blank to select all.</em>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Drafting Rules</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<input type="checkbox" name="draft_legal[]" value="0"> Non-drafting
<input type="checkbox" name="draft_legal[]" value="1"> Draft legal 
<em>Leave blank to select all.</em>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">Kids' Races</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<input type="checkbox" name="kids_race[]" value="0"> "Normal" (18yo+) Races ONLY
<input type="checkbox" name="kids_race[]" value="1"> Kids' Races ONLY 
<em>Leave blank to select all.</em>
                          </div>
                       </div>
                       <div class="drow">
                          <div class="dcell name">aces with registration fees included in price</div>
                          <div class="dcell divider"></div>
                          <div class="dcell value">
<input type="checkbox" name="registration[]" value="0"> Races where it is not specified if fees are included in price
<input type="checkbox" name="registration[]" value="1"> Races where it is explicitly stated that the price <strong>includes</strong> all registration fee(s) 
<em>Leave blank to select all.</em>
                          </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="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>
