/**
 * JavaScript Tooltips
 * @author Brent Knop [CeB] <bknop@bcbsm.com>
 * @version 1.1
 *
 * @ Revisions ------------------------------------------------------------
 *    Fixed title element from showing up by adding code to 
 *    remove title from DOM onmouseover, then replace it 
 *    onmouseout.  - bk, 9.10.07
 * ----------------------------------------------------------------------------
 *
 * shows tooltips popups on mouseover - calculates position so as not to
 * allow page scrolling, on account of the popup tooltip
 *
 * GLOBAL VARIABLE          DESCRIPTION
 *  TOOLTIP_ELEM            ID of tooltip DIV
 *
 * FUNCTION                 DESCRIPTION
 * ----------------------------------------------------------------------------
 * tooltip()                determines which supporting funcs to call, based on evt
 *   @param  evt            event triggering function
 *   @param  txt            text to display in tooltip DIV
 *   @return void
 *
 * tippos()                 calculates tooltip position, based on window size,
 *                          current mouse position, and size of the tooltip DIV
 *   @param  evt            event triggering function
 *   @param  elem           tooltip DIV (TOOLTIP_ELEM)
 *   @return void
 *
 * toggleCSSProperty()      changes CSS property for specified element
 *   @param  id             ID of elem whose property we want to change
 *   @param  property       CSS property name to change
 *   @param  value          new value to assign to CSS property
 *   @return void 
 */

TOOLTIP_ELEM = "tooltip";
TEXT = "";

function tooltip(evt, obj)
{
  if(document.getElementById(TOOLTIP_ELEM))
  {
    var elem = document.getElementById(TOOLTIP_ELEM);
    evt = (!evt) ? window.event: evt;
    if (obj.title) TEXT = obj.title;
    switch(evt.type)
    {
      case "mouseover" :        
        elem.innerHTML = TEXT;        
        tippos(evt, elem);
        obj.title = "";
        //obj.removeAttribute("title");
        toggleCSSProperty(elem, "display", "block");
      break;
      case "mousemove" :
        tippos(evt, elem);
      break;
      case "mouseout" :        
        toggleCSSProperty(elem, "display", "none");
        obj.setAttribute("title", TEXT);
      break;            
    }   
  }
}

function tippos(evt, elem)
{ 
  var sw = document.documentElement.clientWidth;
  var sh = document.documentElement.clientHeight;
  var width = elem.offsetWidth;
  var height = elem.offsetHeight;
  var mouseX, mouseY, x, y;
  if(evt.pageX && evt.pageY)
  {
    mouseX = evt.pageX;
    mouseY = evt.pageY;
    x = (evt.pageX); 
    y = 10 + evt.pageY;    
  }
  else
  {
    mouseX = evt.clientX;
    mouseY = evt.clientY;
    x = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; 
    y = 10 + evt.clientY + document.body.scrollTop + document.documentElement.scrollTop; 
  }
  if (width > (sw - mouseX)) x = sw - (width + 10);
  if (sh < (mouseY + height + 10)) y = mouseY - (height + 10);
  toggleCSSProperty(elem, "left", x + "px");
  toggleCSSProperty(elem, "top", y + "px");  
}

function toggleCSSProperty(id, property, value)
{
  if(document.getElementById(id))
  {
   var str = "document.getElementById('" + id + "').style." + property + "='" + value + "';";
  }
  else
  {
   var str = "id.style." + property + "='" + value + "';";
  }
  eval(str);
}