/*  TABLE HIGHLIGHTING FUNCTIONS (D.Kuehne 04.11.06)

HOW TO USE:
	 
The altRows function (styling even background rows) will
look for the table with an id of "t-table" and highlight
every-other row by adding the class "t-even" to the
alternating rows.

Simply add a class to your CSS like this:
   .t-even {background: #f7f7f7;) #f7f7f7 is a very light grey.

The mouseover highlighting of rows & columns is accomplished 
by the hi_cell & lo_cell functions. Depending on your 
needs, you can add CSS to highlight just the rows or 
both the rows and columns.

To highlight rows simply add a class to your CSS like this:
   tr.t-hi {background: #fcedca;) #fcedca is a very light orange.
   (Make sure to target just the tr like the example above.)

To higlight rows and columns change the declaration to this:
   tr.t-hi, td.t-hi {background: #fcedca;)

To target a particular table, add the table id before the class:
   #t-table tr.t-hi {background: #fcedca;)
   (all other table will not be affected)

ADDING THE SCRIPT(S) TO THE PAGE:

The table.js is dependent on the prototype.js library. The
table function are unobtrusive and therefore do not need 
event-handlers in the markup, but rather look for classes 
and id's. The Prototype library currently must be added with 
the exstention of .txt in order to work with the content 
handler. Add these files in this order:

<script type="text/javascript" src"../content/j/prototype.txt"></script>
<script type="text/javascript" src"../content/j/table.txt"></script>

============================================================ */

// Class function - used with altRows function
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

// Alternate color on the table rows - use the class "even" in the css
function altRows() {
  if (!document.getElementsByTagName || !document.getElementById) return false;
  var tables = document.getElementsByTagName("table");
  if (document.getElementsByClassName("t-table")) {
  for (var i=0; i<tables.length; i++) {
    var odd = true;
    var rows = tables[i].getElementsByTagName("tr");
    for (var j=0; j<rows.length; j++) {
      if (odd == true) {
        addClass(rows[j],"t-even");
        odd = false;
      } else {
        odd = true;
      }
      }
    }
  }
}

// DON'T USE THIS RIGHT NOW -- SLOWS IE AND THROWS ERRORS
/*
// climb up the tree to the supplied tag.
function ascendDOM(e, target) {
  while (e.nodeName.toLowerCase() != target && 
      e.nodeName.toLowerCase() != 'html')
    e = e.parentNode;
  
  return (e.nodeName.toLowerCase() == 'html') ? null : e;
}

// turn on highlighting
function hi_cell(e) {
  var el;
  if (window.event && window.event.srcElement)
    el = window.event.srcElement;
  if (e && e.target)
    el = e.target;
  if (!el) return;

  el = ascendDOM(el, 'td');
  if (el == null) return;

  var parent_row = ascendDOM(el, 'tr');
  if (parent_row == null) return;

  var parent_table = ascendDOM(parent_row, 'table');
  if (parent_table == null) return;

  // row styling
  parent_row.className += ' hi';

  // column styling
  var ci = -1;
  for (var i = 0; i < parent_row.cells.length; i++) {
    if (el === parent_row.cells[i]) {
      ci = i;
    }
  }
  if (ci == -1) return; // this should never happen

  for (var i = 0; i < parent_table.rows.length; i++) {
    var cell = parent_table.rows[i].cells[ci];
    cell.className += ' hi';
  }

}

// turn off highlighting
function lo_cell(e) {
  var el;
  if (window.event && window.event.srcElement)
    el = window.event.srcElement;
  if (e && e.target)
    el = e.target;
  if (!el) return;

  el = ascendDOM(el, 'td');
  if (el == null) return;
  
  var parent_row = ascendDOM(el, 'tr');
  if (el == null) return;

  var parent_table = ascendDOM(parent_row, 'table');
  if (el == null) return;

  // row de-styling
  parent_row.className = parent_row.className.replace(/\b ?hi\b/, '');

  // column de-styling
  var ci = -1;
  for (var i = 0; i < parent_row.cells.length; i++) {
    if (el === parent_row.cells[i]) {
      ci = i;
    }
  }
  if (ci == -1) return; // this should never happen

  for (var i = 0; i < parent_table.rows.length; i++) {
    var cell = parent_table.rows[i].cells[ci];
    cell.className = cell.className.replace(/\b ?hi\b/, '');
  }
}

// event listeners for the row highlighting on mouseover
function addListeners() {
  if (!document.getElementsByTagName) return;
  
  var all_cells = document.getElementsByTagName('td');
  for (var i = 0; i < all_cells.length; i++) {
    Event.observe(all_cells[i], 'mouseover', hi_cell, false);
    Event.observe(all_cells[i], 'mouseout', lo_cell, false);
  }
}*/

// load the functions on window load
Event.observe(window,'load',altRows,false);
// Event.observe(window,'load',addListeners,false);