Index: misc/tabledrag.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/tabledrag.js,v
retrieving revision 1.13.2.1
diff -u -r1.13.2.1 tabledrag.js
--- misc/tabledrag.js	8 Feb 2008 18:54:10 -0000	1.13.2.1
+++ misc/tabledrag.js	8 Mar 2008 01:15:24 -0000
@@ -111,25 +111,31 @@
       // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based.
       var columnIndex = $('td', field.parents('tr:first')).index(cell.get(0)) + 1;
       var headerIndex = $('td:not(:hidden)', field.parents('tr:first')).index(cell.get(0)) + 1;
-      $('tbody tr', this.table).each(function() {
-        // Find and hide the cell in the table body.
-        var cell = $('td:nth-child('+ columnIndex +')', this);
-        if (cell.size()) {
-          cell.css('display', 'none');
+      $('thead tr, tbody tr', this.table).each(function() {
+        var parentTag = $(this).parent().get(0).tagName.toLowerCase();
+        var index = (parentTag == 'thead') ? headerIndex : columnIndex;
+        if ($(this).children('[colspan]').size()) {
+          // We need to add up colspans to find the right cell.
+          var cellCount = 0;
+          for (var i = 1; cellCount < index; i++) {
+            var cell = $(this).children(':nth-child('+ i +')');
+            cellCount += parseInt(cell.attr('colspan') ? cell.attr('colspan') : 1);
+          }
         }
-        // We might be dealing with a row spanning the entire table.
-        // Reduce the colspan on the first cell to prevent the cell from
-        // overshooting the table.
         else {
-          cell = $('td:first', this);
-          cell.attr('colspan', cell.attr('colspan') - 1);
+          var cell = $(this).children(':nth-child('+ index +')');
         }
-      });
-      $('thead tr', this.table).each(function() {
-        // Remove table header cells entirely (Safari doesn't hide properly).
-        var th = $('th:nth-child('+ headerIndex +')', this);
-        if (th.size()) {
-          th.remove();
+        if (cell.size()) {
+          if (cell.attr('colspan') > 1) {
+            // If the cell we're supposed to remove has a colspan,
+            // we simply reduce it.
+            cell.attr('colspan', cell.attr('colspan') - 1);
+          }
+          else {
+            // We hide table body cells, but we remove table header cells
+            // entirely (Safari doesn't hide properly).
+            parentTag == 'thead' ? cell.remove() : cell.css('display', 'none');
+          }
         }
       });
     }
@@ -693,7 +699,7 @@
           var maxVal = values[values.length - 1];
           // Populate the values in the siblings.
           $(targetClass, siblings).each(function() {
-            // If there are more items than possible values, assign the maximum value to the row. 
+            // If there are more items than possible values, assign the maximum value to the row.
             if (values.length > 0) {
               this.value = values.shift();
             }
