/* 	Super Tables 1.0	Copyright 2005 Tim Hettler	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>*/var ST = {	requiredAttrParams: ["evenClass", "oddClass", "overClass"],	optionalAttrParams: ["type","replaceClass","tableid"],	create: function(vars) {		var loadfn = function() {			if (ST.hasRequiredAttrParams(vars)) {				ST.stripe(vars);			}		};		ST.addLoadEvent(loadfn);	},		hasRequiredAttrParams: function(vars) {		for (var i = 0; i < ST.requiredAttrParams.length; i++) {			if (typeof vars[ST.requiredAttrParams[i]] == "undefined") return false;		}		return true;	},		stripe: function(vars) {		// the flag we'll use to keep track of 		// whether the current row is odd or even		var even = true;				//if a specific table has been selected, we'll get a reference for that. Otherwise, we'll obtain a reference to all table elements in page.		var tables = new Array();		if(vars.tableid != '') {			tables[0] = document.getElementById(vars.tableid);		} else {			tables = document.getElementsByTagName("table");		}		for (var g = 0; g < tables.length; g++) {			//reset even to false value so color alternate at same interval on each table			even = false;			// by definition, tables can have more than one tbody			// element, so we'll have to get the list of child			// <tbody>s 			var tbodies = tables[g].getElementsByTagName("tbody");			// and iterate through them...			for (var h = 0; h < tbodies.length; h++) {				// find all the <tr> elements... 				var trs = tbodies[h].getElementsByTagName("tr");				// ... and iterate through them				for (var i = 0; i < trs.length; i++) {					if(vars.type == 'click') {						ST.highlightRowOnClick(trs[i], vars.overClass, tables[g]);					} else if(vars.type == 'mouseover') {						ST.highlightRowOnMouseOver(trs[i], vars.overClass);					}					// get all the cells in this row...					var tds = trs[i].getElementsByTagName("td");					// and iterate through them...					for (var k = 0; k < tds.length; k++) {						var mytd = tds[k];						if (vars.replaceClass == 'y' || !ST.hasClass(mytd)) {							if(even) {								mytd.className +=" "+vars.evenClass;							} else {								mytd.className +=" "+vars.oddClass;							}						}					}					 // flip from odd to even, or vice-versa					even =  ! even;				 }			}		}	 },	 	 // this function is needed to work around 	// a bug in IE related to element attributes	hasClass: function(obj) {		var result = false;		if (obj.getAttributeNode("class") != null) {			result = obj.getAttributeNode("class").value;		}		return result;	},		highlightRowOnMouseOver: function() {		var element = arguments[0];		var overClass = arguments[1];				element.onmouseover=function() {			for (var j=0; j<element.childNodes.length; j++) {				var node = element.childNodes[j];				if (node.nodeName == "TD") {					node.className += " "+overClass;				}			}		}		element.onmouseout=function() {			for (var j=0; j<element.childNodes.length; j++) {				var node = element.childNodes[j];				if (node.nodeName == "TD") {					node.className = node.className.replace(" "+overClass, "");				}			}		}		return true;	},		highlightRowOnClick: function() {		var element = arguments[0];		var overClass = arguments[1];		var parentTable = arguments[2];				element.onclick=function() {			//first, de-highlight all rows in table			var tbodies = parentTable.getElementsByTagName("tbody");			for (var h = 0; h < tbodies.length; h++) {				var trs = tbodies[h].getElementsByTagName("tr");				for (var i = 0; i < trs.length; i++) {					var tds = trs[i].getElementsByTagName("td");					for (var k = 0; k < tds.length; k++) {						tds[k].className = tds[k].className.replace(" "+overClass, "");					}					}			}						//now highlight the selected one			for (var j=0; j<element.childNodes.length; j++) {				var node = element.childNodes[j];				if (node.nodeName == "TD") {					node.className += " "+overClass;				}			}		}	},		addLoadEvent: function(fn) {		if (window.addEventListener) {			window.addEventListener("load", fn, false);		}		else if (document.addEventListener) {			document.addEventListener("load", fn, false);		}		else if (window.attachEvent) {			window.attachEvent("onload", fn);		}		else if (typeof window.onload == "function") {			var fnOld = window.onload;			window.onload = function(){				fnOld();				fn();			};		}		else {			window.onload = fn;		}	}}