function tooltip(elem) {

  // elem = a reference to the element (in this case an <a>) that fired the event handler;
 
  if (!document.getElementById) return false;
  if (!document.getElementsByTagName) return false;

  //make sure that any div#tooltip element node that was previously created is destroyed;
  if (document.getElementById("tooltip")) {
    document.getElementsByTagName("body")[0].removeChild(document.getElementById("tooltip"));
  }

  //extract first the tooltip\d class name and then just the class number(\d);
  //remember there may be more than one class;
  if (elem.getAttribute("class")) { //modern browsers;
    var classes = elem.getAttribute("class");
  } else if (elem.className) { //IE;
    var classes = elem.className;
  }
 
  var pattern = /\btooltip\d+\b/; //will match tooltip0, tooltip22, tooltip538, etc.;
  if (classes.match(pattern)) { //now extract the exact class name we're looking for;
    var myClass = classes.replace(classes, classes.match(pattern));
    var myClassNumber = myClass.replace(myClass, myClass.match(/\B\d+\b/)); //now extract just the digit(s) from the class;
  }

  //create the div#tooltip element node;
  var tipDiv = document.createElement("div");
  tipDiv.setAttribute("id", "tooltip");

  //create the div#tooltip a.tooltipClose node;
  var close = document.createElement("a");
  close.appendChild(document.createTextNode("Close"));
  close.setAttribute("href", "#");
  close.setAttribute("class", "tooltipClose");
  close.setAttribute("onfocus", "if(this.blur)this.blur();");
  close.setAttribute("onclick", "document.getElementById('tooltip').style.display = 'none'; return false;");
 
  tipDiv.appendChild(close); //append a.tooltipClose to div#tooltip;
  document.getElementsByTagName("body")[0].appendChild(tipDiv); //append div#tooltip to the document;
  tipDiv.innerHTML += toolbox(myClassNumber); //grab the selected Tooltip from the Toolbox;
  
  //get the x/y coordinates of our node element;
  var coords = new Array();
  coords = findPosition(elem);
  var positionX = coords[0];
  var positionY = coords[1];

  //position the div, and then finally display it;
  if (document.all) { //works in all but it's offset in Windows strict, Mozilla 1.6 strict and Safari;
	if ( (document.body.clientWidth - positionX) > 250 ) { //if the viewport won't allow for the tooltip to be fully displayed to the right of the element then position it to the left;
	  tipDiv.style.left = positionX + "px"; //x coord;
      tipDiv.style.top = positionY + "px"; //y coord;
	} else {
	  tipDiv.style.left = (positionX - 250) + "px";
	  tipDiv.style.top = (positionY) + "px";
	}
	
  } else { //works in all but Opera and Windows quirks mode;
	if ( (document.body.offsetWidth - positionX) > 250 ) { //if the viewport won't allow for the tooltip to be fully displayed to the right of the element then position it to the left;
	  tipDiv.style.left = positionX + "px"; //x coord;
      tipDiv.style.top = positionY + "px"; //y coord;
	} else {
	  tipDiv.style.left = (positionX - 250) + "px";
	  tipDiv.style.top = (positionY) + "px";
	}
  }
  tipDiv.style.display = "block";

}

function findPosition(obj) {
  var x = y = 0;
  if (obj.offsetParent) {
    x = obj.offsetLeft
    y = obj.offsetTop
    while (obj = obj.offsetParent) {
      x += obj.offsetLeft
      y += obj.offsetTop
    }
  }
  return [x, y];
}

function toolbox(which) {

  // which = the Tooltip Number (etc. tooltip0, tooltip31) which was extracted from the class name and that corresponds to an index of the array below;

  var tip = new Array();
  tip[1] = "<p class=\"firstPara\"><p>You will be prompted for your password after you enter your username and click \"Sign In.\"</p>";
  tip[2] = "<p class=\"firstPara\">If you have forgotten your password you can reset it by:</p><ul><li>Entering your Username above and click \"Sign In\"</li><li>On the screen where you are asked to enter your Password, click the \"Forgot your Password?\" link</li><li>Next, you will be asked to enter your information and we will send you a temporary password</li>";

  return tip[which];

}
