/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Arc90, Inc. | http://arc90.com/ */
/* Globals */
var arc90_isIE = document.all? true: false;

function arc90_altrows() {
	var parts = ['TABLE', 'THEAD', 'TFOOT', 'TBODY'];

	for (var t = 0, r = parts.length; t < r; t++) {
		var T = document.getElementsByTagName(parts[t]);

		// create the alterNation
		for (var i = 0, l = T.length, c = 0; i < l; i++) {
			var tc = T[i].className;
			var a = tc.indexOf('altrows');
			var n = tc.indexOf('norows');
			if (n >= 0) {
				T[i].className = 'arc90_norows';
				var R = T[i].getElementsByTagName('TR');
					for (var j = 0, m = R.length; j < m; j++) {
						R[j].style.background = '';
						R[j].className = 'arc90_norows';
					}
			} else if (a >= 0 ) {
				var c = T[i].className.slice(a), s = c.indexOf(' '), x = null, z = '', cn = '';
				c = T[i].className.slice(a, s > 0? s: T[i].className.length).split('-');
				if (c.length == 2) { // theme
					cn = c[1];
				} else if (c.length > 2) { // rotating colours
					cn = c.slice(1);
					x = c.length - 1;
					z = -1;
				}

				// now go through every sub row and assign alternating row colours
				R = T[i].getElementsByTagName('TR');
				for (var j = 0, m = R.length; j < m; j++) {
					n = R[j].className.indexOf('norows');
					if (n >= 0)
						continue;
					z = (x != null && z+1 < x? z+1: x != null? 0: j % 2); // either the rotating row number or theme alternation
					if (x == null) R[j].className = 'arc90_altrows'+cn+''+z;
						else R[j].style.backgroundColor = '#'+ cn[z];
				}
			}
		}
	}
}

/* Events */
function arc90_isString(o) { return (typeof(o) == "string"); }

function arc90_isNumeric(o) { return (typeof(parseFloat(o).toString() == 'NaN'? 'xxx': parseFloat(o)) == "number" && parseFloat(o) != ''); }

function arc90_addEvent(e, meth, func, cap) {
	if (arc90_isString(e))	e = document.getElementById(e);

	if (e.addEventListener){
		e.addEventListener(meth, func, cap);
    	return true;
	}	else if (e.attachEvent)
		return e.attachEvent("on"+ meth, func);
	return false;
}

/* Nodes */
function arc90_newNode(t, i, s, x, c) {
	var node = document.createElement(t);
	if (x != null && x != '') {
		var n = document.createTextNode(x);
		node.appendChild(n);
	}
	if (i != null && i != '')
		node.id = i;
	if (s != null && s != '')
		node.className = s;
	if (c != null && c != '')
		node.appendChild(c);
	return node;
}

/* Onload */
arc90_addEvent(window, 'load', arc90_altrows);

