var offsetfromcursorX=12 //Customize x offset of help
var offsetfromcursorY=10 //Customize y offset of help

var offsetdivfrompointerX=10 //Customize x offset of Help DIV relative to header
var offsetdivfrompointerY=14 //Customize y offset of Help DIV relative to header.

document.write("<div id='helpText' align='justify'></div>") //write out tooltip DIV
document.write("<table id='helpHeader' bgcolor='navy'><tr><td class='headertext'>Help</td><td align='right'><img id='imgClose' src='Controls/HelpControl/close.gif' onclick='HideHelp()'></td></tr></table>") //write out Header

var ie=document.all
var ns6=document.getElementById && !document.all
var enableHelp=false
var helpObj
var headerObj
var imgCloseButton
if (ie||ns6)
{
    helpObj=document.all? document.all["helpText"] : document.getElementById? document.getElementById("helpText") : ""
    headerObj=document.all? document.all["helpHeader"] : document.getElementById? document.getElementById("helpHeader") : ""
    imgCloseButton=document.all? document.all["imgClose"] : document.getElementById? document.getElementById("imgClose") : ""
    helpObj.style.visibility="hidden"
    headerObj.style.visibility="hidden"
}

function ietruebody()
{
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}



function ShowHelp(thetext, thewidth, theheight, imgurl, thecolor)
 {
   // debugger;
    if (ns6||ie)
    {
        imgCloseButton.src = imgurl;
        helpObj.innerHTML=thetext;                     
               
        if(theheight==0)        
            helpObj.style.height = "auto";                    
        else
        {
            helpObj.style.height = theheight+ "px";
            helpObj.style.overflow="auto";
        }            
        
        helpObj.style.valign="top";
        helpObj.style.width = thewidth + "px"; 
        headerObj.style.width= thewidth + 19 + "px";
        enableHelp=true;        
        
        positionHelp();
        helpFade(10);
        return false;
    }
}


if(!ie){ document.captureEvents(Event.onCLICK);
        document.onclick = positionHelp;}




function helpFade(opac) 
{
    var passed = parseInt(opac);
    var newOpac = parseInt(passed+10);
    if ( newOpac < 100 ) 
    {
        helpObj.style.opacity = '.'+newOpac;
        helpObj.style.filter = "alpha(opacity:"+newOpac+") progid:DXImageTransform.Microsoft.Shadow(color=#696969,direction=135)";
        headerObj.style.opacity = '.'+newOpac;
        headerObj.style.filter = "alpha(opacity:"+newOpac+") progid:DXImageTransform.Microsoft.Shadow(color=#696969,direction=135)";
        opacityID = window.setTimeout("helpFade('"+newOpac+"')",20);
    }
    else 
    { 
        helpObj.style.opacity = '.100';
        helpObj.style.filter = "alpha(opacity:100) progid:DXImageTransform.Microsoft.Shadow(color=#696969,direction=135)";
        headerObj.style.opacity = '.100';
        headerObj.style.filter = "alpha(opacity:100) progid:DXImageTransform.Microsoft.Shadow(color=#696969,direction=135)";
    }
}



function positionHelp(e)
{
    if (enableHelp)
    {
        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 leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;
        
        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


        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge<helpObj.offsetWidth)
        {
            //move the horizontal position of the menu to the left by it's width
            helpObj.style.left=curX-helpObj.offsetWidth+"px";
            headerObj.style.left=helpObj.style.left;
            //nondefaultpos=true;
        }
        else if (curX<leftedge)
        {
            helpObj.style.left="5px";
            headerObj.style.left=helpObj.style.left;
        }
        
        else
        {
            //position the horizontal position of the menu where the mouse is positioned
            helpObj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
            headerObj.style.left=curX+2+"px";
        }
        
        
        //same concept with the vertical position
        if (bottomedge<helpObj.offsetHeight)
        {
            helpObj.style.top=curY-helpObj.offsetHeight-offsetfromcursorY+"px";
            headerObj.style.top=curY-helpObj.offsetHeight-offsetfromcursorY-22+"px";               
            nondefaultpos=false;
        }
        else
        {  
            helpObj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
            headerObj.style.top=curY+2+"px";
        }
        helpObj.style.visibility="visible";
        if (!nondefaultpos)
            headerObj.style.visibility="visible";
        else
            headerObj.style.visibility="hidden";
    }
}


function HideHelp()
{
    if (ns6||ie)
    {
        enableHelp=false
        helpObj.style.visibility="hidden"
        headerObj.style.visibility="hidden"
        helpObj.style.left="-1000px"
        helpObj.style.backgroundColor=''
        helpObj.style.width=''
    }
}

