
// Return the X coordinate of the specified HTML object relative
// to the window.
function getElemPosX(o)
{
	var x = 0;
	while (o.offsetParent) {
		x += o.offsetLeft
		o = o.offsetParent;
	}
	return x;
}

// Return the Y coordinate of the specified HTML object relative
// to the window.
function getElemPosY(o)
{
	var y = 0;
	while (o.offsetParent) {
		y += o.offsetTop
		o = o.offsetParent;
	}
	return y;
}

// Returns the coordinate of the mouse pointer relative to the
// element which fired the mouse event. 
function getMouseEventX(e)
{
	var x = document.all? event.offsetX : e.layerX;
	return x;
}

// Returns the coordinate of the mouse pointer relative to the
// element which fired the mouse event. 
function getMouseEventY(e)
{
	var y = document.all? event.offsetY : e.layerY;
	return y;
}

// Returns the element which fired the event. Must be called from
// within an event handler.
function getEventTarget(e)
{
	var t = document.all? event.srcElement : e.target;
	return t;
}

// Displays a debug message. Used for development. The document must have
// an element with id="debug-info".
function debugMessage(append, s)
{
	var debugElem = document.getElementById("debug-info");
	if (!debugElem)
		return;
	if (append)
		debugElem.innerHTML += s + " ";
	else
		debugElem.innerHTML = "script debug messages:<br>" + s + " ";
}

