/** 
 * Redirects to the given url 
 * 
 * @param string	url		URL to redirect to
 */
function redirect(url) {
	window.location=url;
}

/** Note the following functions can probably be replaced if we add jquery or prototype */

/** Adds an event listener for a given element */
function hookEvent(element, eventName, callback) {
	if (typeof (element) == "string") {
		element = document.getElementById(element);
	}
	
	if (element != null) {
		if (element.addEventListener) {
			if (eventName == 'mousewheel') {
				element.addEventListener('DOMMouseScroll', callback, false);
			}
			element.addEventListener(eventName, callback, false);
		} else if (element.attachEvent) {
			element.attachEvent("on" + eventName, callback);
		}
	}
}

/** Removes an event listener for a given element */
function unhookEvent(element, eventName, callback) {
	if (typeof (element) == "string") {
		element = document.getElementById(element);
	}
	
	if (element != null) {
		if (element.removeEventListener) {
			if (eventName == 'mousewheel') {
				element.removeEventListener('DOMMouseScroll', callback, false);
			}
			element.removeEventListener(eventName, callback, false);
		} else if (element.detachEvent) {
			element.detachEvent("on" + eventName, callback);
		}
	}
}

/** Cancels an event so it no longer propagates */
function cancelEvent(e) {
	e = e ? e : window.event;
	if (e.stopPropagation) {
		e.stopPropagation();
	}
	if (e.preventDefault) {
		e.preventDefault();
	}
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

/** executes a func on load */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

