/*  Your are permitted to reuse this code as long as the following copyright
    notice is not removed:

    The HTML tip handling code is copyright 1998 by insideDHTML.com, LLC. More information about this
    code can be found at Inside Dynamic HTML: HTTP://www.insideDHTML.com
*/

var tipped = null;

function setupEventObject(e) {
  // Map NS event object to IEs
  if (e==null) return // IE returns
  window.event = e
  window.event.fromElement = e.target
  window.event.toElement = e.target
  window.event.srcElement = e.target
  window.event.x = e.x
  window.event.y = e.y
}


function checkName(src) {
  // Look for tooltip in IE
  while ((src!=null) && (src.getAttribute("tip")==null))
    src = src.parentElement
  return src
}

function writeContents(el, tip) {
  // Replace the contents of the tooltip
  el.innerHTML = tip
}

function getOffset(el, which) {
  // Function for IE to calculate position 
  // of an element.
  var amount = el["offset"+which] 
  if (which=="Top")
    amount+=el.offsetHeight
  el = el.offsetParent
  while (el!=null) {
    amount+=el["offset"+which]
    el = el.offsetParent
  }
  return amount
}


function setPosition(el) {
  // Set the position of an element
  src = window.event.srcElement
  el.style.pixelTop = getOffset(src, "Top")
  el.style.pixelLeft = getOffset(src, "Left")
}

function setVisibility(el, bDisplay) {
  // Hide or show to tip
  if (bDisplay)
    el.style.visibility = "visible" 
  else
    el.style.visibility = "hidden"
}


function displayContents(tip) {
  // Display the tooltip. 
  var el = document.getElementById("tipBox");
  if (null==el) return;

  writeContents(el, tip)
  setPosition(el)
  setVisibility(el, true);
}

function hideContents() {
  // Hides the tooltip
  var el = document.getElementById("tipBox");
  if (null==el) return;

  setVisibility(el, false);

}


function doMouseOver(e) {
  // Mouse moves over an element
  setupEventObject(e)
  var el;
  el = checkName(window.event.srcElement)
  if (el!=null) {
    if (!tipped) {
      displayContents(el.getAttribute("tip"));
      tipped = el;
    }
  }
}

function doMouseOut(e) {
  // Mouse leaves an element
  setupEventObject(e)
  
  if (tipped) {
    hideContents();
    tipped = null;
  }
}

function doKeyDown(e) {
  doMouseOut(e);
}

function doLoad() {
  var docBody = document.getElementsByTagName("body").item(0);
  var tipBox = document.createElement("div");
  var tipText = document.createTextNode("");
  tipBox.appendChild(tipText);
  tipBox.id = "tipBox";
  docBody.appendChild(tipBox);

  var el = document.getElementById("tipBox");
  el.style.pixelTop=0;
  setVisibility(el, true);
  setVisibility(el, false);

  // Do Loading
  window.document.onmouseover = doMouseOver;
  window.document.onmouseout = doMouseOut;
  window.document.onkeydown = doKeyDown;

  if (null!= tooltip_backup_onload) {
    tooltip_backup_onload();
  }
}
var tooltip_backup_onload = window.onload;
window.onload = doLoad;
