//******************************************************************************/
//*                                                                            */
//*         Internet Computer Software - Java Script library.                  */
//*                                                                            */
//*         Program:                     PopupNote.                            */
//*         Programmer :                 John  S.  Parry.                      */
//*         Date :                       October 2008.                         */
//*         Language :                   JavaScript.                           */
//*                                                                            */
//*         Copyright (C) 2008,   Internet Computer Software Pty Ltd.          */
//*                               PO Box 279                                   */
//*                               Sandy Bay  7006                              */
//*                               Tasmania  Australia                          */
//*                                                                            */
//******************************************************************************/
//*                                                                            */
//* This software is distributed under a shareware license, you are free to    */
//* distribute this software without obtaining a license to use                */
//*                                                                            */
//*                                                                            */
//******************************************************************************/
//*                                                                            */
//* This file contains the javascript functions to display pop up notes.       */
//*                                                                            */
//* To use the pop up notes define each text and note as follows,              */
//*   <A href='ref' class='PopupNote' Title='html note text'>text</A>          */
//* where 'ref' is the html link if the text is clicked, use '#' as default    */
//*   'text' is the information seen on the screen                             */
//*   and 'html note text' is the information displayed when the mouse moves   */
//*          over the text.                                                    */
//*                                                                            */
//* After you have defined all information with attached pop up notes you      */
//* must include the following lines in your web page, (usually just before    */
//* the </Body> tag.                                                           */
//*   <Script Language='JavaScript' Name='JS/PopupNote.inc'></Script>          */
//* You should note that any notes defined in your html after the above line   */
//* will not be displayed.                                                     */
//*                                                                            */
//******************************************************************************/
//*                                                                            */
//* The following variables which may be specified in the site configuation    */
//* file, config.inc are used by this routine.                                 */
//*                                                                            */
//* PopupNoteUpArrow is the name of the uparrow image file.                    */
//* PopupNoteDownArrow is the name of the downarrow image file.                */
//* PopupNoteNoteOffX is the X offset from the current mouse position to the   */
//*   top left corner of the text box.                                         */
//* PopupNoteNoteOffY is the Y offset from the current mouse position to the   */
//*   top left corner of the text box.                                         */
//* PopupNoteArrowOffX is the X offset from the current mouse position to the  */
//*   top left corner of the up arrow.                                         */
//* PopupNoteArrowOffY is the Y offset from the current mouse position to the  */
//*   top left corner of the up arrow.                                         */
//* PopupNoteAboveOffset                           */
//*                                                                            */
//******************************************************************************/

  var PopupNoteUpArrow     = "UpArrow.gif" ;
  var PopupNoteDownArrow   = "DownArrow.gif" ;
  var PopupNoteTextOffX    = -30 ;
  var PopupNoteTextOffY    = 32 ;
  var PopupNoteArrowOffX   = -7 ;
  var PopupNoteArrowOffY   = 20 ;
  var PopupNoteAboveOffset = 16 ;

  var PopupNoteObj ;
  var UpArrowObj ;
  var DownArrowObj ;
  var EnablePopup = false ;

  document.write( "<Div Id='PopupNote' Class='PopupBox'>" ) ;
  document.write( "</Div>" );
  document.write( "<Img Id='PopupNoteUpArrow' src='" + PopupNoteUpArrow + "'>" ) ;
  document.write( "<Img Id='PopupNoteDownArrow' src='" + PopupNoteDownArrow + "'>" ) ;

  if ( document.all )
    { PopupNoteObj = document.all[ 'PopupNote' ] ;
      UpArrowObj   = document.all[ 'PopupNoteUpArrow' ] ;
      DownArrowObj = document.all[ 'PopupNoteDownArrow' ] ;
    }
  else
    { PopupNoteObj = document.getElementById( 'PopupNote' ) ;
      UpArrowObj   = document.getElementById( 'PopupNoteUpArrow' ) ;
      DownArrowObj = document.getElementById( 'PopupNoteDownArrow' ) ;
    }

  function ConvertPopupNotes()
    {
      var AllAlinks ;
      var Note ;
      var loop ;

      AllAlinks = document.getElementsByTagName( 'a' ) ;
      if ( ! AllAlinks )
        { return ; }
      for ( loop = 0; loop < AllAlinks.length; loop++ )
        { if ( AllAlinks[ loop ].className == 'PopupNote' )
            { Note = AllAlinks[ loop ].title ;
              AllAlinks[ loop ].setAttribute ( 'PopupNote', Note ) ;
              AllAlinks[ loop ].removeAttribute( 'title' ) ;
              AllAlinks[ loop ].onmouseover = function display() { DisplayNote ( this.getAttribute ( 'PopupNote' )) } ;
              AllAlinks[ loop ].onmouseout  = function hide() { HideNote () } ;
            }
        }
       HideNote () ;
    }

  function DocumentBody()
    {
      return (( document.compatMode && document.compatMode != 'BackCompat' ) ? document.documentElement : document.body ) ;
    }

  function DisplayNote ( Text )
    {
      if ( document.getElementById || document.all )
        { PopupNoteObj.innerHTML = Text ;
          EnablePopup = true ;
          return ( false ) ;
        }
    }

  function HideNote ()
    {
      if ( document.getElementById || document.all )
        { EnablePopup = false ;
          PopupNoteObj.style.position   = 'Absolute' ;
          UpArrowObj.style.position     = 'Absolute' ;
          DownArrowObj.style.position   = 'Absolute' ;
          PopupNoteObj.style.visibility = 'hidden' ;
          UpArrowObj.style.visibility   = 'hidden' ;
          DownArrowObj.style.visibility = 'hidden' ;
        }
    }

  function PositionNote ( Evt )
    {
      var NS6 = document.getElementById && ! document.all ;

      if ( EnablePopup )
        { var HideArrow = false ;
          var UseUpArrow = true ;
                                                                          //* Work out new position of box and arrow
          var CurrentX  = (NS6) ? Evt.pageX : event.clientX + DocumentBody().scrollLeft ;
          var CurrentY  = (NS6) ? Evt.pageY : event.clientY + DocumentBody().scrollTop ;
          var NewBoxX   = CurrentX + PopupNoteTextOffX ;
          var NewBoxY   = CurrentY + PopupNoteTextOffY ;
          var NewArrowX = CurrentX + PopupNoteArrowOffX ;
          var NewArrowY = CurrentY + PopupNoteArrowOffY ;
          var WinSize   = GetWindowSize( ) ;
                                                                          //* Make sure that the horizontal position of the box is within the window
          var TextWidth  = PopupNoteObj.offsetWidth ;
          var ArrowWidth = UpArrowObj.offsetWidth ;
          if ( NewBoxX + TextWidth > WinSize[ 2 ] )
            { NewBoxX = WinSize[ 2 ] - TextWidth ; }
          if ( NewBoxX < WinSize[ 0 ] )
            { NewBoxX = WinSize[ 0 ] ; }
          if ( NewArrowX + ArrowWidth > WinSize[ 2 ] )
            { NewArrowX = WinSize[ 2 ] - ArrowWidth ; }
          if ( NewArrowX < WinSize[ 0 ] )
            { NewArrowX = WinSize[ 0 ] ; }
                                                                          //* Make sure that the vertical position of the box is within the window
          var TextHeight = PopupNoteObj.offsetHeight ;
          var ArrowHeight = UpArrowObj.offsetHeight ;
          if ( NewBoxY + TextHeight > WinSize[ 3 ] )
            { NewBoxY = CurrentY - PopupNoteTextOffY + PopupNoteAboveOffset - TextHeight ;
              NewArrowY = CurrentY - PopupNoteArrowOffY + PopupNoteAboveOffset - ArrowHeight ;
              UseUpArrow = false ;
            }
                                                                          //* Move the pop up box and arrow
          PopupNoteObj.style.top  = NewBoxY + 'px' ;
          PopupNoteObj.style.left = NewBoxX + 'px' ;
          UpArrowObj.style.top    = NewArrowY + 'px' ;
          UpArrowObj.style.left   = NewArrowX + 'px' ;
          DownArrowObj.style.top  = NewArrowY + 'px' ;
          DownArrowObj.style.left = NewArrowX + 'px' ;
                                                                          //* Make the pop up box and appropriate arrow visible
          PopupNoteObj.style.visibility = 'visible' ;
          if ( ! HideArrow )
            { if ( UseUpArrow )
                { UpArrowObj.style.visibility = 'visible' ;
                  DownArrowObj.style.visibility = 'hidden' ;
                }
              else
                { UpArrowObj.style.visibility = 'hidden' ;
                  DownArrowObj.style.visibility = 'visible' ;
                }
            }
          else
            { UpArrowObj.style.visibility = 'hidden' ;
              DownArrowObj.style.visibility = 'hidden' ;
            }
        }
    }
                                                                          //* Move the popup box with the mouse
  document.onmousemove = PositionNote ;
                                                                          //* Identify all A tags of class PopupNote as using this code
  ConvertPopupNotes() ;
