/*
	Standards Compliant Script
	Alternates Table Columns
	Author : Kevin Cannon
	http://www.multiblah.com
	Last Edited: 12.12.2004
	Version 1.0
	
	Search through the document for tables with the "alternateRows" class,
	and set the class of even rows to "even" to appropriate rows <tr>
	
	Changes:
	4/10/2004 - Added in AddLoadEvent function which piggybacks code onto window.onLoad 
	
*/

// 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 == "seating alternateRows") {
				rows = tables[i].getElementsByTagName("tr");
				applyClasstoRows(rows);
			}
		}
*/

	if (!document.getElementById) return

		var tables = getElementsByClass("fakeTableCol seating alternateRows",document);
		//search through tables in document
		for (i=0; i<tables.length; i++) {
			// If table has the right classname
			rows = getElementsByClass("fakeTableData",tables[i]);
			applyClasstoFakeRows(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", "shaded");
		  rows[j].setAttribute("class", "shaded");
	   } 
	}
}

// Function, which is passed a table reference, applies the class 'even' to each even row, <tr> tag
function applyClasstoFakeRows(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", "fakeTableData shaded");
		  rows[j].setAttribute("class", "fakeTableData shaded");
	   } 
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

// 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);
