var makeTablesActive; // a flag to indicate whether the tables should be made "active"

function enrichTable(table) {
  var rows = xGetElementsByTagName("TR",table);
  var rcnt = 0; // odd-even row count
  for (var rc = 0; rc < rows.length; rc++) {
    var row = rows[rc];
    if (xGetElementsByTagName("TH",row).length > 0) {
      rcnt = 0; // reset the odd-even count at header rows
    } else {
      rcnt++;
      xAddClass(row,rcnt % 2 == 0 ? "EvenRow":"OddRow");
      if (makeTablesActive) { 
        row.onmouseover = function() { xAddClass(this,"ActiveRow"); }
        row.onmouseout  = function() { xRemoveClass(this,"ActiveRow"); }
      }
    }
    if (row.cells.length) {
      xAddClass(row.cells[0],"FirstColumn");
      xAddClass(row.cells[row.cells.length - 1],"LastColumn");
    }
  }
}

function enrichPrintoutTables() {
  xGetElementsByClassName("printout",document,"TABLE",enrichTable);
}

function queryEnrichPrintoutTables() {
  if (! confirm("Do you want to enrich the HTML tables in this document")) return;
  makeTablesActive = confirm("Do you want to make the tables active");
  enrichPrintoutTables();
}

xAddEventListener(window,"load",queryEnrichPrintoutTables);
