/*
* This script contains Javascript that will set up a page header for all pages
* that are part of the BSM Development site, so that they have a standard look
* and feel.
*/

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

// Page information.
var LeftMenuWidth = 170;                // Left side menu width, in pixels
var RightMenuWidth = 110;               // Right side menu width, in pixels

var MenuBarTop = 84;                    // Bar menu positioning
var MenuBarLeft = LeftMenuWidth + 5;
var MenuBarHeight = 24;                 // Height of bar menu

var MenuRightTop = 10;                  // Right menu positioning
var MenuRightLeft = 15;
var MenuRightPad = 3;                   // Padding between menu items

var MenuPagePad = 10;                   // Padding above/below page menu

var ContentPad = 20;                    // Padding between content and menu bars

var TextBlockWidth = 450;               // Text block width on Standard page

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

// Identify the browser type so that we may act accordingly.  This allows us to
// format the page nicely, despite the browser's idiot-syncracies (especially
// those of IE).
var BrowserAgent = navigator.userAgent.toLowerCase();
var BrowserVersion = navigator.appVersion.toLowerCase();
var BrowserMajorVer = parseInt(BrowserVersion);

var BrowserIsNavigator = ((BrowserAgent.indexOf('mozilla') != -1)
  && (BrowserAgent.indexOf('compatible') == -1));
var BrowserIsExplorer = (BrowserAgent.indexOf('msie') != -1);
var BrowserIsOpera = (BrowserAgent.indexOf('opera') != -1);
if (BrowserIsOpera) { BrowserIsNavigator = true; BrowserIsExplorer = false; }

// Set the logo for the browser to display in the address field as well as on
// any tabs.
document.write('<link rel="shortcut icon" href="/Page/BSMLogo_Square_Small.ico" TYPE="image/x-icon">');

// Draw a table to surround the page header with a nice border.
document.write(
  '<table class=PageHeader cols=1 width=100% cellpadding=0 cellspacing=0>' +
    '<tr><td align=left>');

// Include the page header image.
//
// Note that we use "display: block" so that the browser doesn't f**k with the
// image by adding a three pixel space below it for the descenders (i.e.
// because it defaults to "display: text") in STRICT mode.  BTW, everything
// works just fine in TRANSITIONAL.
document.write(
    '<a href="/index.html">' +
      '<img style="display: block;" height=78 width=720 ' +
        'src="/Page/PageHeader.jpg" alt="" border=0>' +
    '</a>');

// Close off the page header table
document.write(
    '</td></tr>' +
  '</table>');

// Use a table to draw a bar where the bar menu goes.  This is drawn whether
// there is a bar menu or not.
document.write(
  '<table class=PageBar cols=1 width=100% border=0 ' +
    'cellpadding=0 cellspacing=0>' +
    '<tr><td height='+MenuBarHeight+'></td></tr>' +
  '</table>');

// Create a table to align everything on the page to the right of the lefthand
// menu.
if (BrowserIsNavigator && (BrowserMajorVer <= 4)) LeftMenuWidth -= 4;

document.write(
  '<table class=PageFrame cols=5 width=100% border=0 ' +
    'cellpadding=0 cellspacing=0>' +
    '<tr><td class=LeftMenuColor width='+LeftMenuWidth+' valign=top>');

// If we have a menu path, add the lefthand content.
if (typeof(PageMenuPath) == 'string')
  {
  var SubmenuType = PageMenuPath.substr(0, 1);

  // If we're not at the home page, add the lefthand, text menu.
  if (PageMenuPath != PageHome)
    {
    var SubmenuPath, SubmenuPtr = null;

    // If this is one of the About menus, set it up.
    if (SubmenuType == '2')
      { SubmenuPath = PageMenuPath.substr(2); SubmenuPtr = AboutMenu; }

    // Otherwise, if this is one of the Services menus, set it up.
    else if (SubmenuType == '3')
      { SubmenuPath = PageMenuPath.substr(2); SubmenuPtr = ServicesMenu; }

    // Otherwise, if this is one of the Products menus, set it up.
    else if (SubmenuType == '4')
      { SubmenuPath = PageMenuPath.substr(2); SubmenuPtr = ProductsMenu; }

    // Otherwise, if this is one of the Reference menus, set it up.
    else if (SubmenuType == '5')
      { SubmenuPath = PageMenuPath.substr(2); SubmenuPtr = ReferenceMenu; }

    // Otherwise, if this is one of the Resources menus, set it up.
    else if (SubmenuType == '6')
      { SubmenuPath = PageMenuPath.substr(2); SubmenuPtr = ResourcesMenu; }

    // Since the menu we're using was originally a submenu, we need to clip the
    // first element off of it.  Also, if it has any submenus, we'll set them
    // up to display in the submenu font.
    //
    // Note that there is an opportunity for recursively processing the menu
    // here but, since there is only ever one level, we do it inline.  Its
    // simpler that way.
    if (SubmenuPtr)
      {
      var CurrSub, NewSub, Submenu = new Array();

      for (CurrSub = 1; CurrSub < SubmenuPtr.length; CurrSub++)
        {
        NewSub = CurrSub - 1;

        Submenu[NewSub] = new Array(4);
        Submenu[NewSub][0] = SubmenuPtr[CurrSub][0];
        Submenu[NewSub][1] = '';

        // If this menu has a submenu, process it (inline).
        if (typeof(SubmenuPtr[CurrSub][2]) == 'object')
          {
          var SubSubmenuPtr = SubmenuPtr[CurrSub][2];
          var CurrSubSub, SubSubmenu = new Array();

          // Set the attributes to the text submenu font, etc.
          SubSubmenu[0] = new Array(4);
          SubSubmenu[0][0] = ''; SubSubmenu[0][1] = ''; SubSubmenu[0][2] = '';
          SubSubmenu[0][3] =
            'Font='+LeftSubmenuFont+', ' +
            'FontSize='+LeftSubmenuFontSize+', ' +
            'Indent='+LeftSubmenuIndent+', ' +
            'MenuSpacing='+LeftSubmenuSpacing;

          for (CurrSubSub = 1; CurrSubSub < SubSubmenuPtr.length; CurrSubSub++)
            {
            SubSubmenu[CurrSubSub] = new Array(4);
            SubSubmenu[CurrSubSub][0] = SubSubmenuPtr[CurrSubSub][0];
            SubSubmenu[CurrSubSub][1] = ''; SubSubmenu[CurrSubSub][2] = '';
            SubSubmenu[CurrSubSub][3] = SubSubmenuPtr[CurrSubSub][3];
            }

          Submenu[NewSub][2] = SubSubmenu;
          }
        else { Submenu[NewSub][2] = 0; }

        Submenu[NewSub][3] = SubmenuPtr[CurrSub][3];
        }

      // OK, let's display the text menu.
      TxMenuWidth = LeftMenuWidth;
      DisplayTextMenu(Submenu, SubmenuPath, '', 5, 17, true);
      }
    }

  // Otherwise, for the home menu, add the latest press release using AJAX.
  // Wow!  How cool is that?
  else
    {
    document.write(
      '<div id=PressRelText style="' +
        'margin-top: 75px; margin-left: 10px; margin-right: 10px;">' +
      '</div>');
    LoadText('PressRelText', '/cgi-bin/InsertDocList.cgi?Type=PR&Count=1&' +
      'Class=NewsText&TplURL=About/PressRel_AJAX.html');
    }
  }

// Otherwise, there is not lefthand content.
else { document.write('&nbsp;'); }

// Finish off aligning the page.
document.write(
    '</td>' +
    '<td width='+ContentPad+'>&nbsp;</td>' +
    '<td valign=top>' +
      '<img style="display: block;" height='+ContentPad+' width=1 ' +
        'src="/Page/OneByOne.gif" alt="">');

// If the page format is one of our standard formats, we can set up the text
// block and add the first heading.
if ((typeof(PageMenuPath) == 'string') && (typeof(PageFormat) == 'string'))
  {
  var PageTitleBar;

  // Decide which title bar to use.
  switch (SubmenuType)
    {
    case '1': PageTitleBar = 'Home_TitleBar'; break;
    case '2': PageTitleBar = 'About_TitleBar'; break;
    case '3': PageTitleBar = 'Services_TitleBar'; break;
    case '4': PageTitleBar = 'Products_TitleBar'; break;
    case '5': PageTitleBar = 'Reference_TitleBar'; break;
    case '6': PageTitleBar = 'Resources_TitleBar'; break;
    case '7': PageTitleBar = 'Search_TitleBar'; break;
    default: PageTitleBar = 'Home_TitleBar'; break;
    }

  // The "Standard" page format.
  if (PageFormat == 'Standard')
    {
    document.write(
      '<p class=StdHead style="margin: .67em 0">' +
        '<img style="display: block;" src="/Page/'+PageTitleBar+'.gif" ' +
          'alt=""></p>' +
      '<table style="margin-top: -20px;" cols=2>' +
        '<tr><td width=8>&nbsp;</td>' +
        '<td width='+TextBlockWidth+'>');
    }

  // The "Reference" page format.
  else if (PageFormat == 'Reference')
    {
    document.write(
      '<p class=StdHead style="margin: .67em 0">' +
        '<img style="display: block;" src="/Page/Reference_TitleBar.gif" ' +
          'alt=""></p>' +
      '<table style="margin-top: -20px;" cols=2>' +
        '<tr><td width=8>&nbsp;</td>' +
        '<td width='+TextBlockWidth+'>');
    }
  }
