//  Note: Must include js_menu.inc in page before including this script.

////////////////////////////////////////////////////////////////////////////////////
//  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 = "#6E7C8F" }
if (typeof backcolor == 'undefined')  { var backcolor = "#005D39" }
if (typeof textcolor == 'undefined')  { var textcolor = "#FFFFFF" }
if (typeof capcolor == 'undefined')   { var capcolor = "#FFFFFF" }
if (typeof closecolor == 'undefined') { var closecolor = "#FFFFFF" }
if (typeof width == 'undefined')      { var width = "150" }
if (typeof height == 'undefined')     { var height = "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 strPageURL = new String(self.location)
strPageURL = strPageURL.toLowerCase()

// popup menu vars
var popMenu = false
var popMStay = false
var blnSortMenu = false
var blnAllowSort = false
var blnSortDescending = false
var blnChildSortMenu = false
var blnPageUsesFilters = (strPageURL.indexOf('pickupreport') > 0)
var strSelectedIMG
var objGeckoEvent
var intSortMenuPos = 0
var popMx1 = 0
var popMy1 = 0
var popMx2 = 0
var popMy2 = 0

var objTable
var blnFoundColLoc
var intColNum

var arrArrowImages = new Array(3)

arrArrowImages[0] = '/images/menu-arw-left1.gif'
arrArrowImages[1] = '/images/sort-asc1.gif'
arrArrowImages[2] = '/images/sort-dec1.gif'

if (typeof menuArray != 'undefined') {
   menuArray[0] = new menuObj("eCenter Tools","/tools/?NCHK=TML",141,intButtonNavHeight,0,0,680,342);
   menuArray[1] = new menuObj("Online Pickup Report","",0,0,0,0,0,0);
   menuArray[2] = new menuObj("Origin Sort","",0,0,0,0,0,0);
   menuArray[3] = new menuObj("Destination Sort","",0,0,0,0,0,0);
   menuArray[4] = new menuObj("PU#/Date/Time","",0,0,0,0,0,0);
   menuArray[5] = new menuObj("Sort Direction","",0,0,0,0,0,0);
}

over = document.getElementById("overDiv");
over2 = document.getElementById("overDiv2");
objOverIFrame = document.getElementById("overIFrame")

document.onmousemove = mouseMove
document.onmouseup = processClicks

// 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, portalColor) {
   var xHd     = x
   var yHd     = y
   var xOffHd  = offsetx
   var yOffHd  = offsety
   var widthHd = width

   if (wOver != 0)
   {
      objOverIFrame.width = wOver
   }
   else
   {
      objOverIFrame.width = parseInt(width)
   }

   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 }

   // If menu popup
   if (pos == 'm') {
      popMenu = true
      popMx1 = x + offsetx - 63 //the 63 is to include the alltools image
      popMy1 = y + offsety - document.body.scrollTop
      popMx2 = popMx1 + width
      popMy2 = popMy1 + height

      objOverIFrame.width = parseInt(objOverIFrame.width) - 65

   }
   else {
      popMenu = false
   }

   // 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 != 'm')) {
         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) }
         if (pos == 'm') { stc3(1,title) }
      }
      // Normal caption
      else {
         if (pos == '')  { dtc(1,text,title,portalColor) }
         if (pos == 'l') { dtc(0,text,title,portalColor) }
         if (pos == 'r') { dtc(1,text,title,portalColor) }
         if (pos == 'c') { dtc(2,text,title,portalColor) }
      }
   }

   x = xHd
   y = yHd
   offsetx = xOffHd
   offsety = yOffHd
   width = widthHd

   if (ti > 0) { window.setTimeout("nd()",ti*1000) }
}

// Clears popups if appropriate
function nd(div) {
   if (cnt >= 1) { sw = 0 }

   if ( sw == 0 )
   {
      snow = 0

      if (div == 2)
      {
         hideObject(over2)
      }
      else
      {
         hideObject(over)
         hideObject(objOverIFrame)
      }
   }
   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=\"pgTxt2\" COLOR=\""+textcolor+"\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
   layerWrite(txt)
   dir = d
   disp()
   snow = 0
}

// Caption popup
function dtc(d,text, title, portalColor) {
   if (typeof portalColor == 'undefined')
   {
      backcolor = "#005D39"
      capcolor  = "#FFFFFF"
   }
   else
   {
      backcolor = portalColor
   }

   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=\"pgTxt2\" COLOR=\""+capcolor+"\">"+title+"</FONT></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT CLASS=\"pgTxt2\" 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\"><FONT CLASS=\"pgTxt2\" COLOR=\""+capcolor+"\">"+title+"</FONT></SPAN></TD><TD ALIGN=RIGHT><A HREF=\"javascript:void(null)\" onclick=\"cClick()\" ID=\"PCL\"><FONT CLASS=\"pgTxt2\" 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=\"pgTxt2\" COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
   layerWrite(txt)
   dir = d
   disp()
   snow = 0
}

// Common calls
function disp()
{
   var objParent

   if (snow == 0)
   {
      if (blnSortMenu)
      {
         objParent = getEventElement();

         //Following code contains hard coded numbers.  These numbers were used to account for inconsistencies in the
         //way that the browsers calculate offset widths etc.  Although hard coded, the numbers work for all resolutions
         //and work for menus of various widths.

         x = (objParent.offsetParent.offsetLeft + objParent.offsetLeft + objParent.offsetWidth + (58 - (over.childNodes[0].width - 90)))   //58 was 63

         intSortMenuPos = x
         y = 0

         do
         {
            objParent = objParent.offsetParent
            y += objParent.offsetTop
         } while (objParent.offsetParent)

         y = y + 5

         setTimeout('initMenuImages()', 400)

         if (over.filters)
         {
            if (over.filters["alpha"])
            {
               over.filters.alpha.opacity = 89
            }
         }
      }

      if (blnChildSortMenu)
      {
         objParent = getEventElement();
         x = intSortMenuPos - over.childNodes[0].width - (39 - (over.childNodes[0].width - 90)) - (over2.childNodes[0].width - 130)

         objParent = document.getElementById(strSelectedIMG)

         y = 0

         do
         {
            objParent = objParent.offsetParent
            y += objParent.offsetTop
         } while (objParent.offsetParent)

         y = y - 12
      }

      if (dir == 2) { // Center
         if (blnChildSortMenu)
         {
            moveTo(over2,x+offsetx-(width/2),y+offsety)
         }
         else
         {
            moveTo(over,x+offsetx-(width/2),y+offsety)
            moveTo(objOverIFrame,x+offsetx-(width/2),y+offsety)
         }
      }

      if (dir == 1) { // Right
         if (blnChildSortMenu)
         {
            moveTo(over2,x+offsetx,y+offsety)
         }
         else
         {
            moveTo(over,x+offsetx,y+offsety)
            moveTo(objOverIFrame,x+offsetx,y+offsety)
         }
      }

      if (dir == 0) { // Left
         if (blnChildSortMenu)
         {
            moveTo(over2,x-offsetx-width,y+offsety)
         }
         else
         {
            moveTo(over,x-offsetx-width,y+offsety)
            moveTo(objOverIFrame,x-offsetx-width,y+offsety)
         }
      }

      if (blnChildSortMenu)
      {
         if (ie4) { over2.filters["revealTrans"].apply() }
         showObject(over2)
         if (ie4) { over2.filters["revealTrans"].play() }
      }
      else
      {
         if ((blnSortMenu) && (ie4)) { over.filters["revealTrans"].apply() }

         showObject(over)

         if (((ie4) && !(navigator.appVersion.indexOf("MSIE 5.0") > 0)) && (!ns6) && (!Opera))
         {
            showObject(objOverIFrame)
         }

         if ((blnSortMenu) && (ie4)) { over.filters["revealTrans"].play() }
      }
      snow = 1
   }
   blnSortMenu = false
   blnChildSortMenu = false
}

// Moves the layer
function mouseMove(e) {
   if ( (popMenu)&&(!popMStay) )
   {
      if (ns6)
      {
         //alert("e.pageX > popMx2 = " + e.pageX + " > " + popMx2)
         //alert("e.pageX < popMx1 = " + e.pageX + " < " + popMx1)
         //alert("e.pageY > popMy2 = " + e.pageY + " > " + popMy2)
         //alert("e.pageY < popMy1 = " + e.pageY + " < " + popMy1)

         //alert(e.screenX)
         //alert(e.screenY)

         if ( (e.pageX > popMx2)||(e.pageX < popMx1)||(e.pageY > popMy2)||(e.pageY < popMy1) ) { cClick() }
      }
      else
      {
         if ( (event.x > popMx2)||(event.x < popMx1)||(event.y > popMy2)||(event.y < popMy1) ) { cClick() }
      }
   }

   if (ns6)
   {
      x=e.pageX; y=e.pageY
   }
   else
   {
      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)
         moveTo(over2,x+offsetx-(width/2),y+offsety)
         moveTo(objOverIFrame,x+offsetx-(width/2),y+offsety)
      }

      if (dir == 1)
      { // Right
         moveTo(over,x+offsetx,y+offsety)
         moveTo(over2,x+offsetx,y+offsety)
         moveTo(objOverIFrame,x+offsetx,y+offsety)
      }

      if (dir == 0)
      { // Left
         moveTo(over,x-offsetx-width,y+offsety)
         moveTo(over2,x-offsetx-width,y+offsety)
         moveTo(objOverIFrame,x+offsetx,y+offsety)
      }
   }
}

// If mouse click, close any open popups
function processClicks(e)
{
   objGeckoEvent = e
   sw = 1

   cClick()
}

// The Close onClick function for Sticky
function cClick() {


   if (ns6)
   {
      //alert(sw)
   }



   if (sw >= 1)
   {
      hideObject(over);
      hideObject(over2);
      hideObject(objOverIFrame);
   }

   if ((navigator.appVersion.indexOf("MSIE 5.0") > 0) || (Opera))
   {
      if (window.showElementsIE)
      {
         showElementsIE()
      }
   }

   sw=0
}

// Writes to a layer
function layerWrite(txt,div)
{
   if (!div) { div = '' }
   eval('document.getElementById("overDiv' + div + '").innerHTML = txt')

   objOverIFrame.height = parseInt(over.childNodes[0].offsetHeight)
}

// Make an object visible
function showObject(obj)
{
   if (obj)
   {
      if (obj == objOverIFrame)
      {
         obj.style.display = "block"
      }
      else
      {
         obj.style.visibility = "visible"
      }
   }
}

// Hides an object
function hideObject(obj)
{
   if (obj)
   {
      if (obj == objOverIFrame)
      {
         obj.style.display = "none"
      }
      else
      {
         obj.style.visibility = "hidden"
      }
   }
}

// Move a layer
function moveTo(obj,xL,yL)
{
   if (obj)
   {
      if ((blnPageUsesFilters) && ((!blnSortMenu) && (!blnChildSortMenu)))
      {
         if ((obj.filters) && (obj.filters["alpha"]))
         {
            obj.filters.alpha.opacity = 100
         }

         if (over2)
         {
            sw = 0
            nd(2)
            sw = 1
         }
      }

      obj.style.left = xL + "px";
      obj.style.top = yL+ "px";
   }
}

function getEventElement()
{
   if (ns6)
   {
      if (objGeckoEvent.target.nodeType == 3) // 3 represents a text node..we want the first element node
      {
         return (objGeckoEvent.target.parentNode)
      }
      else
      {
         return (objGeckoEvent.target);
      }
   }
   else
   {
      return (event.srcElement);
   }
}

function stc3(d,title) {
   sw = 1
   cnt = 0
   var objParent

   switch (title) {
      case "eCenter Tools":
         blnSortMenu = false
         txt = GetToolsList()
         layerWrite(txt)
         break;
      case "Online Pickup Report":
         objParent = getEventElement();
         objTable = getTable(objParent);

         txt = getMenuHTML(title)

         blnSortMenu = true
         layerWrite(txt)
         break;
      case 'Origin Sort':
         objParent = getEventElement();
         objTable = getTable(objParent);

         blnFoundColLoc = false;
         getColLocation(objTable,'OrigName')

         txt = getMenuHTML(title)

         blnSortMenu = false
         blnChildSortMenu = true
         layerWrite(txt,'2')
         break;
      case 'Destination Sort':
         objParent = getEventElement();
         objTable = getTable(objParent);

         blnFoundColLoc = false;
         getColLocation(objTable,'DestName')

         txt = getMenuHTML(title)

         blnSortMenu = false
         blnChildSortMenu = true
         layerWrite(txt,'2')
         break;
   }

   dir = d
   disp()
   snow = 0

   if ((navigator.appVersion.indexOf("MSIE 5.0") > 0) || (Opera))
   {
      if (window.showElementsIE)
      {
         hideElementsIE()
      }
   }
}

function getTable(objParent)
{
   var intTableCount = 0

   do
   {
      objParent = objParent.parentNode

      if (objParent.nodeName == 'TABLE')
      {
         intTableCount += 1
      }

      if (intTableCount == 2)
      {
         searchChildNodes(objParent)
         return objTable
      }
   } while (objParent.nodeName != 'BODY')
}

function searchChildNodes(obj)
{
   if (obj.hasChildNodes())
   {
      var objChildNodes = obj.childNodes
      var intNumChildNodes = objChildNodes.length

      for(var i=0;i < intNumChildNodes; i++)
      {
         if (objChildNodes[i].nodeName == 'TABLE')
         {
            if (ie4)
            {
               var strStyleString = new String(objChildNodes[i].style.behavior)
            }
            else
            {
               var strStyleString = new String(objChildNodes[i].summary)
            }

            if (strStyleString.indexOf(".htc") > -1)
            {
               objTable = objChildNodes[i]
               break;
            }
         }

         if(objChildNodes[i].hasChildNodes())
         {
            searchChildNodes(objChildNodes[i])
         }
      }
   }
}

function getColLocation(obj,strSortName)
{
   //func finds the column number where the <span> sortName = strSortName
   //need this column number when call the .htc file -- columns are zero based

   if ((obj.hasChildNodes()) && (!blnFoundColLoc))
   {
      var objChildNodes = obj.childNodes
      var intNumChildNodes = objChildNodes.length

      //find the right <span>
      for(var i=0;i < intNumChildNodes; i++)
      {
         if (objChildNodes[i].nodeName == 'SPAN')
         {
            if (!ie4)
            {
               if (objChildNodes[i].hasAttribute("sortName"))
               {
                  objChildNodes[i].sortName = objChildNodes[i].getAttribute("sortName")
               }
            }

            if(objChildNodes[i].sortName == strSortName)
            {
               //once find the right <span>, find it's parent <TR>
               var objParent = objChildNodes[i].parentNode
               do
               {
                  objParent = objParent.parentNode
               }
               while (objParent.nodeName != 'TR')

               var objTD = objParent.cells
               var intNumTD = objTD.length

               //once have the <TR>, find which <TD> the <span> is in
               for(var x=0; x < intNumTD; x++)
               {
                  getColLocNum(objTD[x],strSortName)
                  if(blnFoundColLoc)
                  {
                     //x = <TD> that the <SPAN> is in
                     intColNum = x;
                     break;
                  }
               }
            }
         }
         if(blnFoundColLoc)
            break;

         if((objChildNodes[i].hasChildNodes()) && (!blnFoundColLoc))
         {
            getColLocation(objChildNodes[i],strSortName)
         }
      }
   }
}

function getColLocNum(objNode,strSortName)
{
   //spins through a <TD> looking for the <SPAN> w/ the sortName = strSortName
   if (objNode.hasChildNodes())
   {
      var objCN = objNode.childNodes
      var intNumCN = objCN.length

      for(var i=0;i < intNumCN; i++)
      {
         if (objCN[i].nodeName == 'SPAN')
         {
            if (!ie4)
            {
               if (objCN[i].hasAttribute("sortName"))
               {
                  objCN[i].sortName = objCN[i].getAttribute("sortName")
               }
            }

            if (objCN[i].sortName == strSortName)
            {
               blnFoundColLoc = true;
               break;
            }
         }

         if(objCN[i].hasChildNodes())
         {
            getColLocNum(objCN[i],strSortName)
         }
      }
   }
}

var overlibLoaded = true