


var menuSelection = "";

function menuOver(id)
{
  if (id != menuSelection)
    document.getElementById(id).className='menuTextOver';
}

function menuOut(id)
{
  if (id != menuSelection)
    document.getElementById(id).className='menuText';
}

function menuSelect(id)
{
  if (menuSelection != "")
  {
    try
    {
      document.getElementById(menuSelection).className='menuText';
      document.getElementById(menuSelection + 'tr').className='menuRow';
    }
    catch(e)
    {
    }
  }

  menuSelection = id;
  if (menuSelection != "")
  {
    try
    {
      document.getElementById(menuSelection).className='menuTextSelected';
      document.getElementById(menuSelection + 'tr').className='menuRowSelected';
    }
    catch(e)
    {
      // alert('menu select: ' + menuSelection);
    }
  }
}


function menuOver2(id)
{
  if (id != menuSelection)
    document.getElementById(id).className='menuTextOver2';
}

function menuOut2(id)
{
  if (id != menuSelection)
    document.getElementById(id).className='menuText2';
}

function menuSelect2(id)
{
  if (menuSelection != "")
  {
    document.getElementById(menuSelection).className='menuText2';
    document.getElementById(menuSelection + 'tr').className='menuRow2';
  }

  menuSelection = id;
  if (menuSelection != "")
  {
    document.getElementById(menuSelection).className='menuTextSelected2';
    document.getElementById(menuSelection + 'tr').className='menuRowSelected2';
  }
  
  try
  {
 //   menuTo(id);
  }
  catch(e)
  {
  }
}

function parseURL()
{
  return parseAnURL(document.URL);
}

function parseAnURL(url)
{
  var res = new Array();

  ndx = url.indexOf('?');
  if (ndx > -1)
  {
    querystring = url.substr(ndx + 1);
    ndx = querystring.indexOf('&');
    while (ndx > -1)
    {
      temp = querystring.substring(0, ndx);
      querystring = querystring.substr(ndx + 1);

      ndx = temp.indexOf('=');
      if (ndx > -1)
      {
        left = temp.substring(0, ndx);
        res[left] = decodeURIComponent(temp.substr(ndx + 1));
      }
      ndx = querystring.indexOf('&');
    }
    ndx = querystring.indexOf('=');
    if (ndx > -1)
    {
      left = querystring.substring(0, ndx);
      res[left] = decodeURIComponent(querystring.substr(ndx + 1));
    }
  }
  
  return res;
}

function appendArgs(url, args)
{
  res = url;
  
  for (var nam in args)
  {
    if (-1 == res.indexOf('?'))
      res += '?';
    else
      res += '&'; 
    res += nam + '=' + encodeURIComponent(args[nam]);
  }
  
  return res;
}

var listSelection = '';
var listSelClass = '';
var listOverClass = '';

function listOver(id)
{
  if (id != listSelection)
  {
    listOverClass = document.getElementById(id).className;
    document.getElementById(id).className = 'listOver';
  }
}

function listOut(id)
{
  if (id != listSelection)
    document.getElementById(id).className = listOverClass;
}

function listSelect(id)
{
  if (listSelection != '')
  {
    try
    {
      document.getElementById(listSelection).className = listSelClass;
    }
    catch(e)
    {
    }
  }
  
  listSelection = id;
  listSelClass  = listOverClass;
  document.getElementById(listSelection).className = 'listSelected';
  
  try
  {
    idSelected(listSelection);
  }
  catch(e)
  {
  }
}


function workTrunc(str, maxlen)
{
  var res = str;
  if (res.length > maxlen)
  {
    ndx = maxlen - 1;
    while (ndx > 0 && res.charAt(ndx) != ' ')
      ndx--;
    if (ndx <= 0)
      res = res.substring(0, maxlen - 1);
    else
      res = res.substring(0, ndx);
  }

  return res;
}


function adjustFrameSize(sz)
{
  var res = sz;
  if (top.textSize == 1)
  {
    res = parseInt(sz * 1.3);
  }
  
  return res;
}


// This function actually performs two tasks.  One, check if the top window
// URL is actually for a sub-frame.  In this case, extract the section and
// menu, and reload from within index.html.  If this is not the case, then
// we use this function to also select the left menu item that should be
// selected (change the UI only, it's already on the correct page).

function checkRedirect()
{
  // If there's an '/html/' in the location string of the top window, then this is
  // a direct reference to an URL, which must be translated to menu/sub/extra stuff
  
  hr = top.window.location.href;
  ndx = hr.indexOf('/html/');
  if (ndx > -1)
  {
    // In almost all cases, the last directory is the menu, and the filename
    // is the sub selection.  This is not the case in the services section, where
    // there are some sub-pages that map to 'contract', and the product pages.
    
    extra = parseAnURL(hr);
    
    ndx = hr.indexOf('/html/');
    url = hr.substring(0, ndx) + '/index.html';
    args = '';
    right = hr.substr(ndx + 6);
    ndx = right.indexOf('/');
    if (ndx > -1)
    {
      menu = right.substring(0, ndx);
      extra['menu'] = menu;

      right = right.substr(ndx+1);

      ndx = right.indexOf('.');
      if (ndx > -1)
      {
        sub = right.substring(0, ndx);
        
        
        // Time for the special cases here...
        if (menu == "products")
        {
          // Presumably, this is an explicit detail page, which means we are looking
          // at the product id embedded in the filename (item now)
          ndx = sub.indexOf('/product');
          if (ndx > -1)
          {
            sub = sub.substr(ndx + 8);
            extra['item'] = sub;
            sub = 'masterlist';
          }
        }
        
        extra['sub'] = sub;
      }
    }
    
    url = appendArgs(url, extra);
    
    top.window.location.href = url;
  }
  else
  {
  
  // Now we're going to select the appropriate menu item as active.
  // This is typically the file name (without extension), but may
  // be overridden by an "menuid" query string argument.
  
    tp = this.location.href;
    
    top.forRefresh(tp);
    
    qa = '';
    ndx = tp.indexOf('?');
    if (ndx > -1)
    {
      qa = tp.substr(ndx);
      tp = tp.substring(0, ndx);
    }
    ndx = tp.lastIndexOf('/');
    if (ndx > -1)
    {
      tp = tp.substr(ndx + 1);
      ms = '';
      extra = parseAnURL(tp + qa);
      if (extra['menuid'] != null)
        ms = extra['menuid'];
      else
      {
        ndx = tp.indexOf('.');
        if (ndx > -1)
          ms = tp.substr(0, ndx);
      }
    
      if (ms != '')
      {
        try
        {
          parent.menuSelect(ms);
        }
        catch(e)
        {
          alert('What the hey: ' + ms);
        }
      }
    }
  }
}



function checkCMS()
{
  tp = this.location.href;
  ndx = tp.lastIndexOf('/');
  if (ndx == -1)
    ndx = tp.lastIndexOf('\\');
  if (ndx > -1)
  {
    tp = tp.substr(ndx + 1);
    qa = '';
    ndx = tp.indexOf('?');
    if (ndx > -1)
    {
      qa = tp.substr(ndx);
      tp = tp.substring(0, ndx);
    }
    ndx = tp.indexOf('.');
    if (ndx > -1)
    {
      tp = tp.substring(0, ndx);
      try
      {
        parent.menuSelect(tp + qa);
      }
      catch(e)
      {
      }
    }
  }
}





