caja-safe roots javascript utils

var foreach = function(collection, callback){//tested: ff 3 mac
	if(collection.length){//array or node list
		for(var i = 0; i < collection.length; i++){
			callback(i, collection[i]);
		}
	}else if(collection.hasOwnProperty){
		for(var key in collection){
			if(collection.hasOwnProperty(key)){
				callback(key, collection[key]);
			}
		}
	}else{
		throw('each() error: collection (' + collection + ') is neither an array nor an object');
	}
},
getElementsByClassName = function(elements, className){
	var nodes = [];
	foreach(elements, function(i,element){
		if(className === element.className){
			nodes.push(element);
		}
	});
	return nodes;
},
hasClass = function(node, className){//tested: ff 2/3 win/mac, ie 6/7 win
	return new RegExp('[\b]*' + className + '[\b]*').test(node.className);
},