<?php
  $menuSystem = array(
    'Sort' => array(
       'TeamSchedule' => 'Team Schedule',
       'Recent' => 'Recent', 
       'TopRated' => 'Top Rated'),
    'Season' => array(
       'All' => 'All', 
       '2017' => '2017',
       '2016' => '2016',
       '2015' => '2015',
       '2014' => '2014', 
       '2013' => '2013', 
       '2012' => '2012', 
       '2011' => '2011', 
       '2010' => '2010',
       '2009' => '2009'),
    'Team' => array(
       'All' => 'All', 
       'AFC' => array(
         'AFCEast' => array(
           'BUF' => 'BUF',
           'MIA' => 'MIA',
           'NE' => 'NE',
           'NYJ' => 'NYJ'),
         'AFCNorth' => array(
           'BAL' => 'BAL',
           'CIN' => 'CIN',
           'CLE' => 'CLE',
           'PIT' => 'PIT'),
         'AFCSouth' => array(
           'HOU' => 'HOU',
           'JAC' => 'JAC',
           'IND' => 'IND',
           'TEN' => 'TEN'),
         'AFCWest' => array(
           'DEN' => 'DEN',
           'KC' => 'KC',
           'OAK' => 'OAK',
           'SD' => 'SD')),
       'NFC' => array(
         'NFCEast' => array(
           'DAL' => 'DAL',
           'NYG' => 'NYG',
           'PHI' => 'PHI',
           'WAS' => 'WAS'),
         'NFCNorth' => array(
           'CHI' => 'CHI',
           'DET' => 'DET',
           'GB' => 'GB',
           'MIN' => 'MIN'),
         'NFCSouth' => array(
           'ATL' => 'ATL',
           'CAR' => 'CAR',
           'NO' => 'NO',
           'TB' => 'TB'),
         'NFCWest' => array(
           'ARI' => 'ARI',
           'LA' => 'LA',
           'SEA' => 'SEA',
           'SF' => 'SF'))),
     'MinRating' => array(
       '00' => '<img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '05' => '<img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '10' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '15' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '20' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '25' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '30' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '35' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '40' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '45' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">',
       '50' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">'),
     'PassFail' => array(
       'Off' => 'Off',
       '10' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '15' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '20' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '25' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '30' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '35' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/Large50.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">',
       '40' => '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">')
    );


  function GenerateURL($param, $newvalue)
  {
    $ret = 'football.php';
    $sep = '?';
    
    $newGet = $_GET;
    $newGet[$param] = $newvalue;
    
    if($param != 'IDX' && $param != 'PassFail')
      $newGet['IDX'] = '0';
    
    if($param == 'Sort' && $newvalue == 'TeamSchedule' &&
      ($newGet['Team'] == 'All' ||
       $newGet['Team'] == 'AFC' ||
       $newGet['Team'] == 'NFC' ||
       $newGet['Team'] == 'AFCEast' ||
       $newGet['Team'] == 'AFCNorth' ||
       $newGet['Team'] == 'AFCSouth' ||
       $newGet['Team'] == 'AFCWest' ||
       $newGet['Team'] == 'NFCEast' ||
       $newGet['Team'] == 'NFCNorth' ||
       $newGet['Team'] == 'NFCSouth' ||
       $newGet['Team'] == 'NFCWest'))
    {
      if(array_key_exists('LastFootballTeam',$_COOKIE))
        $newGet['Team'] = $_COOKIE['LastFootballTeam'];
      else
        $newGet['Team'] = 'ARI';
    }
    
    if($param == 'Sort' && $newvalue == 'TeamSchedule' && $newGet['Season'] == 'All')
    {
      $newGet['Season'] == '2017';  //This needs to be updated for each new season!
    }
    
    if($param == 'Team' && $newGet['Sort'] == 'TeamSchedule' &&
      ($newvalue == 'All' ||
       $newvalue == 'AFC' ||
       $newvalue == 'NFC' ||
       $newvalue == 'AFCEast' ||
       $newvalue == 'AFCNorth' ||
       $newvalue == 'AFCSouth' ||
       $newvalue == 'AFCWest' ||
       $newvalue == 'NFCEast' ||
       $newvalue == 'NFCNorth' ||
       $newvalue == 'NFCSouth' ||
       $newvalue == 'NFCWest'))
    {
      $newGet['Sort'] = 'Recent';
    }
    
    if($param == 'Season' && $newvalue == 'All' && $newGet['Sort'] == 'TeamSchedule')
    {
      $newGet['Sort'] = 'Recent';
    }

    global $isMobile;
    if($isMobile &&
      ($newGet['Team'] == 'AFC' ||
       $newGet['Team'] == 'NFC' ||
       $newGet['Team'] == 'AFCEast' ||
       $newGet['Team'] == 'AFCNorth' ||
       $newGet['Team'] == 'AFCSouth' ||
       $newGet['Team'] == 'AFCWest' ||
       $newGet['Team'] == 'NFCEast' ||
       $newGet['Team'] == 'NFCNorth' ||
       $newGet['Team'] == 'NFCSouth' ||
       $newGet['Team'] == 'NFCWest'))
    {
      return '#';
    }
    
    foreach($newGet as $key => $value)
    {
      $ret = $ret . $sep . $key . '=' . $value;
      $sep = "&";
    }
    
    return $ret;
  }

  function CleanGetVars()
  {
    global $menuSystem;

    if(!array_key_exists('PassFail', $_GET) && array_key_exists('LastFootballPassFail', $_COOKIE))
      $_GET['PassFail'] = $_COOKIE['LastFootballPassFail'];

    //Remove any GET keys we don't understand
    foreach($_GET as $key => $value)
    {
      if(!array_key_exists($key, $menuSystem) && $key != 'IDX')
      {
        unset($_GET[$key]);
      }
    }
    
    foreach($menuSystem as $key => $value)
    {
      if(array_key_exists($key, $_GET))
      {
        //We know we have a valid key name, but need to verify that we have a valid value
      }
      else
      {
        list($k, $v) = each($value);
        $_GET[$key] = $k;
      }
    }
    
    if($_GET['Sort'] == 'TeamSchedule' &&
      ($_GET['Team'] == 'All' OR
       $_GET['Team'] == 'AFC' OR
       $_GET['Team'] == 'NFC' OR
       $_GET['Team'] == 'AFCEast' OR
       $_GET['Team'] == 'AFCNorth' OR
       $_GET['Team'] == 'AFCSouth' OR
       $_GET['Team'] == 'AFCWest' OR
       $_GET['Team'] == 'NFCEast' OR
       $_GET['Team'] == 'NFCNorth' OR
       $_GET['Team'] == 'NFCSouth' OR
       $_GET['Team'] == 'NFCWest'))
    {
      $_GET['Sort'] = 'Recent';
    }
    
    if($_GET['Sort'] == 'TeamSchedule' && $_GET['Season'] == 'All')
      $_GET['Season'] = '2017';
      
    if(!array_key_exists('IDX', $_GET))
    {
      $_GET['IDX'] = '0';
    }
  }

  function Printable($name)
  {
    switch($name)
    {
      case 'Sort':
        return 'Sort: ' . Printable($_GET['Sort']);
      case 'Season':
        return 'Season: ' . Printable($_GET['Season']);
      case 'Team':
        return 'Team: ' . AltPrintable($_GET['Team']);
      case 'MinRating':
        return 'Min Rating: ' . Printable($_GET['MinRating']);
      case 'PassFail':
        return 'Pass/Fail: ' . Printable($_GET['PassFail']);
        
      case 'TeamSchedule':
        return 'Team Schedule';
      case 'TopRated':
        return 'Top Rated';
 
      case 'AFCEast':
        return 'East';
      case 'AFCNorth':
        return 'North';
      case 'AFCSouth':
        return 'South';
      case 'AFCWest':
        return 'West';
      case 'NFCEast':
        return 'East';
      case 'NFCNorth':
        return 'North';
      case 'NFCSouth':
        return 'South';
      case 'NFCWest':
        return 'West';
 
 
      case '00':
         return   '<img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '05':
         return   '<img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '10':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '15':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '20':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '25':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '30':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '35':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '40':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeEmpty.png" style="width: 12px; height: 12px;">';
      case '45':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/Large50.png" style="width: 12px; height: 12px;">';
      case '50':
         return   '<img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">
                   <img src="images/LargeFull.png" style="width: 12px; height: 12px;">';
    }

    return $name;
  }
  
  function AltPrintable($name)
  {
    switch($name)
    {
      case 'AFCEast':
        return 'AFC East';
      case 'AFCNorth':
        return 'AFC North';
      case 'AFCSouth':
        return 'AFC South';
      case 'AFCWest':
        return 'AFC West';
      case 'NFCEast':
        return 'NFC East';
      case 'NFCNorth':
        return 'NFC North';
      case 'NFCSouth':
        return 'NFC South';
      case 'NFCWest':
        return 'NFC West';
    }
    return Printable($name);
  }






  CleanGetVars();
  if(!$isMobile)
  {
    print "<div class=submenu>\n";
    print "  <ul>\n";
  
    foreach($menuSystem as $key1 => $value1)
    {
      if($key1 == 'PassFail')
        //print "    <li style=\"margin-left: 130px;\">\n";
        print "    <li style=\"position: absolute; left: 640px; width: 150px;\">\n";
      else
        print "    <li>\n";
      print "      <a href=\"#\">" . Printable($key1) . "</a>\n";
      print "      <ul>\n";
      foreach($value1 as $key2 => $value2)
      {
        print "        <li>\n";
        if( $key2 == '00' ||
            $key2 == '05' ||
            $key2 == '10' ||
            $key2 == '15' ||
            $key2 == '20' ||
            $key2 == '25' ||
            $key2 == '30' ||
            $key2 == '35' ||
            $key2 == '40' ||
            $key2 == '45' ||
            $key2 == '50')
          print "          <a href=\"" . GenerateURL($key1, $key2) . "\" class=\"stars\">" . Printable($key2) . "</a>\n";
        else
          print "          <a href=\"" . GenerateURL($key1, $key2) . "\">" . Printable($key2) . "</a>\n";

        if(is_array($value2))
        {
          print "<ul>\n";
          foreach($value2 as $key3 => $value3)
          {
            print "<li>\n";
            print "<a href=\"" . GenerateURL($key1, $key3) . "\">" . Printable($key3) . "</a>\n";

            if(is_array($value3))
            {
              print "<ul>\n";
              foreach($value3 as $key4 => $value4)
              {
                print "<li>\n";
                print "<a href=\"" . GenerateURL($key1, $key4) . "\">" . Printable($key4) . "</a>\n";
                print "</li>\n";
              }
              print "</ul>\n";
            }

            print "</li>\n";
          }
          print "</ul>\n";
        }
        print "        </li>\n";
      }
      print "      </ul>\n";
      print "    </li>\n";
    }
  
    print "  </ul>\n";
    print "</div>";
  }
?>