function getElement( which )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( which );

  else if( document.all ) // this is the way old msie versions work
      elem = document.all[which];

  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[which];

  return elem;
}

function prettyString(text)
{
  return text.replace('\r\n',' ');
}

function prettyFireString(text)
{
  var newText;
  newText='';

  var re = /^([A-Z])$/;
  
  newText = newText + text.substring(0,1);
  for (i=1;i<text.length;i++)
  {
    if (re.test(text.substring(i,i+1)))
    {
      newText = newText + ' ';
    }
    newText = newText + text.substring(i,i+1);
  }
  return newText;
}

function hideLayer( whichLayer )
{
  var elem, vis;
  elem = getElement( whichLayer );
  if(elem){
    vis = elem.style;
    vis.display = 'none';
  }
}

function showLayer( whichLayer )
{
  var elem, vis;
  elem = getElement( whichLayer );
  if(elem){
    vis = elem.style;
    vis.display = 'block';
  }
}

function selectTab( whichTab )
{
  var elem, vis;
  elem = getElement( whichTab );
  vis = elem.style;
  
  vis.backgroundPosition = '0 -68px'; // rest of the world

  var myStash=getElement('stash');
  myStash.innerHTML = whichTab;

  var elembreadcrumbplaceholder, visbreadcrumbplaceholder;
  elembreadcrumbplaceholder = getElement('TabBreadcrumbPlaceholder');  
  visbreadcrumbplaceholder= elembreadcrumbplaceholder.style;
  
  visbreadcrumbplaceholder.display = 'block';
  if (document.all) {
     elembreadcrumbplaceholder.innerText = prettyString(elem.innerText);
  } else {
     elembreadcrumbplaceholder.textContent = prettyFireString(elem.textContent);
  }

}

//
// called to de-select a tab when navigating 
// also hides the breadcrumb tab placeholder
//
function deSelectTab( whichTab )
{
  var elem, vis;
  elem = getElement( whichTab );
  //elem.removeAttribute("style"); // everyone else in the world

  if(elem){
  vis = elem.style; 
  vis.backgroundPosition = '0 0px'; 
  }

  var elembreadcrumbplaceholder, visbreadcrumbplaceholder;
  elembreadcrumbplaceholder = getElement('TabBreadcrumbPlaceholder');  
  visbreadcrumbplaceholder= elembreadcrumbplaceholder.style;
  
  visbreadcrumbplaceholder.display = 'none';
}


function moveitrealgood(item, direction)
{
   var mystash = getElement('stash');

   if (item.id != mystash.innerHTML)
   {

     if (direction == 'up')
    {    item.style.backgroundPosition = '0 -68px'; }
    else 
    {    item.style.backgroundPosition = '0 0px'; }

   }
}

function highlightMenu(item, direction)
{
   var mystash = getElement('lastnavselection');

   if (item.id != mystash.innerHTML)
   {

     if (direction == 'up')
     {    item.style.backgroundPosition = '0 -33px'; }
     else 
     {    item.style.backgroundPosition = '0 0px'; }

   }
}

function toggleMenu( whichLayer )
{

  var mystash = getElement('lastnavselection');
  
  var elem, vis;
  elem=getElement(whichLayer);
  vis = elem.style;

  if (vis.display == 'none')
  {
      vis.display = 'block';
      elem.previousSibling.firstChild.style.backgroundPosition = '0 -66px';
      mystash.innerHTML = elem.previousSibling.firstChild.id;
  }
  else 
  {
      vis.display = 'none';
      elem.previousSibling.firstChild.removeAttribute("style");
  }
}


