function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/*
Copyright Robert Nyman, http://www.robertnyman.com
Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue) {
     var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
     var arrReturnElements = new Array();
     var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
     var oCurrent;
     var oAttribute;
     for(var i=0; i<arrElements.length; i++) {
         oCurrent = arrElements[i];
         oAttribute = oCurrent.getAttribute(strAttributeName);
         if (typeof oAttribute == "string" && oAttribute.length > 0) {
             if (typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                 arrReturnElements.push(oCurrent);
             }
         }
     }
     return arrReturnElements;
}

var domEl = function(e,c,a,p,x) {
	if(e||c) {
		c=(typeof c=='string'||(typeof c=='object'&&!c.length))?[c]:c;   
		e=(!e&&c.length==1)?document.createTextNode(c[0]):e;   
    	var n = (typeof e=='string')?document.createElement(e) : !(e&&e===c[0])?e.cloneNode(false):e.cloneNode(true);   
	    if(e.nodeType!=3) {
			c[0]===e?c[0]='':'';
			for(var i=0,j=c.length;i<j;i++) typeof c[i]=='string'? n.appendChild(document.createTextNode(c[i]))  : n.appendChild(c[i].cloneNode(true));
			if(a) {for(var i=(a.length-1);i>=0;i--) a[i][0]=='class' ? n.className=a[i][1] : n.setAttribute(a[i][0],a[i][1]);}
    	}
	}
	if(!p)return n;
    p=(typeof p=='object'&&!p.length)?[p]:p;
	for(var i=(p.length-1);i>=0;i--) {
		if(x) { while(p[i].firstChild) p[i].removeChild(p[i].firstChild);
		if(!e&&!c&&p[i].parentNode) p[i].parentNode.removeChild(p[i]);}
		if(n) p[i].appendChild(n.cloneNode(true));
	}
}