﻿/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var debug=false

var offsetfromcursorX=-5 //Customize x offset of tooltip
var offsetfromcursorY=-30 //Customize y offset of tooltip

var offsetdivfrompointerX=102 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=12 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var rightalign=false //to be set 'true' for help texts in admin to avoid hiding behind dropdowns

var borderwidth=4 //the value of the border width in the css for the tipobj

var hax=borderwidth*2
//We have to hax the placement javascript, because IE does not agree with other browsers on the border
if(navigator.appName=='Microsoft Internet Explorer'){
hax=0
}

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
if(debug)
{
    document.write('<div id="dhtmltooltipdebug"></div>');
}
document.write('<img id="dhtmlpointer" src="gfx/tooltip.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)

var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var tipdebugobj=document.all? document.all["dhtmltooltipdebug"] : document.getElementById? document.getElementById("dhtmltooltipdebug") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor, thealignment){
    if (ns6||ie){
        if (typeof thewidth!="undefined" && thewidth!="") tipobj.style.width=thewidth+"px"
        if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
        if (typeof thealignment!="undefined" && thealignment!=""){
            if (thealignment=="right"){ //in case we will ever need a 'left' ;)
                rightalign=true
            }
        }else{
            rightalign=false
        }
        if(!debug){
            tipobj.innerHTML=thetext
        }
        enabletip=true
        return false
    }
}

function positiontip(e){
    if (enabletip){
        var nondefaultpos=false
        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=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
        var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

        var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
        var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
        var topedge=ie&&!window.opera? event.clientY-(tipobj.offsetHeight-offsetfromcursorY-offsetdivfrompointerY) : e.clientY-(tipobj.offsetHeight-offsetfromcursorY-offsetdivfrompointerY)

        var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

        //Custom changes to keep bubble on screen
        //Get half the bubble width
        var half=tipobj.offsetWidth / 2;
        var height=tipobj.offsetHeight;
        var newoffsetleft = 0;
        var newoffsetheight = 0; //not in use
            
        //horizontal align
        if(((rightedge + half) > winwidth))
        {
            newoffsetleft = (winwidth - (rightedge + half));
        }
        else{
            if(rightedge < half)
            {
                newoffsetleft =  half - rightedge;
            }      
        }

        if (rightalign){
            tipobj.style.left=curX+offsetfromcursorX-(borderwidth*2)+"px"
            pointerobj.style.left=curX+offsetfromcursorX+"px"  
        }else{
            tipobj.style.left=(curX+offsetfromcursorX-offsetdivfrompointerX)-newoffsetleft+"px"
            pointerobj.style.left=curX+offsetfromcursorX+"px"  
        }
             
        if(topedge <= 0){
            pointerobj.src = "gfx/tooltip_up.gif";
            tipobj.style.top=(curY-offsetfromcursorY)+offsetdivfrompointerY-(borderwidth)+"px"
            pointerobj.style.top=curY-offsetfromcursorY+"px" 
        }else{
            pointerobj.src = "gfx/tooltip.gif";
            tipobj.style.top=(curY+offsetfromcursorY+offsetdivfrompointerY-(tipobj.offsetHeight+hax))+newoffsetheight+"px"
            pointerobj.style.top=curY+offsetfromcursorY+"px" 
        }
        
        //vertical align
        //if(((bottomedge + height) < winheight)) {    
            //tipobj.style.top=(curY+offsetfromcursorY+offsetdivfrompointerY-(tipobj.offsetHeight+hax))+newoffsetheight+"px"
            //pointerobj.style.top=curY+offsetfromcursorY+"px" 
        //}    

        if(debug)
        {
            //Gareth debugging
            tipobj.innerHTML="Width:" + winwidth + " Height: " + winheight;    
            tipobj.innerHTML= tipobj.innerHTML + "<br /> Right Edge:" + rightedge + " Bottom Edge: " + bottomedge;    
            tipobj.innerHTML= tipobj.innerHTML + "<br /> Left Edge:" + leftedge + " bubble width:" + tipobj.offsetWidth + " bubble height:" + tipobj.offsetHeight;    
            tipobj.innerHTML= tipobj.innerHTML + "<br /> New Offset Left:" + newoffsetleft + " New Offset Height: " + newoffsetheight + " " + (curX+offsetfromcursorX-offsetdivfrompointerX);    
            tipobj.innerHTML= tipobj.innerHTML + "<br /> Top Edge: " + topedge + " " + winheight + " " + event.clientY;
            tipobj.style.visibility="visible"
        }
        tipobj.style.visibility="visible"
        if (!nondefaultpos)
        pointerobj.style.visibility="visible"
        else
        pointerobj.style.visibility="hidden"
    }
}

function hideddrivetip(){
    if ((ns6||ie)){
        enabletip=false;
        tipobj.style.visibility="hidden"
        pointerobj.style.visibility="hidden"
        tipobj.style.left="-1000px"
        tipobj.style.backgroundColor=''
        tipobj.style.width=''
    }
}

document.onmousemove=positiontip;

function qblack(sQ_ID){
    var Q
    Q = document.getElementById(sQ_ID);
    Q.style.backgroundColor='#000000'
}

function qgrey(sQ_ID){
    var Q
    Q = document.getElementById(sQ_ID);
    Q.style.backgroundColor='#b5b5b5'
}

