window.document.onmousemove = updatetip;

var tipvisible = 0;

function updatetip(e){

    if (tipvisible == 1){

        var posx = 0;
        var posy = 0;

        if (!e) var e = window.event;

        if (e.pageX || e.pageY){
            
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY){

            if (document.documentElement && document.documentElement.scrollTop)
            {

	        posx = e.clientX + document.documentElement.scrollLeft;
	        posy = e.clientY + document.documentElement.scrollTop;
            }
            else if (document.body){

                posx = e.clientX + document.body.scrollLeft;
	        posy = e.clientY + document.body.scrollTop;
            }
        }

        var w;
        var test1 = document.body.scrollWidth;
        var test2 = document.body.offsetWidth;

        if (test1 > test2){ 

            w = document.body.scrollWidth;
        }
        else{

            w = document.body.offsetWidth;
        }
      
        if ((posx+20+parseInt(document.getElementById('tooltip').style.width))>=w){

            posx = posx-(parseInt(document.getElementById('tooltip').style.width)+40);
        }   

        document.getElementById('tooltip').style.left = (posx + 20) + "px";
        document.getElementById('tooltip').style.top = (posy + 20) + "px";
    }
}

function showtip(text, w){

    tipvisible = 1;
    active = setTimeout("doshowtip('"+text+"', '"+w+"')", 500);
}

function doshowtip(text, w){

    if (tipvisible == 1){

        document.getElementById('tooltip').innerHTML = text;
        document.getElementById('tooltip').style.display = "block";

        if (w != 'undefined'){

            document.getElementById('tooltip').style.width = w+"px";
        }
        else{

            document.getElementById('tooltip').style.width = "100px";
        }
    }
}

function hidetip(){

    if (tipvisible = 1){

        document.getElementById('tooltip').style.display = "none";
        clearTimeout(active);
        tipvisible = 0;
    }
}