/*
* Get all elements with a certain class name
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

/* 
* Add a class name to an element if the element hasn't that class.
*/
function addClassName(oElm, strClassName){
	var strCurrentClass = oElm.className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}

/*
* Remove a class name from an element and spaces which are not necessary after this operation
*/
function removeClassName(oElm, strClassName){
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}

/*
* A shorthand function for document.getElementById.
*/
function $(strId){
	return document.getElementById(strId);
}

/*
* Support for Array.push in IE 5.0
* Copyright Robert Nyman, http://www.robertnyman.com
* Free to use if this text is included
*/
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = function (){
		for(var i=0; i<arguments.length; i++){
        	this[this.length] = arguments[i];
        }
		return this.length;
	}
}

function addLoadEvent(func){
   var oldonload = window.onload;
   if(typeof window.onload != 'function'){
      window.onload = func;
   } else {
      window.onload = function() {
         oldonload();
         func();
      }
   }
}

