//  Note: Must include menu.js in page before including this script.
//  01/01/2001 njc included /abfglobal/include/menu.js code into freightvalue/include/allinclude.js
////////////////////////////////////////////////////////////////////////////////////
//  overLIB 2.22  --  Please leave this notice.
//
//  By Erik Bosrup (erik@bosrup.com)  Last modified 1999-03-31
//  Portions by Dan Steinman, Landon Bradshaw and Gnowknayme.
//
//  Get the latest version at http://www.bosrup.com/web/overlib/
//
//  This script library was created for my personal usage from the start
//  but then it became so popular I made an easy to use version. It's that
//  version you're using now. Since this is free please don't try to sell
//  this solution to a company claiming it is yours. Give me credit where
//  credit is due and I'll be happy. And I'd love to see any changes you've
//  done to the code. Free to use - don't abuse.
////////////////////////////////////////////////////////////////////////////////////

// Init main vars:

if (typeof fcolor == 'undefined')     { var fcolor = "#CCCCFF" }
if (typeof backcolor == 'undefined')  { var backcolor = "#333399" }
if (typeof textcolor == 'undefined')  { var textcolor = "#000000" }
if (typeof capcolor == 'undefined')   { var capcolor = "#FFFFFF" }
if (typeof closecolor == 'undefined') { var closecolor = "#9999FF" }
if (typeof width == 'undefined')      { var width = "150" }
if (typeof border == 'undefined')     { var border = "1" }
if (typeof offsetx == 'undefined')    { var offsetx = 10 }
if (typeof offsety == 'undefined')    { var offsety = 10 }

var x = 0
var y = 0
var snow = 0
var sw = 0
var cnt = 0
var dir = 1
var tr = 1
var yBefore = 0
var xBefore = 0

if ( (ns4) || (ie4) || (ns6)) {
   if (ns4) over = document.overDiv
   if (ie4) over = overDiv.style
   if (ns6) over = document.getElementById('overDiv')
   
   document.onmousemove = mouseMove
   if (ns4) document.captureEvents(Event.MOUSEMOVE)
}

// Display popup:
// xOver - set x coordinate (0 for default)
// yOver - set y coordinate (0 for default)
// xOff  - x offset (0 for default)
// yOff  - y offset (0 for default)
// wOver - width (0 for default)
// pos   - position ('' default, 'l' left, 'r' right, 'c' center, 'p' positional)
// stick - stay up until closed, title required
// ti    - timeout in # of seconds (0 for no timeout)
// text  - message text
// title - caption title ('' no caption)
function pop(xOver, yOver, xOff, yOff, wOver, pos, stick, ti, text, title) {
        text = "<FONT CLASS=\"txtPg\">" + text + "</FONT>"
        var xHd     = x
        var yHd     = y
        var xOffHd  = offsetx
        var yOffHd  = offsety
        var widthHd = width

   yBefore = y
   xBefore = x

        if (xOver != 0) { x = xOver }
        if (yOver != 0) { y = yOver }
        if (xOff != 0)  { offsetx = xOff }
        if (yOff != 0)  { offsety = yOff }
        if (wOver != 0) { width = wOver }

        // this code is used in Shipment Planner, but can be used for any application
        // where the popup should be displayed based on the mouse location.
        // Note: intWAw is the width of the work area.
        if (pos == 'p') {
          if (parseInt(x) + parseInt(offsetx) + parseInt(width) <= intWAw) {
            pos = 'r'
          }
          else if (parseInt(x) + parseInt(offsetx) + parseInt(width) > intWAw) {
            pos = 'l'
          }
          else {
            pos = ''
          }
        }

        // Simple popup
        if (title == '') {
          if (pos == '')  { dts(1,text) }
          if (pos == 'l') { dts(0,text) }
          if (pos == 'r') { dts(1,text) }
          if (pos == 'c') { dts(2,text) }
        }
        // Caption popup
        else {
          // Sticky caption
          if (stick) {
            if (pos == '')  { stc(1,text,title) }
            if (pos == 'l') { stc(0,text,title) }
            if (pos == 'r') { stc(1,text,title) }
            if (pos == 'c') { stc(2,text,title) }
          }
          // Normal caption
          else {
            if (pos == '')  { dtc(1,text,title) }
            if (pos == 'l') { dtc(0,text,title) }
            if (pos == 'r') { dtc(1,text,title) }
            if (pos == 'c') { dtc(2,text,title) }
          }
        }

   x = xHd
   y = yHd
   offsetx = xOffHd
   offsety = yOffHd
   width = widthHd

   if (ti > 0) { window.setTimeout("nd()",ti*1000) }
}

// Clears popups if appropriate
function nd() {
   // this put in because of a bug in ie4
   if ((yBefore == y) && (xBefore == x) && ((ie4) || (ns6)) && (!ie5)) {
      return
   }
   if ( cnt >= 1 ) { sw = 0 }
   if ( (ns4) || (ie4) || (ns6) ) {
      if ( sw == 0 ) {
         snow = 0
         hideObject(over)
      } else {
         cnt++
      }
   }
}

// Non public functions. These are called by other functions etc.

// Simple popup
function dts(d,text) {
   txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT CLASS=\"winHpTxt\" COLOR=\""+textcolor+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
   layerWrite(txt)
   dir = d
   disp()
   snow = 0
}

// Caption popup
function dtc(d,text, title) {
   txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><FONT CLASS=\"winHpTxt\" COLOR=\""+capcolor+"\">"+title+"</FONT></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT CLASS=\"winHpTxt\" COLOR=\""+textcolor+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
   layerWrite(txt)
   dir = d
   disp()
   snow = 0
}

// Sticky
function stc(d,text, title) {
   sw = 1
   cnt = 0
   txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT CLASS=\"winHpTxt\" COLOR=\""+capcolor+"\">"+title+"</FONT></B></SPAN></TD><TD ALIGN=RIGHT><A HREF=\"/\" onMouseOver=\"cClick()\" ID=\"PCL\"><FONT CLASS=\"winHpTxt\" COLOR=\""+closecolor+"\">Close</FONT></A></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT CLASS=\"winHpTxt\" COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
   layerWrite(txt)
   dir = d
   disp()
   snow = 0
}

// Common calls
function disp() {
   if ( (ns4) || (ie4) || (ns6) ) {
      if (snow == 0)    {
         if (dir == 2) { // Center
            moveTo(over,x+offsetx-(width/2),y+offsety)
         }
         if (dir == 1) { // Right
            moveTo(over,x+offsetx,y+offsety)
         }
         if (dir == 0) { // Left
            moveTo(over,x-offsetx-width,y+offsety)
         }
         showObject(over)
         snow = 1
      }
   }
// Here you can make the text goto the statusbar.
}

// Moves the layer
function mouseMove(e) {
   if ((ns4) || (ns6)) {x=e.pageX; y=e.pageY}
   if (ie4) {x=event.clientX; y=event.y}
   if (ie5) {x=event.clientX+document.body.scrollLeft; y=event.clientY+document.body.scrollTop}
   if (snow) {
      if (dir == 2) { // Center
         moveTo(over,x+offsetx-(width/2),y+offsety)
      }
      if (dir == 1) { // Right
         moveTo(over,x+offsetx,y+offsety)
      }
      if (dir == 0) { // Left
         moveTo(over,x-offsetx-width,y+offsety)
      }
   }
}

// The Close onMouseOver function for Sticky
function cClick() {
   hideObject(over)
   sw=0
}

// Writes to a layer
function layerWrite(txt) {
   if (ns4) {
      var lyr = document.overDiv.document
      lyr.write(txt)
      lyr.close()
   }
   else if (ie4) document.all["overDiv"].innerHTML = txt
   else if (ns6) {
      range = document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
		   over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
   }
}



// Make an object visible
function showObject(obj) {
        if (ns4) obj.visibility = "show"
        else if (ie4) obj.visibility = "visible"
        else if (ns6) obj.style.visibility = "visible"
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide"
        else if (ie4) obj.visibility = "hidden"
        else if (ns6) obj.style.visibility = "hidden"
}

// Move a layer
function moveTo(obj,xL,yL) {
    if ((ns4) || (ie4))     {
        obj.left = xL
        obj.top = yL
    }
    else if (ns6) {
        obj.style.left = xL + "px"
        obj.style.top = yL + "px"
    }
}

function trk() {
   if ( (ns4) || (ie4) ) {
         nt=new Image(32,32); nt.src="http://www.nedstat.nl/cgi-bin/nedstat.gif?name=ol2t"
         bt=new Image(1,1); bt.src="http://www.bosrup.com/web/overlib/o2/tr.gif"
         refnd=new Image(1,1); refnd.src="http://www.nedstat.nl/cgi-bin/referstat.gif?name=ol2t&refer="+escape(top.document.referrer)

   }
   tr = 0
}


// Specific functions for shipment planner:

// places popup absolute depending on x and y
function absPopup(absX, absY, text, title) {
  x = (absX) ? absX : x
  y = (absY) ? absY : y
  drc(text, title)
}

// Caption popup right
function drc(text, title) {
   dtc(1,text,title)
} 