// JavaScript Document
// Displays a popup window with details on mouseover of element
/*
<span id="eventid" onMouseOver="PopupMenu('eventid', 1);" onMouseOut="PopupMenu('eventid', 0);">
	<a href="details.php?event=eventid" target="_blank">
		<div class = "event" style="width='.($tdwidth*$colspan).'px; height=1em;" >
					event text
		</div>
	</a>
	<div id="eventiddetails" class="eventdetails">'
		eventdetails text
			<div class="private">
				private details
			</div>
	</div>
</span>


*/
function getElementAbsPosX(el)
{
    var dx = 0;
    if (el.offsetParent) {
        dx = el.offsetLeft + 8;
        while (el = el.offsetParent) {
            dx += el.offsetLeft;
        }
    }
    return dx;
}

function getElementAbsPosY(el)
{
    var dy = 0;
    if (el.offsetParent) {
        dy = el.offsetTop + el.offsetHeight / 2;
        while (el = el.offsetParent) {
            dy += el.offsetTop;
        }
    }
    return dy;
}

function GetAbsWindowBottom()
{
    // Compute the bottom of the popup window and the bottom of
    // the browser window, in absolute co-ordinates - different
    // on all browsers but the below should be accurate usually!
 
    var abswindowbottom = 0;
    if (typeof(window.innerHeight) == 'number')
        abswindowbottom = window.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        abswindowbottom = document.documentElement.clientHeight;
    else if (document.body && document.body.clientHeight)
        abswindowbottom = document.body.clientHeight;
 
    if (typeof(window.pageYOffset) == 'number')
        abswindowbottom = abswindowbottom + window.pageYOffset;
    else if (document.body && document.body.scrollTop)
        abswindowbottom = abswindowbottom + document.body.scrollTop;
    else if (document.documentElement && document.documentElement.scrollTop)
        abswindowbottom = abswindowbottom + document.documentElement.scrollTop;
    return abswindowbottom;
}

function PopupMenu(name, vis)
{
    var el = name + 'details';
    var tag = name;
    if (!document.getElementById(el))  // menu object not found
        return;
    if (vis == 0) {  // hide the menu
        document.getElementById(el).style.visibility = 'hidden';
        return;
    }

    // Get menuroot position
    var pos = document.getElementById(tag);
    var dx = getElementAbsPosX(pos)+55;
    var dy = getElementAbsPosY(pos)-25;

    // Compare bottom of menu to bottom of window
    var abspopupbottom = dy + document.getElementById(el).clientHeight + 10;
    var abswindowbottom = GetAbsWindowBottom();
	dy = dy - document.getElementById(el).clientHeight +10;
    // If menu goes below bottom of window, move it up!
    if (abspopupbottom > abswindowbottom)
        dy = dy - (abspopupbottom - abswindowbottom);

    // Set final menu position and make it appear
    document.getElementById(el).style.left = dx + 'px';
    document.getElementById(el).style.top = dy + 'px';
    if (vis > 0)
        document.getElementById(el).style.visibility = 'visible';
}


/*On Click Popup window with no navigation
*/

function showdetails(x) {
window.open(x,Math.ceil(Math.random()*65535),'width=500px,height=300px,resizable=1,toolbar=0,locationbar=0,menubar=0,userbar=0');
																}