function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function toggleDisplay(id) {
	var o = getElement(id);
	var onDisplay = 'block';
	if (!isIE()) {
		if (o.nodeName == 'TBODY') {
			onDisplay = 'table-row-group';
		}
	}

	if (o && o.style) {
		if (o.style.display == 'none' || o.style.display == '') {
			o.style.display = onDisplay; 
		} else { 
			o.style.display = 'none'; 
		}
	}
}

function openWindow(url, width, height, name, settings) {
	var screen_width = (screen.width) ? screen.width : ((screen.availWidth) ? screen.availWidth: 0);
	var screen_height = (screen.height) ? screen.height : ((screen.availHeight) ? screen.availHeight: 0);
	var left = 0;
	var top = 0;
	width = (!width) ? 0 : width;
	height = (!height) ? 0 : height;
	name = (!name) ? "" : name;
	settings = (!settings) ? "" : settings;
	if (screen_width > 0 && width > 0 && screen_height > 0 && height > 0) {
		left = (screen_width - width) / 2;
		top = (screen_height - height) / 2;
	}
	if (width > 0) { settings = 'width=' + width + ',' + settings;}
	if (height > 0) { settings = 'height=' + height + ',' + settings;}
	if (left > 0) { settings = 'left=' + left + ',' + settings;}
	if (top > 0) { settings = 'top=' + top + ',' + settings;}
	return window.open(url, name, settings);
}

Array.prototype.find = function (x) {
	for(var i = 0; i < this.length; i++) {
		if (this[i] == x) {
			return true;
		}
	}
}

//
// get the target inside an event.
//
function getTarget(e) {
	var t;
	if (!e) { e = window.event; }
	if (e.target) { t = e.target; }
	else if (e.srcElement) { t = e.srcElement; }
	if (t.nodeType == 3) { t = t.parentNode; }
	return t;
}

function getElement(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	}
	return null;
}

/*
** Positioning
*/
function getX(obj) {
	var left = 0;
	if (obj.offsetParent) {
		left += obj.offsetLeft + getX(obj.offsetParent);
	} else if (obj.x) {
		left += obj.x;
	}
	return left;
}

function getY(obj) {
	var top = 0;
	if (obj.offsetParent) {
		top += obj.offsetTop + getY(obj.offsetParent);
	} else if (obj.y) {
		top += obj.y;
	}
	return top;
}

/*
** isFunctions
*/
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    if (typeof a == 'string') {
		return true;
	} else if (typeof a == 'object') {
		var stringObjCheck = a.constructor.toString().match(/string/i); 
		return (stringObjCheck != null);  
	}
	return false;
}
function isUndefined(a) {
    return typeof a == 'undefined';
}
/*
** Browser Detection
*/
function isIE() {
	return document.all;
}

