/* Copyright Schools on the Net 2006. */

function addOnLoad(func) {
	window.onload = _makeOnLoad(func, window.onload);
}

function _makeOnLoad(func, currentOnLoad) {
	return function() {
		if(currentOnLoad != null) {
			currentOnLoad();
		}
		func();
	};
}

function forEachElementOfClass(className, block) {
	// Find all possible elements.
	potentials = document.getElementsByTagName("*");

	for(var potentialIx = 0; potentialIx < potentials.length; potentialIx ++) {
		potential = potentials[potentialIx];

		if(potential.className != className) {
			continue;
		}

		// Invoke block for the potential.
		block(potential);
	}
}

function forEachElementOfTag(tagName, block) {
	// Find all possible elements.
	forEach(document.getElementsByTagName(tagName), block);
}

function forEach(collection, block) {
	for(var itemIx = 0; itemIx < collection.length; itemIx ++) {
		var item = collection[itemIx];
		block(item);
	}
}
