/* browser detection */

var isIE  = false;
var isMac = false;
var ua    = navigator.userAgent.toLowerCase();

if (ua.indexOf("msie") != -1)
   isIE = true;

if (ua.indexOf("mac") != -1)
   isMac = true;

/*****************************************************************************/

/* submenu constructor */
function submenu(name,submenuWidth,submenuHeight,submenuLeft,submenuTop,scrollWidth,scrollHeight,posAdjust,controlTopHeight,controlBottomHeight,menuOptionHeight) // JZ 03/19/07
{
   this.name                = name;
   this.submenuWidth        = submenuWidth;
   this.submenuHeight       = submenuHeight;
   this.submenuLeft         = submenuLeft
   this.submenuTop          = submenuTop;
   this.scrollWidth         = scrollWidth;
   this.scrollHeight        = scrollHeight;
   this.posAdjust           = posAdjust;
   this.controlTopHeight    = controlTopHeight;     // JZ 03/19/07
   this.controlBottomHeight = controlBottomHeight;  // JZ 03/19/07
   this.menuOptionHeight    = menuOptionHeight;     // JZ 03/19/07
}

var submenuArray = new Array();

/*****************************************************************************/

/* submenu creation */

var controlTopHeight    = 0;
var controlBottomHeight = 0;
var scrollLeft          = 0;
var menuOptionHeight    = 21; // JZ 03/19/07

if (isIE)
{
   controlTopHeight    = 22;
   controlBottomHeight = 21;
}
else
{
   controlTopHeight    = 22;
   controlBottomHeight = 21;
   menuOptionHeight    = 18; // JZ 03/19/07
}

if (isMac)
{
   controlTopHeight    = 20;
   controlBottomHeight = 20;
   menuOptionHeight    = 21; // JZ 03/19/07
}

var scrollTop = controlTopHeight;
var submenuWidth  = 150;
var submenuHeight = 0;
var extraHSpace   = 0;
var extraVSpace   = 0;
var posAdjust     = 140;

if (!isIE) {
/*   extraHSpace = 2; */
   extraVSpace = -3;
} 

if (isMac) {
   extraHSpace = -1;
   extraVSpace = 0;
}

submenuArray[0] = new submenu("subMenu1sm1",submenuWidth,submenuHeight,111 + extraHSpace,21 + extraVSpace,submenuWidth,submenuHeight - controlTopHeight - controlBottomHeight,posAdjust,controlTopHeight,controlBottomHeight,menuOptionHeight); // JZ 03/19/07

/* submenu 2 */

var controlTopHeight    = 0;
var controlBottomHeight = 0;
var scrollLeft          = 0;
var menuOptionHeight    = 21; // JZ 03/19/07

if (isIE)
{
   controlTopHeight    = 22;
   controlBottomHeight = 21;
}
else {
   controlTopHeight    = 22;
   controlBottomHeight = 21;
   menuOptionHeight    = 18; // JZ 03/19/07
}

if (isMac) {
   controlTopHeight    = 20;
   controlBottomHeight = 20;
   menuOptionHeight    = 21;  // JZ 03/19/07
}

var scrollTop = controlTopHeight;
var submenuWidth  = 170;
var submenuHeight = 0;
var extraHSpace   = 0;
var extraVSpace   = 0;
var posAdjust     = 150;

if (!isIE) {
/*   extraHSpace = 3; */
   extraVSpace = -6;
} 

if (isMac) {
   extraHSpace   = -1;
   extraVSpace   = 0;
   posAdjust     = 160;
}

submenuArray[1] = new submenu("subMenu1sm2",submenuWidth,submenuHeight,111 + extraHSpace,42 + extraVSpace,submenuWidth,submenuHeight - controlTopHeight - controlBottomHeight,posAdjust,controlTopHeight,controlBottomHeight,menuOptionHeight); // JZ 03/19/07

/*****************************************************************************/

function scroll(obj,dir)
{
   var submenu;
   
   for (var i=0; i<=submenuArray.length; i++)
   {
      if (submenuArray[i].name == obj)
      {
         submenu = submenuArray[i];
         break;
      }
   }

   var scrollObj = document.getElementById(obj + "Scroll");
   var scrollContainer = document.getElementById(obj + "Container");
   var ct  = clipTop(scrollObj);
   var cr  = clipRight(scrollObj);
   var cb  = clipBottom(scrollObj);
   var cl  = clipLeft(scrollObj);
   var w   = submenu.scrollWidth;
   var h   = submenu.scrollHeight;
   var amt = 0;
   
   amt = getContainerSize(obj);

   if (dir == "up")
      amt = -amt;
   
   /* Don't clip past top or bottom. */
   if (ct + amt < 0) 
      amt = -ct;
   else if (cb + amt > h) 
      amt = h - cb;
   
   var objTop = scrollObj.style.top;
   objTop = objTop.substring(0,objTop.indexOf("px"));
   scrollObj.style.top    = eval(objTop - amt) + "px";
   var objHeight = scrollObj.style.height;
   objHeight = eval(objHeight.substring(0,objHeight.indexOf("px")));
   scrollObj.style.height = eval(objHeight + amt) + "px";
   scrollObj.style.clip = "rect(" + eval(ct + amt) + "px " + cr + "px " + eval(cb + amt)  + "px " + cl + "px)";

} // scroll                                            

/*****************************************************************************/

function clipTop(obj)
{                
   var clipValue = 0;
   var a = clipArray(obj);

   if (a)                       
      clipValue = parseInt(a[1]);
   else if (document.layers) 
      clipValue = obj.clip.top;  

   return clipValue;
}
   
function clipBottom(obj) 
{
   var clipValue = obj.style.pixelHeight;
   var a = clipArray(obj);

   if (a) 
      clipValue = parseInt(a[3]);
   else if (document.layers) 
      clipValue = obj.clip.bottom;

   return clipValue;
}

function clipRight(obj) 
{
   var clipValue = obj.style.pixelWidth;
   var a = clipArray(obj);

   if (a) 
      clipValue = parseInt(a[2]);
   else if (document.layers) 
      clipValue = obj.clip.right;

   return clipValue;
}

function clipLeft(obj) 
{
   var clipValue = 0;
   var a = clipArray(obj);

   if (a) 
      clipValue = parseInt(a[4]);
   else if (document.layers) 
      clipValue = obj.clip.left;

   return clipValue;
}

function clipArray(obj)
{
   if (obj.style) 
   {
      var re = /\(|px,?\s?\)?|\s|,|\)/;
      return obj.style.clip.split(re);
   }
   else 
      return null;
}

/*****************************************************************************/

function setupScroll(obj)
{
   var submenu;
   var container;
   var myHeight = 0; 
   
   for (var i=0; i<=submenuArray.length; i++)
   {
      if (submenuArray[i].name == obj)
      {
         submenu = submenuArray[i];
         break;
      }
   }

   setMenuHeight(submenu);  // JZ 03/19/07

   container = document.getElementById(obj + "Container");
   
   if( typeof( window.innerWidth ) == "number" )
   {
      //Non-IE
      myHeight = window.innerHeight; 
   }
   else if( document.documentElement && document.documentElement.clientHeight )
   {
      //IE 6+ in standards compliant mode
      myHeight = document.documentElement.clientHeight; 
   }
   else if( document.body && document.body.clientHeight )
   {
      //IE 4 compatible
      myHeight = document.body.clientHeight; 
   }
   
   var availScrollHeight = myHeight - submenu.posAdjust - (controlTopHeight + controlBottomHeight);

   if (availScrollHeight > submenu.scrollHeight)
      availScrollHeight = submenu.scrollHeight;

   var temp = availScrollHeight + "px";
   container.style.height = temp;
   
   if (availScrollHeight != submenu.scrollHeight)
   {
      availScrollHeight = getContainerSize(obj);
      container.style.height = availScrollHeight + "px";
   }

   /* Scroll Object Setup */

   var scrollObj = document.getElementById(obj + "Scroll");
   var clipTemp =  availScrollHeight;

   if (clipTemp > submenu.scrollHeight)
      clipTemp = submenu.scrollHeight;
   
   clipTemp = "rect(0px " + submenu.scrollWidth + "px " + clipTemp + "px 0px)";
   container.style.clip = clipTemp;
   scrollObj.style.clip = clipTemp; //"rect(0px 0px 0px 0px)"; //clipTemp;

   /* Scroll menu styling. */

   scrollObj.style.height     = container.style.height;
   scrollObj.style.position   = "absolute"; 
   scrollObj.style.overflow   = "hidden"; 
   scrollObj.style.width      = submenu.scrollWidth + "px";
   scrollObj.style.top        = submenu.submenuTop + scrollTop + "px"; 
   scrollObj.style.left       = submenu.submenuLeft + scrollLeft + "px"; 
   scrollObj.style.visibility = "hidden"; 
   scrollObj.style.zIndex     = 6;

   /* Submenu setup */

   var subMenu = document.getElementById(obj);
   subMenu.style.height     = availScrollHeight + controlTopHeight + 
                                                  controlBottomHeight + "px";
   subMenu.style.position   = "absolute"; 
   subMenu.style.overflow   = "hidden"; 
   subMenu.style.width      = submenu.scrollWidth + "px";
   subMenu.style.top        = submenu.submenuTop + "px"; 
   subMenu.style.left       = submenu.submenuLeft + "px"; 
   subMenu.style.visibility = "hidden"; 
   subMenu.style.zIndex     = 6;
   clipTemp = "rect(0px " + submenu.scrollWidth + "px " + eval(availScrollHeight + controlTopHeight + controlBottomHeight) + "px 0px)";
   subMenu.style.clip = clipTemp;

   /* IE7 Bullshit */

   var ie7Spacer1 = document.getElementById(obj + "ContainerIE7Spacer1");
   var ie7Spacer2 = document.getElementById(obj + "ContainerIE7Spacer2");
   ie7Spacer1.style.height = menuOptionHeight + "px";
   //gpw added condition 8.24.07
   if(availScrollHeight - menuOptionHeight > 0){
   ie7Spacer2.style.height = eval(availScrollHeight - menuOptionHeight) + "px";
   }
} // setupScroll

/*****************************************************************************/

function getContainerSize(obj)
{
   var containerSize = 0;
   var container     = document.getElementById(obj + "Container");
   var count         = eval(obj + "Count");
   var tempSize      = 0;
   var subMenu;

   for (var i=0; i<=submenuArray.length; i++)
   {
      if (submenuArray[i].name == obj)
      {
         subMenu = submenuArray[i];
         break;
      }
   }

   if (isIE)
      containerSize = container.style.pixelHeight;
   else
   {
      var temp      = container.style.height;
      temp          = temp.substring(0,temp.indexOf("px"));
      containerSize = eval(temp);
   }   
   
   var menuItemHeight = subMenu.scrollHeight / count;
   var menuItemCount  = Math.floor(containerSize / menuItemHeight); 
   containerSize  = menuItemCount * menuItemHeight;

   return containerSize;

} // getContainerSize

/****v JZ 03/19/07 v*****/

function setMenuHeight(submenu)
{
   var count  = eval(submenu.name + "Count"); 

   submenu.scrollHeight = submenu.menuOptionHeight * count;
   
} // setMenuHeight

/****^ JZ 03/19/07 ^*****/

function quickSrch()
{
    if (checkClickFlag())
        {
            displayProcessingMsg();
            document.cookie="srForward=''; path=/";
            document.forms["search"].submit();
        }
     else
        {return false;}
}

function linkTo(url,winOpt,reqLogin,reqNoLogin,doMsg,timeout)
{
    var winPop = "";
    if (winOpt != "")
        {if (winOpt == "_new")
            winPop = "window.open('" + url + "','','')";
         else
            winPop = "window.open('" + url + "','','" + winOpt + "')";
        }
    else
        winPop = "document.location.href = '" + url + "'";
    if ( loginAlert(reqLogin,reqNoLogin) )
        {if (doMsg)
            {if (checkClickFlag(timeout))
                {displayProcessingMsg();
                 eval(winPop);
                }
             else {return false;}
            }
         else 
            {if (checkClickFlag(timeout))
                {eval(winPop);}
             else {return false;}
            }
        }
}


