<?PHP

/**
$sprintcount = mysql_num_rows(mysql_query("SELECT date FROM gforum_Triathlons WHERE points < 40 AND valid = 1 AND date > '2008-01-01'"));
$intcount = mysql_num_rows(mysql_query("SELECT date FROM gforum_Triathlons WHERE points >= 40 AND points < 100 AND valid = 1 AND date > '2008-01-01'"));
$midcount = mysql_num_rows(mysql_query("SELECT date FROM gforum_Triathlons WHERE points >= 100 AND points < 180 AND valid = 1 AND date > '2008-01-01'"));
$ultracount = mysql_num_rows(mysql_query("SELECT date FROM gforum_Triathlons WHERE points > 180 AND valid = 1 AND date > '2008-01-01'"));**/

/**$sqlstatelist = "SELECT gts.statetag AS statetag, gts.statelong AS statelong, COUNT(gt.uid) AS numraces
FROM gforum_TriathlonsStates AS gts
LEFT JOIN gforum_Triathlons AS gt
ON gts.statetag = gt.statetag AND gt.date > '2008-01-01'
GROUP BY gts.statetag ORDER BY gts.statetag ASC";**/

$sqlregionlist = "SELECT gtr.regionlong AS regionlong, gtr.regionid AS regionid, gtr.regionname AS regionname, gts.statetag AS statetag, gts.statelong AS statelong, COUNT(gt.uid) AS numraces
FROM gforum_TriathlonsStates AS gts
LEFT JOIN gforum_Triathlons AS gt
ON gts.statetag = gt.statetag AND gt.date > '".$min_date."'
LEFT JOIN gforum_TriathlonsRegions AS gtr
ON gts.regionid = gtr.regionid
GROUP BY gtr.regionlong, gts.statetag ORDER BY gtr.regionlong ASC";

//$resultstatelist = mysql_query($sqlstatelist);

$resultregionlist = mysql_query($sqlregionlist);

?>

<div class="widget">
  <h2>Browse Races</h2>
  <div class="region-list">
<?

/**echo ("<br/><strong><a href='pointlist.php?points=sprint'>Sprint ($sprintcount)</a></strong>");
echo ("<br/><br/><strong><a href='pointlist.php?points=international'>International ($intcount)</a></strong>");
echo ("<br/><br/><strong><a href='pointlist.php?points=mid'>Mid-Distance ($midcount)</a></strong>");
echo ("<br/><br/><strong><a href='pointlist.php?points=ultra'>Ultra ($ultracount)</a></strong><br/>"); **/

$currentregion = '';
$regioncount = '';
$tempstring = '';
$currenttag = '';
$showhide = '';
$region_dropdown = '';
$state_string = '';
//while($rowstatelist = mysql_fetch_array($resultstatelist)){
while($rowregionlist = mysql_fetch_array($resultregionlist)){
  $selected_region = '';
  $selected_state  = '';
    if ($currentregion != $rowregionlist[regionlong]) {
        if ($selected_item == $currentrid) {
            $selected_region = ' selected="seleted"';
        }
        if ($currentregion != '') {
            $region_dropdown .= "<option value=\"$site_url/regionlist.php?region=$currentrid\"$selected_region>$currentregion ($regioncount)</option>$state_string";
            echo ("<div class='list-item'><a href='$site_url/regionlist.php?region=$currentrid'>" . $currentregion . " (" . $regioncount . ")</a><span>+</span><div class='sublist' id='". $currenttag . "'>");
            echo $tempstring;
            echo ('</div></div>');
        }
        $currentregion = $rowregionlist[regionlong];
        $currentrid = $rowregionlist[regionid];
        $currenttag = $rowregionlist[regionname];
        $regioncount = 0;
        $tempstring = '';
        $state_string = '';
    }
    if ($selected_item == $rowregionlist[statetag]) {
        $selected_state = ' selected="selected"';
    }
    $state_string .= "<option value=\"$site_url/statelist.php?state=$rowregionlist[statetag]\"$selected_state>&nbsp;&nbsp;&nbsp;$rowregionlist[statelong] ($rowregionlist[numraces])</option>";
    $tempstring = $tempstring. "<a href='$site_url/statelist.php?state=$rowregionlist[statetag]".get_sid()."' class='lhdr' title='$rowregionlist[statelong]'>$rowregionlist[statelong] ($rowregionlist[numraces])</a>\n";
    $regioncount += $rowregionlist[numraces];
}

echo ("<div class='list-item'><a href='$site_url/regionlist.php?region=$currentrid'>".$currentregion." (".$regioncount.")</a><span>+</span><div class='sublist' id='".$currenttag."'>");
echo $tempstring;
echo ('</div></div>');
if ( $selected_item == 'top') { $selected_region = ' selected="selected"'; }
$region_dropdown .= "<option value=\"" .  $site_url . '/top_races.php' . "\"$selected_region>Top Ranked</option>";
?>

<?
/** <p class="statenav"><a href="statelist.php?state=alabama<?PHP echo get_sid()?>" class="lhdr" title="Alabama">Alabama (<? echo(mysql_num_rows(mysql_query("SELECT uid FROM gforum_Triathlons WHERE statetag='alabama' AND valid=1 AND date > '2008-01-01'"))); ?>)</a></p>   
<p class="statenav"><a href="statelist.php?state=alaska<?PHP echo get_sid()?>" class="lhdr" title="Alaska">Alaska</a></p>       
<p class="statenav"><a href="statelist.php?state=alberta<?PHP echo get_sid()?>" class="lhdr" title="Alberta">Alberta</a></p>
<p class="statenav"><a href="statelist.php?state=arizona<?PHP echo get_sid()?>" class="lhdr" title="Arizona">Arizona (<? echo(mysql_num_rows(mysql_query("SELECT uid FROM gforum_Triathlons WHERE statetag='arizona' AND valid=1 AND date > '2008-01-01'"))); ?>)</a></p>
<p class="statenav"><a href="statelist.php?state=arkansas<?PHP echo get_sid()?>" class="lhdr" title="Arkansas">Arkansas</a></p>         
<p class="statenav"><a href="statelist.php?state=britishcolumbia<?PHP echo get_sid()?>" class="lhdr" title="British Columbia">British Columbia</a></p>
<p class="statenav"><a href="statelist.php?state=california<?PHP echo get_sid()?>" class="lhdr" title="California">California</a></p>   
<p class="statenav"><a href="statelist.php?state=colorado<?PHP echo get_sid()?>" class="lhdr" title="Colorado">Colorado</a></p> 
<p class="statenav"><a href="statelist.php?state=connecticut<?PHP echo get_sid()?>" class="lhdr" title="Connecticut">Connecticut</a></p>        
<p class="statenav"><a href="statelist.php?state=delaware<?PHP echo get_sid()?>" class="lhdr" title="Delaware">Delaware</a></p> 
<p class="statenav"><a href="statelist.php?state=florida<?PHP echo get_sid()?>" class="lhdr" title="Florida">Florida</a></p>    
<p class="statenav"><a href="statelist.php?state=georgia<?PHP echo get_sid()?>" class="lhdr" title="Georgia">Georgia</a></p>    
<p class="statenav"><a href="statelist.php?state=hawaii<?PHP echo get_sid()?>" class="lhdr" title="Hawaii">Hawaii</a></p>       
<p class="statenav"><a href="statelist.php?state=idaho<?PHP echo get_sid()?>" class="lhdr" title="Idaho">Idaho</a></p>  
<p class="statenav"><a href="statelist.php?state=illinois<?PHP echo get_sid()?>" class="lhdr" title="Illinois">Illinois</a></p> 
<p class="statenav"><a href="statelist.php?state=indiana<?PHP echo get_sid()?>" class="lhdr" title="Indiana">Indiana</a></p>    
<p class="statenav"><a href="statelist.php?state=iowa<?PHP echo get_sid()?>" class="lhdr" title="Iowa">Iowa</a></p>     
<p class="statenav"><a href="statelist.php?state=kansas<?PHP echo get_sid()?>" class="lhdr" title="Kansas">Kansas</a></p>       
<p class="statenav"><a href="statelist.php?state=kentucky<?PHP echo get_sid()?>" class="lhdr" title="Kentucky">Kentucky</a></p> 
<p class="statenav"><a href="statelist.php?state=louisiana<?PHP echo get_sid()?>" class="lhdr" title="Louisiana">Louisiana</a></p>      
<p class="statenav"><a href="statelist.php?state=maine<?PHP echo get_sid()?>" class="lhdr" title="Maine">Maine</a></p>  
<p class="statenav"><a href="statelist.php?state=manitoba<?PHP echo get_sid()?>" class="lhdr" title="Manitoba">Manitoba</a></p>
<p class="statenav"><a href="statelist.php?state=maryland<?PHP echo get_sid()?>" class="lhdr" title="Maryland">Maryland</a></p> 
<p class="statenav"><a href="statelist.php?state=massachussetts<?PHP echo get_sid()?>" class="lhdr" title="Massachusetts">Massachusetts</a></p>
<p class="statenav"><a href="statelist.php?state=mississippi<?PHP echo get_sid()?>" class="lhdr" title="Mississippi">Mississippi</a></p>        
<p class="statenav"><a href="statelist.php?state=missouri<?PHP echo get_sid()?>" class="lhdr" title="Missouri">Missouri</a></p> 
<p class="statenav"><a href="statelist.php?state=michigan<?PHP echo get_sid()?>" class="lhdr" title="Michigan">Michigan</a></p> 
<p class="statenav"><a href="statelist.php?state=minnesota<?PHP echo get_sid()?>" class="lhdr" title="Minnesota">Minnesota</a></p>      
<p class="statenav"><a href="statelist.php?state=montana<?PHP echo get_sid()?>" class="lhdr" title="Montana">Montana</a></p>    
<p class="statenav"><a href="statelist.php?state=nebraska<?PHP echo get_sid()?>" class="lhdr" title="Nebraska">Nebraska</a></p> 
<p class="statenav"><a href="statelist.php?state=nevada<?PHP echo get_sid()?>" class="lhdr" title="Nevada">Nevada</a></p>
<p class="statenav"><a href="statelist.php?state=newbrunswick<?PHP echo get_sid()?>" class="lhdr" title="New Brunswick">New Brunswick</a></p>
<p class="statenav"><a href="statelist.php?state=newfoundland<?PHP echo get_sid()?>" class="lhdr" title="Newfoundland">Newfoundland</a></p>     
<p class="statenav"><a href="statelist.php?state=newhampshire<?PHP echo get_sid()?>" class="lhdr" title="New Hampshire">New Hampshire</a></p>   
<p class="statenav"><a href="statelist.php?state=newjersey<?PHP echo get_sid()?>" class="lhdr" title="New Jersey">New Jersey</a></p>    
<p class="statenav"><a href="statelist.php?state=newmexico<?PHP echo get_sid()?>" class="lhdr" title="New Mexico">New Mexico</a></p>    
<p class="statenav"><a href="statelist.php?state=newyork<?PHP echo get_sid()?>" class="lhdr" title="New York">New York</a></p>  
<p class="statenav"><a href="statelist.php?state=northcarolina<?PHP echo get_sid()?>" class="lhdr" title="North Carolina">North Carolina</a></p>        
<p class="statenav"><a href="statelist.php?state=northdakota<?PHP echo get_sid()?>" class="lhdr" title="North Dakota">North Dakota</a></p>
<p class="statenav"><a href="statelist.php?state=novascotia<?PHP echo get_sid()?>" class="lhdr" title="Nova Scotia">Nova Scotia</a></p>
<p class="statenav"><a href="statelist.php?state=ohio<?PHP echo get_sid()?>" class="lhdr" title="Ohio">Ohio</a></p>     
<p class="statenav"><a href="statelist.php?state=oklahoma<?PHP echo get_sid()?>" class="lhdr" title="Oklahoma">Oklahoma</a></p>
<p class="statenav"><a href="statelist.php?state=ontario<?PHP echo get_sid()?>" class="lhdr" title="Ontario">Ontario</a></p>    
<p class="statenav"><a href="statelist.php?state=oregon<?PHP echo get_sid()?>" class="lhdr" title="Oregon">Oregon</a></p>       
<p class="statenav"><a href="statelist.php?state=pennsylvania<?PHP echo get_sid()?>" class="lhdr" title="Pennsylvania">Pennsylvania</a></p>
<p class="statenav"><a href="statelist.php?state=princeedwardisland<?PHP echo get_sid()?>" class="lhdr" title="Prince Edward Island">Prince Edward Island</a></p>
<p class="statenav"><a href="statelist.php?state=quebec<?PHP echo get_sid()?>" class="lhdr" title="Quebec">Quebec</a></p>
<p class="statenav"><a href="statelist.php?state=rhodeisland<?PHP echo get_sid()?>" class="lhdr" title="Rhode Island">Rhode Island</a></p>      
<p class="statenav"><a href="statelist.php?state=saskatchewan<?PHP echo get_sid()?>" class="lhdr" title="Saskatchewan">Saskatchewan</a></p>
<p class="statenav"><a href="statelist.php?state=southcarolina<?PHP echo get_sid()?>" class="lhdr" title="South Carolina">South Carolina</a></p>        
<p class="statenav"><a href="statelist.php?state=southdakota<?PHP echo get_sid()?>" class="lhdr" title="South Dakota">South Dakota</a></p>      
<p class="statenav"><a href="statelist.php?state=tennessee<?PHP echo get_sid()?>" class="lhdr" title="Tennessee">Tennessee</a></p>      
<p class="statenav"><a href="statelist.php?state=texas<?PHP echo get_sid()?>" class="lhdr" title="Texas">Texas</a></p>  
<p class="statenav"><a href="statelist.php?state=utah<?PHP echo get_sid()?>" class="lhdr" title="Utah">Utah</a></p>     
<p class="statenav"><a href="statelist.php?state=virginia<?PHP echo get_sid()?>" class="lhdr" title="Virginia">Virginia</a></p> 
<p class="statenav"><a href="statelist.php?state=vermont<?PHP echo get_sid()?>" class="lhdr" title="Vermont">Vermont</a></p>    
<p class="statenav"><a href="statelist.php?state=washington<?PHP echo get_sid()?>" class="lhdr" title="Washington">Washington</a></p>   
<p class="statenav"><a href="statelist.php?state=westvirginia<?PHP echo get_sid()?>" class="lhdr" title="West Virginia">West Virginia</a></p>   
<p class="statenav"><a href="statelist.php?state=wisconsin<?PHP echo get_sid()?>" class="lhdr" title="Wisconsin">Wisconsin</a></p>      
<p class="statenav"><a href="statelist.php?state=wyoming<?PHP echo get_sid()?>" class="lhdr" title="Wyoming">Wyoming</a></p>
**/
?>

    <div class="advsearch">
        <a href="<? echo $site_url . '/search.php' ?>">Search Races</a> <span class="sprite-magnify">&nbsp;</span>
    </div>
  </div>
</div>
