
// Main function, called when the page loads
function alternateRows() {
	var i, j;
	
	if (!document.getElementById) return
	
		var tables = document.getElementsByTagName("table");	  
		//search through tables in document
		for (i=0; i<tables.length; i++) {
			// If table has the right classname
			if (tables[i].className == "alternateRows") {
				rows = tables[i].getElementsByTagName("tr");
				applyClasstoRows(rows);
			}
		}
}

// Function, which is passed a table reference, applies the class 'even' to each even row, <tr> tag
function applyClasstoRows(myRows) {
	// search through rows
	for (j=0; j<rows.length; j++) {
	
	   // Set class for even rows (odd doesn't need to be set)
	   if (j%2 == 0) { 
		  rows[j].setAttribute("className", "even");
		  rows[j].setAttribute("class", "even");
	   } 
	}
}

// Piggy-back fucntion onto onLoad event ............................................
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(alternateRows);
