
/* All material from Jeremy Keith's "DOM Scripting: Web Design with JavaScript and the Document Object Model"
**
** Scripts may have been modified
*/

/*********************************************************************************
*	
*	addClass
*	addLoadEvent
*	insertAfter
*	stripeTables
*********************************************************************************/



/*********************************************************************************
*****
*********************************************************************************/
function addClass(element,value) {
	if (!element.className) {
		element.className = value;
	}
	else {
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
	}
}



/*********************************************************************************
*****
*********************************************************************************/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} 
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}



/*********************************************************************************
*****
*********************************************************************************/
function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}



/*********************************************************************************
*****
*********************************************************************************/
function stripeTables () {
	if (!document.getElementsByTagName) {
		return false;
	}
	var tables = document.getElementsByTagName("table");
	for (var i=0; i<tables.length; i++) {
		var altRow = false;
		var rows = tables[i].getElementsByTagName("tr");
		for (var j=0; j<rows.length; j++) {
			if (altRow == true) {
				addClass(rows[j],"altRow");
				altRow = false;
			}
			else {
				altRow = true;
			}
		}
	}
}

addLoadEvent(stripeTables);

