var ttXpos = 0, ttYpos = 0;
var ttXadd = -5, ttYadd = 0;
var ttDisplay = 0, ttHoldIt = 0;
var ttNS4 = (document.layers) ? 1 : 0; 
var ttIE4 = (document.all) ? 1 : 0; 
var ttDOM = (document.getElementById) ? 1 : 0;
if (ttDOM) { 
    ttNS4 = 0;
    ttIE4 = 0;
}


function getPos(elem)
{
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

var myTooltipContainer = null;
var myTooltipContent = null;

if ( (ttDOM) || (ttIE4) || (ttNS4) ) {
    if ( ttNS4 ) {
        document.captureEvents(Event.CLICK);
    } else {
        document.onclick = click;
    }
}

function textTooltip(theText) {
    if	(ttDOM || ttIE4) {  
        myTooltipContent.innerHTML = ""; 
        myTooltipContent.innerHTML = theText;
    } else if (ttNS4) {                    
        var layerNS4 = myTooltipContent.document;
        layerNS4.write(theText);
        layerNS4.close();
    }
}

/**
 * @var integer
 */
var ttTimerID = 0;
    var x = 0, y = 0;


/**
 * swap the Tooltip // show and hide
 *
 * @param boolean stat view status
 */
function swapTooltip(stat) {
    if (ttHoldIt!=1) {
        if (stat!='default') {
            if (stat=='true')
                showTooltip(true);
            else if (stat=='false')
                showTooltip(false);
        } else {
            if (ttDisplay)
                ttTimerID = setTimeout("showTooltip(false);",500);
            else
                showTooltip(true);
        }
    } else {
        if (ttTimerID) {
           clearTimeout(ttTimerID);
           ttTimerID = 0;
        }
        showTooltip(true);
    }
}

function showTooltip(stat) {
    if (stat==false) {
        if (ttNS4)
            myTooltipContainer.visibility = "hide";
        else
            myTooltipContainer.style.visibility = "hidden";
        ttDisplay = 0;
    } else {
        if (ttNS4)
            myTooltipContainer.visibility = "show";
        else
            myTooltipContainer.style.visibility = "visible";
        ttDisplay = 1;
    }
}
function holdTooltip() {
    ttHoldIt = 1;
    swapTooltip('true');
    ttHoldIt = 0;
}
function closett() {
    ttDisplay = 0;
    showTooltip('false');
    moveTooltip(-1000,-1000);
}

function moveTooltip(posX, posY) {
    if (ttDOM || ttIE4) {
        myTooltipContainer.style.left	=	posX + "px";
        myTooltipContainer.style.top  =	posY + "px";
    } else if (ttNS4) {
        myTooltipContainer.left = posX;
        myTooltipContainer.top  = posY;
    }
}

function pmaTooltip( theText, link ) {
    if ( null == myTooltipContainer ) {
        if (ttNS4) {
            myTooltipContainer = document.TooltipContainer;
            myTooltipContent = document.TooltipContent;
        } else if (ttIE4) {
            myTooltipContainer = document.all('TooltipContainer');
            myTooltipContent = document.all('TooltipContent');
        } else if (ttDOM) {
            myTooltipContainer = document.getElementById('TooltipContainer');
            myTooltipContent = document.getElementById('TooltipContent');
        } else {
            return;
        }

        if ( typeof( myTooltipContainer ) == 'undefined' ) {
            return;
        }
    }

    var plusX=0, plusY=0, docX=0, docY=0;
    var divHeight = myTooltipContainer.clientHeight;
    var divWidth  = myTooltipContainer.clientWidth;
    if (navigator.appName.indexOf("Explorer")!=-1) {
        if (document.documentElement && document.documentElement.scrollTop) {
            plusX = document.documentElement.scrollLeft;
            plusY = document.documentElement.scrollTop;
            docX = document.documentElement.offsetWidth + plusX;
            docY = document.documentElement.offsetHeight + plusY;
        } else {
            plusX = document.body.scrollLeft;
            plusY = document.body.scrollTop;
            docX = document.body.offsetWidth + plusX;
            docY = document.body.offsetHeight + plusY;
        }
    } else {
        docX = document.body.clientWidth;
        docY = document.body.clientHeight;
    }


    
pos = getPos(link);
x = pos.left;
y = pos.top;
textTooltip(theText);
moveTooltip((x + ttXadd), (y + ttYadd));
holdTooltip();
}


function pmaTooltip2( theText, link ) {
    if ( null == myTooltipContainer ) {
        if (ttNS4) {
            myTooltipContainer = document.TooltipContainer;
            myTooltipContent = document.TooltipContent;
        } else if (ttIE4) {
            myTooltipContainer = document.all('TooltipContainer');
            myTooltipContent = document.all('TooltipContent');
        } else if (ttDOM) {
            myTooltipContainer = document.getElementById('TooltipContainer');
            myTooltipContent = document.getElementById('TooltipContent');
        } else {
            return;
        }

        if ( typeof( myTooltipContainer ) == 'undefined' ) {
            return;
        }
    }

    var plusX=0, plusY=0, docX=0, docY=0;
    var divHeight = myTooltipContainer.clientHeight;
    var divWidth  = myTooltipContainer.clientWidth;
    if (navigator.appName.indexOf("Explorer")!=-1) {
        if (document.documentElement && document.documentElement.scrollTop) {
            plusX = document.documentElement.scrollLeft;
            plusY = document.documentElement.scrollTop;
            docX = document.documentElement.offsetWidth + plusX;
            docY = document.documentElement.offsetHeight + plusY;
        } else {
            plusX = document.body.scrollLeft;
            plusY = document.body.scrollTop;
            docX = document.body.offsetWidth + plusX;
            docY = document.body.offsetHeight + plusY;
        }
    } else {
        docX = document.body.clientWidth;
        docY = document.body.clientHeight;
    }


    
pos = getPos(link);
x = pos.left;
y = pos.top;
textTooltip(theText);
moveTooltip((x + ttXadd), (y + ttYadd));
holdTooltip();
}

function click(e) {
    if ( typeof( event ) != 'undefined' ) {
        ttXpos = event.x;
        ttYpos = event.y;
    } else {
        ttXpos = e.pageX;
        ttYpos = e.pageY;
    }
    x = ttXpos;
    y = ttYpos;
}

