﻿/* Tooltips */


/*
    Copyright Robert Nyman, http://www.robertnyman.com
    Free to use if this text is included

function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return arrReturnElements;
}
*/

var ALREADY_SET = false;

function positionTip(event, tipDiv) 
{
    var scrollingPosition = getScrollingPosition();
    var cursorPosition = [0, 0];
    if (typeof event.pageX != "undefined" && typeof event.x != "undefined")
    {
        cursorPosition[0] = event.pageX;
        cursorPosition[1] = event.pageY;
    }
    else
    {
        cursorPosition[0] = event.clientX + scrollingPosition[0];
        cursorPosition[1] = event.clientY + scrollingPosition[1];
    }

    tipDiv.style.left = cursorPosition[0] + 10 + "px";
    tipDiv.style.top = cursorPosition[1] + 10 + "px";
}

function showTip(event)
{
    if(ALREADY_SET) return;

    if (typeof event == "undefined") {    event = window.event;  }

    var target = getEventTarget(event);
    var tipDiv = document.getElementById(target.id + 'ToolTip');
    if(tipDiv==null) return;
    
    tipDiv.parentNode.removeChild(tipDiv);
    document.getElementsByTagName("body")[0].appendChild(tipDiv);
    positionTip(event, tipDiv);
    tipDiv.style.display="block";
    ALREADY_SET = true;

    return true;
}

function hideTip(event)
{
    if (!ALREADY_SET) return;
    if (typeof event == "undefined") { event = window.event; }

    var target = getEventTarget(event);
    var tipDiv = document.getElementById(target.id + 'ToolTip');

    if (tipDiv != null)
    {
        tipDiv.style.display="none";
    }

    ALREADY_SET = false;

    return false;
}

function moveTip(event)
{
    if (!ALREADY_SET) return;
    if (typeof event == "undefined") { event = window.event; }

    var target = getEventTarget(event);
    var tipDiv = document.getElementById(target.id + 'ToolTip');

    if (tipDiv != null)
    {
        positionTip(event, tipDiv);
    }

    return false;
}

function getEventTarget(event)
{
  var targetElement = null;

  if (typeof event.target != "undefined")
  {
    targetElement = event.target;
  }
  else
  {
    targetElement = event.srcElement;
  }

  while (targetElement.nodeType == 3 && targetElement.parentNode != null)
  {
    targetElement = targetElement.parentNode;
  }

  return targetElement;
}

function getScrollingPosition()
{
  //array for X and Y scroll position
  var position = [0, 0];

  //if the window.pageYOffset property is supported
  if(typeof window.pageYOffset != 'undefined')
  {
    //store position values
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  //if the documentElement.scrollTop property is supported
  //and the value is greater than zero
  if(typeof document.documentElement.scrollTop != 'undefined'
    && document.documentElement.scrollTop > 0)
  {
    //store position values
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  //if the body.scrollTop property is supported
  else if(typeof document.body.scrollTop != 'undefined')
  {
    //store position values
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  //return the array
  return position;
}


