// - - - - [ addEvent ]
// crossbrowser event listener by Scott Andrews
function addEvent (elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else
		elm['on' + evType] = fn;
}

// - - - - [ addLoadEvent ]
// add a function call to window.onload without affecting already existing calls.
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// - - - - [ getAncestor ]
// look up the DOM Tree for the nearest element with a given tagName
function getAncestor(elm,tagname,excludeMyself) {
	if (!excludeMyself && elm.tagName.toLowerCase() == tagname.toLowerCase())
		return elm;
	if (elm == document.body)
		return null;
	return getAncestor(elm.parentNode,tagname);
}