var ie = document.all;
var moz = document.getElementById && !document.all; 
var intr;
var tout;

////////////////////////////
// Floating-Text example
////////////////////////////

function getScrollTop() {
    var position = 0; 

    if (typeof window.pageYOffset != 'undefined') { 
	position = window.pageYOffset;
    } 

    else if (typeof document.documentElement.scrollTop 
      != 'undefined' && document.documentElement.scrollTop > 0) {
	position = document.documentElement.scrollTop; 
    } 
    else if (typeof document.body.scrollTop != 'undefined') {
	position = document.body.scrollTop;
    } 
    return position; 
}

function Message_UpdatePos(msg, dy) {
    var el = document.getElementById(msg);
    if (ie) {
	el.style.pixelTop = getScrollTop() + dy;
    }
    else if (moz) {
	el.style.top = window.pageYOffset + dy + 'px';
    }
}

function Message_Display(msg, vis, dx, dy) {
    var el = document.getElementById(msg);
    if (ie) {
	el.style.pixelTop = getScrollTop() + dy;
	el.style.pixelLeft = document.body.clientWidth - dx;
    }
    else if (moz) {
	el.style.left = window.innerWidth - dx + 'px';
	el.style.top = window.pageYOffset + dy + 'px';
    }
    if (vis) {
	el.style.visibility = "visible";
	intr = setInterval("Message_UpdatePos('" + msg + "', " + dy + ")", 1);
    }
    else {
	el.style.visibility = "hidden";
	if (intr)
	    clearInterval(intr);
    }
}

///////////////////////////
// Popup menu example
///////////////////////////

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, foo)
{
    var dy = 0;
    if (el.offsetParent) {
	dy = el.offsetTop + el.offsetHeight / 2;
	while (el = el.offsetParent) {
	    if (foo == 0)
		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 + 'menu';
    var tag = name + 'menuroot';
    if (!document.getElementById(el))
	return;
    if (vis == 0) {
	document.getElementById(el).style.visibility = 'hidden';
	return;
    }
	
    var pos = document.getElementById(tag);
    var dx = getElementAbsPosX(pos);
    var dy = getElementAbsPosY(pos, 1);
    var dyfoo = getElementAbsPosY(pos, 0);
    var abspopupbottom = dyfoo + document.getElementById(el).clientHeight + 10;
    var abswindowbottom = GetAbsWindowBottom();
    if (abspopupbottom > abswindowbottom)
	dy = dy - (abspopupbottom - abswindowbottom);
    document.getElementById(el).style.left = dx + 'px';
    document.getElementById(el).style.top = dy + 'px';
    if (vis > 0)
	document.getElementById(el).style.visibility = 'visible';
}

///////////////////////////////////////////////////////////////////////////////////////////////////
