// JavaScripts for PopUp Feature

//Global Variables
var oldContent;
var onScreen = null;
var w;

function onLoad() {
  //Create container for IE
  if (document.all) {
    document.writeln('<DIV ID="popupContainer" STYLE="position:absolute;visibility:hidden"></DIV>');
    container = document.all["popupContainer"];
    container.onclick = hidePopUp;
    container.onmouseover = keepPopUp;
  }
}

function doPopUp(content,e) {

  //If PopUp is visible and this is the same term, ignore.
  if ((onScreen) && (content == oldContent)) {
    if (document.all) {
      window.event.cancelBubble = true;
    }
    return;
  }

  //If PopUp is visible, hide it.
  if (onScreen) hidePopUp();

  //Create the PopUp
  setContents(content);

  //Set the PopUp location based on mouse location
  setLocation(content,e);

  //Display the PopUp
  showPopUp(); 
  mouseTracker(); 
}


function setContents(content) {
  oldContent = content;

  //Calculate width of popup
  if (document.layers) {
    if (content.length < 300) {
      w = Math.round(window.innerWidth * .4)
    } else { 
      w = Math.round(window.innerWidth * .5)
    }
  } else {
    if (content.length < 300) {
      w = Math.round(document.body.clientWidth * .4)
    } else {
      w = Math.round(document.body.clientWidth * .5)
    }
  }

  //Create container (layer) for Netscape
  if (document.layers) {
    document.container = new Layer(w);
    document.container.captureEvents(Event.MOUSEOUT);
    document.container.onmouseout = hidePopUp;
  }

  //Create contents
  PopUpText = "<DIV ID=\"PopUp\" "
  PopUpText += "style=\""
  PopUpText += "font-family:arial,verdana,helvetica\; "
  PopUpText += "visibility:inherit\; "
  PopUpText += "background-color:#ccccff\; "
  PopUpText += "padding:7\; "
  PopUpText += "position:absolute\; "
  PopUpText += "width:" + w + "\; "
  if (document.layers) {
    PopUpText += "font-size:small\; "
    PopUpText += "border-width:2px\; "
    PopUpText += "border-color: silver\; "
    PopUpText += "border-style:outset\; "
  } else {
    PopUpText += "font-size:x-small\; "
    PopUpText += "border-bottom: silver outset 2px \; "
    PopUpText += "border-top: white outset 2px \; "
    PopUpText += "border-left: white outset 2px \; "
    PopUpText += "border-right: silver outset 2px \; "
  }
  PopUpText += "\">\n"  //Close STYLE definition
  PopUpText += content;
  PopUpText += "\n</div>";

  //Write contents to container
  if (document.all) {
    container.innerHTML=PopUpText;
  } else {
    document.container.document.open("text/html");
    document.container.document.writeln(PopUpText);
    document.container.document.close();
  }
}


function setLocation(content,e) {
  if (document.layers) {
    if (e.pageX > (window.innerWidth / 2)) {
      x = e.pageX - w
    } else {
      x = e.pageX
    }
    y = e.pageY - 3
    document.container.moveTo(x, y)
  } else {
    if (e.clientX > (document.body.clientWidth / 2)) {
      x = e.clientX - w 
    } else {
      x = e.clientX
    }
    y = e.clientY + document.body.scrollTop
    container.style.pixelWidth = w
    container.style.pixelLeft = x
    container.style.pixelTop = y
  }
}

function showPopUp() {
  if (document.layers) {
    document.container.visibility = "visible";
  } else {
    container.style.visibility = "visible"
    window.event.cancelBubble = true;
  }
  onScreen = 1;
}

function hidePopUp(e) {
  if (document.layers) {
    document.container.visibility = "hidden";
  } else {
    container.style.visibility = "hidden"
    window.event.cancelBubble = true;
    document.onmouseover = "";
  }
  onScreen = null; 
}

function mouseTracker() {
  if (document.captureEvents) {
    document.captureEvents(Event.CLICK);
  }
  document.onclick = hidePopUp;
  if (document.captureEvents) {
    document.releaseEvents(Event.CLICK);
  }
}

function handleResize() {
  location.reload();
  return false;
}

if (navigator.appname == "Netscape") {
  window.captureEvents(Event.RESIZE);
  window.onresize = handleResize;
}

function keepPopUp() {
  if (document.all) {
    window.event.cancelBubble = true;
    document.onmouseover = hidePopUp;
  }
}

