var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

offsetX = 15;
offsetY = 10;

var toolTipSTYLE=null;

function initToolTips() {

  if(ns4||ns6||ie4) {

    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;

    if(ns4) document.captureEvents(Event.MOUSEMOVE);

    else {

      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";

    }

    document.onmousemove = moveToMouseLoc;

  }

}

function toolTip(msg, fg, bg) {
 if (toolTipSTYLE==null) return;

   if(toolTip.arguments.length < 1) { // hide

      if(ns4) toolTipSTYLE.visibility = "hidden";

      else {

        toolTipSTYLE.display = "none";
      }

    }

  else { // show

    if(!fg) fg = "#777777";
    if(!bg) bg = "#FFFFFF";

    var content =
    '<table style="border: 1px solid ' + fg + ';" cellspacing="0" cellpadding="0" bgcolor="' + bg + '"><tr><td>' +
    '<table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" bgcolor="' + bg +
    '"><tr><td align="center">' + msg + '</td></tr></table></td></tr></table>';

    if(ns4) {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }

    if(ns6) {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }

    if(ie4) {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }

  }

}

function moveToMouseLoc(e) {
  if(ns4||ns6) {
    x = e.pageX;
    y = e.pageY;
  }

  else {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }

  if (document.body.clientWidth - x < 90){
	  //alert(document.body.clientWidth + " " + document.all("toolTipLayer") + " " + x);
    diferencia = document.all("toolTipLayer").clientWidth; //100;
  } else {
  	diferencia = 0;
  }

  if (diferencia == 0)	{
	  toolTipSTYLE.left = x + offsetX;
	  toolTipSTYLE.top = y + offsetY;
  } else	{
	  toolTipSTYLE.left = x - diferencia - offsetX;
	  toolTipSTYLE.top = y + offsetY;
  }
  return true;

}