// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety =  8;
var offsetdivX=10; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivY=14; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 

var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            backgroundColor = '#f0f7ff';
            width = '300px';
            display = 'none';
            position = 'absolute';
            border = '1px solid #E1E1E1';
            //align = 'left';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
function newelement_width(newid,wid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            backgroundColor = '#f0f7ff';
            width = wid;
            display = 'none';
            position = 'absolute';
            border = '1px solid #E1E1E1';
            //align = 'left';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 
function getmouseposition(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

      var mytip = document.getElementById('tooltip');
        mytip.style.left = (mousex+pagex+offsetx) + 'px';
        mytip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function getmouseposition_width(e)
{
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

      var mytip = document.getElementById('tooltip_width');
        mytip.style.left = (mousex+pagex+offsetx) + 'px';
        mytip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function positiontip(e)
{
   
    var mytip = document.getElementById('tooltip');

    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var winwidth=ie5&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
    var winheight=ie5&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

    var rightedge=ie5&&!window.opera? winwidth-event.clientX-offsetx : winwidth-e.clientX-offsetx
    var bottomedge=ie5&&!window.opera? winheight-event.clientY-offsety : winheight-e.clientY-offsety

    var leftedge=(offsetx<0)? offsetx*(-1) : -1000

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<mytip.offsetWidth)
    {
        //move the horizontal position of the menu to the left by it's width
        mytip.style.left=curX-mytip.offsetWidth+"px"
    }
    else if (curX<leftedge)
        mytip.style.left="5px"
    else
    {
        //position the horizontal position of the menu where the mouse is positioned
        mytip.style.left=curX+offsetx-offsetdivX+"px"
    }

    //same concept with the vertical position
    if (bottomedge<mytip.offsetHeight)
    {
        mytip.style.top=curY-mytip.offsetHeight-offsety+"px"

    }
    else
    {
        mytip.style.top=curY+offsety+offsetdivY+"px"
    }
    mytip.style.visibility="visible"

}
function positiontip_width(e)
{
   
    var mytip = document.getElementById('tooltip_width');

    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var winwidth=ie5&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
    var winheight=ie5&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

    var rightedge=ie5&&!window.opera? winwidth-event.clientX-offsetx : winwidth-e.clientX-offsetx
    var bottomedge=ie5&&!window.opera? winheight-event.clientY-offsety : winheight-e.clientY-offsety

    var leftedge=(offsetx<0)? offsetx*(-1) : -1000

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<mytip.offsetWidth)
    {
        //move the horizontal position of the menu to the left by it's width
        mytip.style.left=curX-mytip.offsetWidth+"px"
    }
    else if (curX<leftedge)
        mytip.style.left="5px"
    else
    {
        //position the horizontal position of the menu where the mouse is positioned
        mytip.style.left=curX+offsetx-offsetdivX+"px"
    }

    //same concept with the vertical position
    if (bottomedge<mytip.offsetHeight)
    {
        mytip.style.top=curY-mytip.offsetHeight-offsety+"px"

    }
    else
    {
        mytip.style.top=curY+offsety+offsetdivY+"px"
    }
    mytip.style.visibility="visible"

}
function tooltip(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var mytip = document.getElementById('tooltip');
    mytip.innerHTML = tip;
    mytip.style.display = 'block';
    mytip.style.align = 'justify';

    document.onmousemove = positiontip; //getmouseposition
}
function tooltip_width(tip,wid)
{
    newelement_width('tooltip_width',wid);
    var mytip = document.getElementById('tooltip_width');
    mytip.innerHTML = tip;
    mytip.style.display = 'block';
    mytip.style.align = 'justify';

    document.onmousemove = positiontip_width; //getmouseposition
}

function exit_width(e)
{
  var mytip = document.getElementById('tooltip_width');
    mytip.style.display = 'none';
    mytip.style.position = 'absolute';
}
function exit(e)
{
  var mytip = document.getElementById('tooltip');
    mytip.style.display = 'none';
    mytip.style.position = 'absolute';
}
