function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function()
        {
            if (oldonload)
            {
                oldonload();
            }
            func();
        }
    }
}


function toothTalkLoader()
{
    var toothtalkLinks = document.getElementById('toothtalklinks');
    var destination = toothtalkLinks.options[toothtalkLinks.selectedIndex].value;
    if(destination != "")
    {
        document.location = destination;
    }
}


function chooseQuote()
{
    if(document.getElementsByTagName)
    {
        var quotes = document.getElementsByTagName("BLOCKQUOTE");
        if(window.location.href.indexOf("editor.php") == -1)  // if we're not editing the page, display a randomly-selected quote
        {
            var quote = Math.round(Math.random() * (quotes.length - 1));
            quotes[quote].style.display = "block";
        }
        else                                                  // otherwise turn them all on so we can edit them
        {
            for(var i = 0; i < quotes.length; i++)
                quotes[i].style.display = "block";
        }
    }
}


function setIframeHeight(iframeName)
{
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}


function getDocHeight(doc)
{
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}



// Based on http://surguy.net/menu/highlight.html
function getLeaf(url) {
  return url.substring(url.lastIndexOf("/")+1);
}

function setNav() {
  if(!document.getElementById("colleft"))
      return;

  var currentLocation = getLeaf(document.location.href);
  var menu = document.getElementById("navtop");
  var Links = menu.getElementsByTagName("a");

  for (var i=0; i<Links.length; i++) {
    var currentHref = Links[i].getAttribute("href");
    var currentLeafName = getLeaf(currentHref);
    if (currentLeafName==currentLocation) {
      // Setting class is needed for Mozilla compatibility - className appears to be correct 
      // according to the DOM spec
      Links[i].setAttribute("class", "currentpage");
      Links[i].setAttribute("className", "currentpage");
    }
  }
}

