/**********************************************************************
 * Adds an event handler 'listenerFunction' for the 'eventType' 
 * event to the 'obj' object
 **********************************************************************/
function addEvent(obj, eventType, listenerFunction) {
	if(isIE) {  // Internet Explorer
		obj.attachEvent('on' + eventType, listenerFunction);
	}
	else if(isFF) {  // Firefox
		obj.addEventListener(eventType, listenerFunction, true);
	}
}
/**********************************************************************
 * Stops the event
 **********************************************************************/
function stopEvent(ev) {
	if(isIE) {  // Internet Explorer
		try {
			ev.cancelBubble = true;
			ev.returnValue = false;
		}
		catch(ex) { }
	}
	else if(isFF) {  // Firefox
		ev.preventDefault();
		ev.stopPropagation();
	}
}
function getElementById(tag_name, id) {
	var objs = document.getElementsByTagName(tag_name);
	for(var i in objs) {
		if(objs[i].id == id) return objs[i];	
	}
	
	return false;
}
/**********************************************************************
 * Returns an object with properties w and h containing the given
 * objects width and height
 **********************************************************************/
function getSize(obj) {
	if(typeof obj != 'object') return false;

	var size = {
		w: getSizeW(obj) + 'px',
		h: getSizeH(obj) + 'px'
	};
	
	return size;
}
/**********************************************************************
 * Returns the given objects width in pixels
 **********************************************************************/
function getSizeW(obj) {
	if(typeof obj != 'object') return false;	
	
	return obj.offsetWidth;
}
/**********************************************************************
 * Returns the given objects height in pixels
 **********************************************************************/
function getSizeH(obj) {
	if(typeof obj != 'object') return false;
	
	return obj.offsetHeight;
}
/**********************************************************************
 * Returns an object with properties x and y containing the given
 * objects x and y position
 **********************************************************************/
function getPos(obj) {
	if(typeof obj != 'object') return false;

	var pos = {
		x: getPosX(obj) + 'px',
		y: getPosY(obj) + 'px'
	};
	
	return pos;
}
/**********************************************************************
 * Returns the given objects x position
 **********************************************************************/
function getPosX(obj) {
	if(typeof obj != 'object') return false;

	var curLeft = 0;
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curLeft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x) {
		curLeft += obj.x	
	}
	else {
		curLeft += obj.offsetLeft;	
	}
	
	return curLeft;
}
/**********************************************************************
 * Returns the given objects y position
 **********************************************************************/
function getPosY(obj) {
	if(typeof obj != 'object') return false;

	var curTop = 0;
	if(obj.offsetParent) {
		while(obj.offsetParent) {
			curTop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if(obj.y) {
		curTop += obj.y	
	}
	
	return curTop;
}
/**********************************************************************
 * Returns a clone of the given object
 **********************************************************************/
function cloneObject(obj) {
	if(!obj) return null;
	
	var new_obj = new Object();
	
	if(obj.constructor.toString().match(/\s*function Array\(/)) {  // Array object
		new_obj = obj.constructor();											
	}
	else if(obj.constructor.toString().match(/\s*function Function\(/)) {  // Function object
		new_obj = obj;
	}
	else {  // Object object
		for(var i in obj) {
			var node = obj[i];
			
			if(typeof node == 'object') {
				new_obj[i] = cloneObject(node);
			}
			else {
				new_obj[i] = node;	
			}
		}
	}
	return new_obj;
}