// global variables
var TIMEOUT_ID;
/* single out IE through feature detection */
var isActiveX = (window.ActiveXObject) ? true : false;

function addEvent(obj, evtType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evtType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evtType, fn);
		return r;
	} else {
		obj['on'+evtType] = fn;
		return true;
	}
}

function EvtHandler(evtObj) {
	this.evt = evtObj;
	this.evtTarget = this.evt.target ? this.evt.target : this.evt.srcElement ? this.evt.srcElement : evtObj;
	if (this.evtTarget.nodeType == 3) this.evtTarget = this.evtTarget.parentNode;
	this.evtType = this.evt.type ? this.evt.type : null;
}


function createXhtmlElement(obj) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', obj);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(obj);
	}
	return false;
}

// Retrieve the first ancestor of a given element that matches the given 
// tag name.
function getAncestorByTagName(obj, tag) {
    var s = obj ? obj : null;
    if (s == null) return s;
    var tagName;
    do {
        s  = s.parentNode;
        tagName = s.tagName.toLowerCase();
        if (tagName=='body') return null;
    }
    while (tagName != tag);
    return s;   
}

function cancelHref(e) {
	if (e && e.preventDefault) {
		e.preventDefault();
		/* old-style event handler for Safari (at least until Apple fixes its DOM standard event support) */
		var target = e.target ? e.target : e.srcElement? e.srcElement : null;
		if (target && target.nodeType == 3) target = target.parentNode;
		if (target && target.tagName.toLowerCase() == "a" && e.type == "click"){
			target.onclick = function(){return false;}
			}
	}
	if (window.event) {
		window.event.returnValue = false;
		return false;
	}
}


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
