//OFT1.1


///////////////////////////////////////
//
//  Onfocus tooltips by Brothercake
//  http://www.brothercake.com/
//
///////////////////////////////////////

//
// Flag to disable/enable this custom tooltip.
// It's set to true (enable) by default.
//
var m_bEnabledTooltip = true;

//global object and initial properties
var tip = {
    'tooltip' : null,
    'parent' : null,
    'timer' : null
    };



//initialisation function
tip.init = function()
{
    // [phi,040105] Disable tooltip when either flag is specified.
    // The second flag will be defined inside the actual HTML.
    if (m_bEnabledTooltip==false)
        return;

    //if the necessary collection is supported
    if(typeof document.getElementsByTagName != 'undefined')
    {
        //get all tags 
        tip.tags = document.getElementsByTagName('*');
        tip.tagsLen = tip.tags.length;
    
        for (var i=0; i < tip.tagsLen; i++)
        {
            with (tip.tags[i]) 
            {
                //if tag has a title attribute 
                // [phi,040105] - interested only in those with "usetooltip" flag.
                if(title && (typeof usetooltip!="undefined"))
                {
                    //attach handlers
                    onfocus = tip.focusTimer;
                    onblur = tip.blurTip;
                    onmouseover = tip.blurTip;
                }
            }   
        }
    }
}



//setup initialisation function
if(typeof window.addEventListener != 'undefined')
{
    //.. gecko, safari, konqueror and standard
    window.addEventListener('load', tip.init, false);
}
else if(typeof document.addEventListener != 'undefined')
{
    //.. opera 7
    document.addEventListener('load', tip.init, false);
}
else if(typeof window.attachEvent != 'undefined')
{
    //.. win/ie
    window.attachEvent('onload', tip.init);
}



//find object position
tip.getRealPosition = function(ele, dir)
{
    tip.pos = (dir=='x') ? ele.offsetLeft : ele.offsetTop;
    tip.tmp = ele.offsetParent;
    while(tip.tmp != null)
    {
        tip.pos += (dir=='x') ? tip.tmp.offsetLeft : tip.tmp.offsetTop;
        tip.tmp = tip.tmp.offsetParent;
    }
    return tip.pos;
}




//delay timer
tip.focusTimer = function(e)
{
    //second loop   
    if(tip.timer != null)
    {
        //clear timer
        clearInterval(tip.timer);
        tip.timer = null;
    
        //pass object to create tooltip
        tip.focusTip(e);
    }
    //first loop
    else
    {
        //get focussed object to pass back through timer
        tip.tmp = (e) ? e.target : event.srcElement;
    
        //set interval
        tip.timer = setInterval('tip.focusTimer(tip.tmp)',400);
    }
}


//create tooltip
tip.focusTip = function(obj)
{

    //remove any existing tooltip
    tip.blurTip();
  //hide Iframe * EB 1/25/2005
    document.getElementById('DivShim').style.display = "none";
  //add-in timer to remove tip * EB 1/12/2005
  tip.timer = setInterval(tip.blurTip,5500);
    //if tooltip is null
    if(tip.tooltip == null)
    {
        //get window dimensions
        if(typeof window.innerWidth!="undefined")
        {
            tip.window = {
                x : window.innerWidth,
                y : window.innerHeight
                };
        }
        else if(typeof document.documentElement.offsetWidth!="undefined")
        {
            tip.window = {
                x : document.documentElement.offsetWidth,
                y : document.documentElement.offsetHeight
                };
        }
        else 
        {
            tip.window = {
                x : document.body.offsetWidth,
                y : document.body.offsetHeight
                };
        }

        //create toolTip, detecting support for namespaced element creation, in case we're in the XML DOM
        tip.tooltip = (typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'div') : document.createElement('div');

        //add classname
        tip.tooltip.setAttribute('class','');       
        tip.tooltip.className = 'tooltip';
        tip.tooltip.setAttribute('id','tooltip');

        //get focussed object co-ordinates
        if(tip.parent == null)
        {
            tip.parent = {
                x : tip.getRealPosition(obj,'x'),
                y : tip.getRealPosition(obj,'y') + 2
                };
        }

        // offset tooltip from object
        tip.parent.y += obj.offsetHeight;

        //apply tooltip position
        tip.tooltip.style.left = tip.parent.x + 'px';
        tip.tooltip.style.top = tip.parent.y + 'px';

        //write in title attribute 
        tip.tooltip.appendChild(document.createTextNode(obj.title));

        //add to document
        document.getElementsByTagName('body')[0].appendChild(tip.tooltip);
        
   //add variable for IFrame * EB 1/25/05
     var IfrRef = document.getElementById('DivShim');

    tip.tooltip.style.display = "block";
    tip.tooltip.style.zIndex = 60000;

        //restrict width
        if(tip.tooltip.offsetWidth > 300)
        {
            tip.tooltip.style.width = '300px';
        }

        //get tooltip tip.extent
        tip.extent = {
                x : tip.tooltip.offsetWidth,
                y : tip.tooltip.offsetHeight
                };

        //if tooltip exceeds window width
        if((tip.parent.x + tip.extent.x) >= tip.window.x)
        {
            //shift tooltip left
            tip.parent.x -= tip.extent.x;
            tip.tooltip.style.left = tip.parent.x + 'px';
        }
        
        //get scroll height
        if(typeof window.pageYOffset!="undefined")
        {
            tip.scroll = window.pageYOffset;
        }
        else if(typeof document.documentElement.scrollTop!="undefined")
        {
            tip.scroll = document.documentElement.scrollTop;
        }
        else 
        {
            tip.scroll = document.body.scrollTop;
        }

        //if tooltip exceeds window height
        if((tip.parent.y + tip.extent.y) >= (tip.window.y + tip.scroll))
        {
            //shift tooltip up
            tip.parent.y -= (tip.extent.y + obj.offsetHeight + 4);
            tip.tooltip.style.top = tip.parent.y + 'px';
        }


    }

   //set variable for IFrame = Tooltip Div container * EB 1/25/05
    IfrRef.style.width = tip.tooltip.offsetWidth;
    IfrRef.style.height = tip.tooltip.offsetHeight;
    IfrRef.style.top = tip.tooltip.style.top;
    IfrRef.style.left = tip.tooltip.style.left;
    IfrRef.style.zIndex = tip.tooltip.style.zIndex - 1;
    IfrRef.style.display = "block";

}

//remove tooltip
tip.blurTip = function()
{
    //if tooltip exists
    if(tip.tooltip != null)
    {
        //remove and nullify tooltip
        document.getElementsByTagName('body')[0].removeChild(tip.tooltip);
   //hide Iframe * EB 1/25/2005
        document.getElementById('DivShim').style.display = "none";
        tip.tooltip = null;
        tip.parent = null;
    }
    
    //cancel timer
    clearInterval(tip.timer);
    tip.timer = null;
}



