// $Source: D:/cvsrepo/dreamsrc/web/scripts/ui.js,v $
// $Revision: 1.1 $
// $Author: mls $
// $Date: 2004/03/02 13:15:38 $

// Declares functions used as event handlers in UI elements at dreammodel.dk

function getElement(id) {
// Browser agnostic identification of elements for dreammodel.dk
// Do not rely on this function for full cross-browser compatibility
  
  var elm;
  
  if (document.layers) {
    // (Supported) proprietary Navigator 4.x elements
    elm = document.layers[id];
  }
  else if (document.all && !document.getElementById) {
    // (Supported) proprietary IE4
    elm = id;
  }
  else if (document.getElementById && document.body.style) {
    // Standards compliant browser
    elm = document.getElementById(id);
  }
  return elm;
}

function toggleAbstract(toggleTarget)
{
  var tt = getElement(toggleTarget);
  if (tt.className == "collapsed") {
    tt.className = "expanded";
  }
  else {
    tt.className = "collapsed" ;
  }
}

function updateMenu() {
// Causes the topic currently shown in the content frame to be highlighted in the menu, and updates browser title bar

  var maindoc = window.parent.frames['content'].document;
  var menudoc = window.parent.frames['contentmenu'].document;

  if (menudoc.body == null) return;

  var curLocation = maindoc.location;
  var menuLinks = menudoc.body.getElementsByTagName("A");
  var highlightSet = false;
  
  for (i = menuLinks.length - 1; i >= 0; i--)
  {
    if (highlightSet || (menuLinks[i].href != curLocation))
      menuLinks[i].className = '';
    else
    {
      menuLinks[i].className = 'highlight';
      if(menuLinks[i].innerText)
        document.title = 'Danish Rational Economic Agents Model - ' + menuLinks[i].innerText;
      else
        document.title = 'Danish Rational Economic Agents Model - ' + menuLinks[i].text;
      highlightSet = true;
    }
  }
}