// This JavaScript script file is used to display some tool tip text over a page link.
// This code is better than the A HREF title='' because you can include HTML tags in the tool tip display.
// By; Mark A. Agius, (c) 13/09/2009 -  9:30pm bst (Email; MarkAgius@markagius.co.uk)
// '   '  ' '  '   '  '   14/09/2009
// Code version; 0.02

/*
  To use this code add the following below the BODY tag and above your first page link.
  <SCRIPT language="JavaScript" src='TooltipText.js'></SCRIPT>

  Then add the following into your page links.
  onMouseover="TTText('tooltip_','Tooltip message','Tooltip title', 'Message BG colour', 'Title BG colour');" onMouseout="TTTextOff();"
  Eg.
  <A HREF="NewPage.htm"  onMouseover="TTText('tooltip_','The new page.<BR>Click here to load it.');" onMouseout="TTTextOff();">Load new page</A>
  or
  <A HREF="NewPage.htm"  onMouseover="TTText('tooltip_','The new page.','A page link.');" onMouseout="TTTextOff();">Load new page</A>
  

  This code works with the following browsers;
    Internet Explorer             Yes
    Netscape Communicator (4.6)   No yet working
    Netscape (7.1)                No yet working
    Netscape Navigator (9.0)      Yes
    32bit Web Browser             Yes
    AOL                           Yes
    Apple Safari                  Yes
    Google Chrome                 Yes
    Mozilla Firefox               Yes
    NeoPlanet                     Yes
    Opera (8.01) IE/Mozilla/Opera Yes
    Opera (9.02) IE/Firefox/Opera Yes
    SeaMonkey                     Yes
    Visual Explorer               Yes
    WebWindow                     Yes

*/

  var displayTooltipText = false;
  var Ex = 0; Ey = 0;
  // var ie = document.all    ?1:0;
  // var ns = document.layers ?1:0;
  var ie = isInternetExplorer();
  var ns = isNetscape();

  this.document.write("<DIV ID=\"tooltip_div\" STYLE=\"position:absolute; z-index:4; visibility:hidden;\">\n");
  this.document.write("<LAYER ID=\"tooltip_layer\">\n");
  this.document.write("</LAYER>\n");
  this.document.write("</DIV>\n");

  document.body.onmousemove = MoveDivHere;


// The functions start here. //
function isInternetExplorer(){
  // This function will return true if this browser supports DIVs. (E.g. Microsoft Internet Explorer)
  return document.all?true:false;
}
function isNetscape(){
  // This function will return true if this browser supports layers. (E.g. Netscape)
  // The next line will only work with versions of Netscape from version 0.01 to version 4.60.
  return document.layers?true:false;
  // The next line will work with Netscape from version 0.01 to version 9.00
  // (See if 'Netscape' is in navigator.appName)
  // if(navigator.appName.indexOf("Netscape")<0){
  //   return false;
  // } else {
  //   return true;
  // }
}
function MoveDivHere(e){
  // The mouse pointer has moved, so read the position and move the div their.
  if(displayTooltipText){
    if(ie)        {Ex = event.x + this.document.body.scrollLeft; Ey = event.y + this.document.body.scrollTop;};
    if(ns)        {Ex = e.pageX; Ey = e.pageY;};
    if(!ie && !ns){Ex = e.pageX; Ey = e.pageY;};
    Ex = Ex-18;
    Ey = Ey+16;
    MoveDiv("tooltip_", Ex, Ey);
    tooltip_div.style.visibility = 'visible';
  } else {
    MoveDiv("tooltip_",0, 0);
    tooltip_div.style.visibility = 'hidden';
  }
}
function TTText(divName, TMessage, TTitle, BodyBG, TitleBG){
  // Setup the div or layer text.
  if(TTitle  ==undefined) {TTitle  =""};
  if(TMessage==undefined) {TMessage=""};
  if(TitleBG ==undefined) {TitleBG ="#7D92A9"};
  if(BodyBG  ==undefined) {BodyBG  ="#FFFFDF"};
  var NewDivCode = "<TABLE BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n";
  if(TTitle!=""){
    NewDivCode = NewDivCode+"<TR><TD BGCOLOR=\""+TitleBG+"\"><FONT FACE=\"Arial\" COLOR=\"#FFFFFF\" STYLE=\"FONT-SIZE:8pt;\"><B>&nbsp;"+TTitle+"&nbsp;</B></FONT></TD></TR>\n";
  }
  if(TMessage!=""){
    NewDivCode = NewDivCode+"<TR><TD BGCOLOR=\""+BodyBG+"\"><FONT FACE=\"Arial\" COLOR=\"#000000\" STYLE=\"FONT-SIZE:8pt;\">&nbsp;"+TMessage+"&nbsp;</FONT></TD></TR>\n";
  }
  if(TTitle+TMessage==""){
    NewDivCode = NewDivCode+"<TR><TD BGCOLOR=\"#7F0000\"><FONT FACE=\"Arial\" COLOR=\"FFFFFF\" STYLE=\"FONT-SIZE:8pt;\"><B>&nbsp;TTText() error.&nbsp;</B><BR>&nbsp;<SMALL><I>Tooltip text error.</I></SMALL>&nbsp;</FONT></TD></TR>\n";
  }
  NewDivCode = NewDivCode+"</TABLE>\n";

  if(ie){
    document.all[divName+"div"].innerHTML = NewDivCode;
  }
  if(ns){
    document.layers[divName+"layer"].document.write(NewDivCode);
    document.layers[divName+"layer"].document.close();
    // document.all[divName+"div"].innerHTML = NewDivCode;
  }
  if(!ie && !ns){
    document.all[divName+"div"].innerHTML = NewDivCode;
  }
 // Set the displayTooltipText flag to true to display the div.
  displayTooltipText=true;
}
function MoveDiv(divName, PosX, PosY){
  // Move the div or layer to PosX, PosY.
  if(ie){
    // Internet Explorer or IE clone.
    document.all[divName+"div"].style.zIndex    = 1;
    document.all[divName+"div"].style.position  = "absolute";
    document.all[divName+"div"].style.pixelLeft = PosX;
    document.all[divName+"div"].style.pixelTop  = PosY;
  }
  if(ns){
    // Old version of Netscape Communicator (4.6 or before)
    document.layers[divName+"layer"].zIndex   = 1;
    document.layers[divName+"layer"].position = "absolute";
    document.layers[divName+"layer"].left = PosX;
    document.layers[divName+"layer"].top  = PosY;
    // document.all[divName+"div"].style.zIndex    = 1;
    // document.all[divName+"div"].style.position  = "absolute";
    // document.all[divName+"div"].style.pixelLeft = PosX;
    // document.all[divName+"div"].style.pixelTop  = PosY;
  }
  if(!ie && !ns){
    // New version of Netscape Navigator (7.1 or after) or NS clone.
    document.all[divName+"div"].style.zIndex    = 1;
    document.all[divName+"div"].style.position  = "absolute";
    document.all[divName+"div"].style.left = PosX;
    document.all[divName+"div"].style.top  = PosY;
  }
}

// function TTTextOn(){
//   // Display the div.
//   displayTooltipText=true;
// }
function TTTextOff(){
 // Hide the div.
  displayTooltipText=false;
}
// -- end of file -- //