// this function adds a background color to every other row in the tables which have a class of "striped"
function stripeTables() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementsByTagName("table")) return false;
	var tables = document.getElementsByTagName("table");
	for (var i=0; i<tables.length; i++) {
		var class_name = tables[i].getAttribute("class");
		if (class_name !== "striped") continue;
		// creates a new variable 'odd' and sets initial value as false
		var odd = false;
		var rows = tables[i].getElementsByTagName("tr");
		// loops through all the rows in the current table
		for (var j=0; j<rows.length; j++) {
			//styles the background row of every second row in the table
			if (odd == true) {
				// call the "addClass" function to style the rows
				addClass(rows[j],"odd");
				// resets the value of odd to false
				odd = false;
			} else {
				// changes the value of odd to true so that the next row will get the styling
				odd = true;
			}
		}
	}
}

// this function assigns a class to an element
function addClass(element,value) {
	// does the element already have a class name? If not, "value" is assigned as class name
	if (!element.className) {
		element.className = value;
		// But if the element already has a class, then "value" is ADDED to the existing class
	} else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}

addLoadEvent(stripeTables);

