// Copyright (c) 2008 Ezer IT Consulting. All rights reserved.
// For information contact claus@ezer.dk.

var currenttip = null;

// Show a tip with the specified name
function showTip(e,name) {
    var coord = getMouseXY(e,name);

    if (document.getElementById(name).style.visibility!="visible") {
        var popup = document.getElementById(name);
        var docBody = document.body;

        var popupHeight = popup.offsetHeight;
        var popupWidth = popup.offsetWidth;

        var left, top;

        if (coord[0]-docBody.scrollLeft+10+popupWidth < docBody.clientWidth)
            // Position to the right of the cursor
            left = coord[0]+10;
        else
            // Position to the left of the cursor
            left = coord[0]-10-popupWidth;

        if (coord[1]-docBody.scrollTop+10+popupHeight < docBody.clientHeight)
            // Position below the cursor
            top = coord[1]+10;
        else
            // Position above the cursor
            top = coord[1]-10-popupHeight;

        popup.style.visibility = "visible";
        popup.style.left = left;
        popup.style.top	 = top;
        currenttip = popup;
    }
}

// Hide a tip with the specified name
function hideTip(name) {
    document.getElementById(name).style.visibility = "hidden";
}


// Remove current tip. Requred by Firefox lest a tip is still there when the
// back button is pressed
function unloading() {
    if (currenttip!=null)
	currenttip.visibility = "hidden";
}


// Sets posX and posY to the mouse coordinates relative to the document
function getMouseXY(e,name) {
    if (!e) var e = window.event;

    var posX, posY;

	if (e.pageX || e.pageY) {
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
    
    posX -= document.getElementById("container").offsetLeft;
    posY -= document.getElementById("container").offsetTop;

    return [posX,posY];
}

function confirm_request(question,yes_url)
{
    if (confirm(question))
        location = yes_url;
}
