function getElementPosition(elemID) {
		var offsetTrail = document.getElementById(elemID);
		var offsetLeft = 0;
		var offsetTop = 0;
		while (offsetTrail) {
				offsetLeft += offsetTrail.offsetLeft;
				offsetTop += offsetTrail.offsetTop;
				offsetTrail = offsetTrail.offsetParent;
		}
		if (navigator.userAgent.indexOf("Mac") != -1 && 
				typeof document.body.leftMargin != "undefined") {
				offsetLeft += document.body.leftMargin;
				offsetTop += document.body.topMargin;
		}
		return {left:offsetLeft, top:offsetTop};
}

var ptimer;
function delayed_popup(id, pos_id) {
	ptimer = window.setTimeout(function () { popup(id, pos_id); }, 300);
}
function popup(id,pos_id) {
	pos = getElementPosition(pos_id);

	$('#' + id).show();
	
	$('#' + id).css.position = 'absolute';
	$('#' + id).css.left = pos.left + 'px';
	$('#' + id).css.top = pos.top + 'px';
}
function cancel_popup() {
	window.clearTimeout(ptimer);
}
function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}		

