Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.292.2.8
diff -u -p -r1.292.2.8 theme.inc
--- includes/theme.inc	29 Jan 2007 21:39:27 -0000	1.292.2.8
+++ includes/theme.inc	6 Oct 2007 04:20:39 -0000
@@ -705,18 +705,27 @@ function theme_table($header, $rows, $at
 
   // Format the table header:
   if (count($header)) {
+
     $ts = tablesort_init($header);
-    $output .= ' <thead><tr>';
+    // HTML requires that the thead tag has tr tags in it follwed by tbody
+    // tags. Using ternary operator to check and see if we have any rows.
+    $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
     foreach ($header as $cell) {
       $cell = tablesort_header($cell, $header, $ts);
-      $output .= _theme_table_cell($cell, 1);
+      $output .= _theme_table_cell($cell, TRUE);
     }
-    $output .= " </tr></thead>\n";
+    // Using ternary operator to close the tags based on whether or not there are rows
+    $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
+  }
+  else {
+    $ts = array();
   }
 
   // Format the table rows:
-  $output .= "<tbody>\n";
   if (count($rows)) {
+    $output .= "<tbody>\n";
+    $flip = array('even' => 'odd', 'odd' => 'even');
+    $class = 'even';
     foreach ($rows as $number => $row) {
       $attributes = array();
 
@@ -734,28 +743,30 @@ function theme_table($header, $rows, $at
       else {
         $cells = $row;
       }
+      if (count($cells)) {
+        // Add odd/even class
+        $class = $flip[$class];
+        if (isset($attributes['class'])) {
+          $attributes['class'] .= ' '. $class;
+        }
+        else {
+          $attributes['class'] = $class;
+        }
 
-      // Add odd/even class
-      $class = ($number % 2 == 1) ? 'even': 'odd';
-      if (isset($attributes['class'])) {
-        $attributes['class'] .= ' '. $class;
-      }
-      else {
-        $attributes['class'] = $class;
-      }
-
-      // Build row
-      $output .= ' <tr'. drupal_attributes($attributes) .'>';
-      $i = 0;
-      foreach ($cells as $cell) {
-        $cell = tablesort_cell($cell, $header, $ts, $i++);
-        $output .= _theme_table_cell($cell, 0);
+        // Build row
+        $output .= ' <tr'. drupal_attributes($attributes) .'>';
+        $i = 0;
+        foreach ($cells as $cell) {
+          $cell = tablesort_cell($cell, $header, $ts, $i++);
+          $output .= _theme_table_cell($cell);
+        }
+        $output .= " </tr>\n";
       }
-      $output .= " </tr>\n";
     }
+    $output .= "</tbody>\n";
   }
 
-  $output .= "</tbody></table>\n";
+  $output .= "</table>\n";
   return $output;
 }
 
