//
// These functions will show and hide a text box next to the current cursor position.
//

function showinfobox(currentObj, ev, text)
{
    // Determine dimensions of client window
    if (self.innerWidth)
    {
	    frameWidth = self.innerWidth;
    	frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
    	frameWidth = document.documentElement.clientWidth;
    	frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
    	frameWidth = document.body.clientWidth;
    	frameHeight = document.body.clientHeight;
    }

    // Determine dimensions of client window
    var scrollX = 0;
    var scrollY = 0;
    if (document.documentElement && document.documentElement.scrollTop)
    {
    	scrollX = document.documentElement.scrollLeft;
    	scrollY = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
    	scrollX = document.body.scrollLeft;
    	scrollY = document.body.scrollTop;
    }
    else
    {
        scrollX = self.pageXOffset;
        scrollY = self.pageYOffset;
    }

    // Locate the infobox div
    if (typeof(document.infobox) == "object")
        var infobox = document.infobox;
    else if ((typeof(document.getElementById) == "function") && (typeof(document.getElementById("infobox")) == "object"))
        var infobox = document.getElementById("infobox");
    else if ((typeof(document.all) == "object") && (typeof(document.all.infobox) == "object"))
        var infobox = document.all.infobox;

    // Determine the position of the cursor
    var isIE = (navigator.userAgent.indexOf('MSIE') != -1)
	var posx = 0;
	var posy = 0;
	if (!ev) var ev = window.event;
	if (ev.pageX || ev.pageY)
	{
		posx = ev.pageX;
		posy = ev.pageY;
	}
	else if (ev.clientX || ev.clientY)
	{
		posx = ev.clientX;
		posy = ev.clientY;
		if (isIE)
		{
			posx += document.body.scrollLeft;
			posy += document.body.scrollTop;
		}
	}

	// posx and posy contain the mouse position relative to the document
	// Do something with this information
    cursorX = posx;
    cursorY = posy;
    var DIV_WIDTH = 260;
    
    // Adjust location of infobox to prevent it from going offscreen
    var locX = cursorX + 20;
    if (((locX + DIV_WIDTH) - scrollX) > (frameWidth - 20))
        locX = (scrollX + frameWidth - 20) - DIV_WIDTH;
    var locY = cursorY + 20;

    if (typeof(infobox.innerHTML) != "undefined")
    {
        infobox.style.width = DIV_WIDTH;
        infobox.innerHTML = text;
        if (((locY + infobox.offsetHeight) - scrollY) > (frameHeight - 20))
            locY = (frameHeight + scrollY - 20) - infobox.offsetHeight;
//alert(cursorY + ":" + frameHeight + ":" + scrollY + ":" + infobox.offsetHeight + ":" + locY);
        infobox.style.left = locX;
        infobox.style.top = locY;
        infobox.style.backgroundColor = "e4e9f2";
        infobox.style.border = "1px solid black";
        infobox.style.textAlign = "center";
        infobox.style.visibility = "visible";
    }
    else if (document.layers)
    {
        // Handle NS4
        document.infobox.document.write('<layer bgColor="white" style="width:' + DIV_WIDTH + ';border:1px solid black;"><span style="font-size:12px;font-family:arial, verdana, arial"><center>' + text + '</center></span></layer>');
        document.infobox.document.close()
        document.infobox.left = locX;
        document.infobox.top = cursorY + 20;
        document.infobox.visibility = "show";
    }
}

function hideinfobox()
{
    if (document.layers)
        document.infobox.visibility="hidden";
    else
    {
        // Locate the infobox div
        if (typeof(document.infobox) == "object")
            var infobox = document.infobox;
        else if ((typeof(document.getElementById) == "function") && (typeof(document.getElementById("infobox")) == "object"))
            var infobox = document.getElementById("infobox");
        else if ((typeof(document.all) == "object") && (typeof(document.all.infobox) == "object"))
            var infobox = document.all.infobox;

        infobox.style.visibility="hidden";
    }
}
