// this script paints every other data row of every table on the page whose style class is
// "report" using the style classes "shade0" and "shade1";
// it does not paint rows whose cells' style is "reportHeader".
// NOTE: the <script> tag that includes this code must appear after every <table> has been
// sent to the HTML output stream.

// all <table> elements
var tables = document.getElementsByTagName("table");
for (var ix = 0; ix < tables.length; ix++) {
  paintRows(tables[ix]);
}

// If the argument table's style class is "report", paints every other data row of the table
// using the style classes "shade0" and "shade1"
function paintRows(table) {
  // skip tables that are not "report"
  if (table.className == "report") {
    var trs = table.getElementsByTagName("tr");
    var startRow;
    for (var startRow = 0; startRow < trs.length; startRow++) {
      if (isPaintable(trs[startRow])) {
        break;
      }
    }
    // startRow is now the index of the first paintable row
    var light = true;
    for (var row = startRow; row < trs.length; row++) {
      // skip hidden rows on the congestion report
      if (trs[row].style.display != "none") {
        trs[row].className = "shade" + (light ? "0" : "1");
        light = !light;
      }
    }
  }
}

// return false if the row is a header row
function isPaintable(tr) {
  var className = tr.cells[0].className;
  if (className == null) {
    return true;
  }
  return className != "reportHeader";
}


// return the number of rows to paint
function rowsToPaint(trs) {
  var paintableRows = trs.length;
  for (var row = 0; row < trs.length; row++) {
    if (!isPaintable(trs[row])) {
      paintableRows--;
    }
  }
  return paintableRows;
}
