function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  var newnext = "javascript:next([";
  var nextpage;
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
    var id = a.id;
    var title = a.title;
    if (href.indexOf("#header") != -1) { // back to top
      a.className = "alt";
    } else if ((href.indexOf("#") != -1) && (href.indexOf("header") == -1)) { // jump ref
      var index = href.indexOf("#") + 1;
      if(href.substring(index) != '')
      {
        newnext = newnext + "'" + href.substring(index) +"',";
        href = "javascript:show('" + href.substring(index) + "');";
      }
      a.setAttribute("href",href);
    } else if(id == "Next") {
      nextpage = href;
    }
  }

  //loop through and fix the next button
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
    var id = a.id;
    if(id == "Next")
    {
      href = newnext + "'" + nextpage + "']);";
      a.setAttribute("href",href);
      break;
    }
  }
}

function hideDivs(exempt)
{
  exemptid = ["header","footer","idxheader","r_idxheader","r_modcntdiv","modulecontentdiv","leftdiv","simplemodcntdiv","logo","coursename","moduletitlediv","moduletitle","modcntdiv","langheader","langvalues","coursehome","nextmodule","modcnt","sectionnav",exempt];
  if (!document.getElementsByTagName) return null;
  if (!exempt) exempt = "";
  var divs = document.getElementsByTagName("div");
  for(var i=0; i < divs.length; i++)
  {
    var div = divs[i];
    var id = div.id;
    var hideid = true;
    if(id == "") id = "header";
    for(var j=0;j<exemptid.length; j++)
    {
      if(exemptid[j] == id)
      {
        hideid=false;
        break;
      }
    }
    if(hideid) div.className = "hidden";
  }
}

function next(what)
{
  var nextpage = what[what.length-1];
  if (!document.getElementById)
  {
    location = nextpage;
  }
  else
  {
    var found=false;
    //only check the links, last one is the next page
    for(var i=0; i<what.length-1; i++)
    {
      var sectionname = document.getElementById(what[i]);

      if(sectionname.className == "")
      {
        found=true;
        if(what[i+1] == nextpage) 
          location = nextpage;
        else
          show(what[i+1]);
        break;
      }
    }
    if(!found) location = nextpage;
  }
}

function show(what)
{
  if (!document.getElementById) return null;
  showWhat = document.getElementById(what);
  showWhat.className = "";
  hideDivs(what);
}

function sendFocus(what)
{
  var obj = document.getElementById(what);
  if(obj) obj.focus();
}

window.onload = function()
{
  fixLinks();
  hideDivs("firstlink");
  sendFocus("navfirstlink");
}