
function getByID (anID) {
  if (document.getElementById)
    return document.getElementById(anID);
  else if (document.layers)
    return document.layers[anID];
  else if (document.all)
    return document.all[anID];
  else
    alert ("getByID: Cannot access elements by ID in this browser" + " " + document.getElementByID(anID));
}

function toggleAnnotationVisibility (anID) {
  var allSpans = document.getElementsByTagName("table");
  for (var i = 0; i < allSpans.length; ++i) {
     var aSpan = allSpans.item(i);
     var idAttr = aSpan.getAttributeNode("id");
     if (idAttr != null && idAttr.value == anID) {
        if (aSpan.style.display == "inline") 
           aSpan.style.display = "none";
        else {
           aSpan.style.display = "inline";
        }
     }
  }
}


function suppressNextNavigation () {
	alert ("suppressNextNavigation ");
  var allSpans = document.getElementsByTagName("a");
	alert ("suppressNextNavigation " + allSpans.length);
  for (var i = 0; i < allSpans.length; ++i) {
     var aSpan = allSpans.item(i);
     var idAttr = aSpan.getAttributeNode("title"); 
     if (idAttr != null && idAttr.value == "next") {
        aSpan.style.display = "none";
     }
  }
}


function endOfLesson (frame) {
    var i = Math.round(45.0*Math.random());
    frame.document.write ("<center>\n");
    if (i < 9) {
	frame.document.write ("<img src=\"_axle/line" + i + ".gif\"/>\n");
    } 
}


// Javascript for lessons
function gotoPage(url) {
  top.location.href = url + ".html";
}

function questionOK(url) {
  alert ("Correct!");
  top.location.href = url + ".html";
}

function questionWrong() {
  alert ("No. Try again.");
}

/*
function checkForAnchorOnOtherPage(anchorName, pageName)
{
 //   alert("checkForAnchorOnOtherPage " + anchorName);
  var hashPart = document.location.hash.substr(1);
  if (anchorName == hashPart) {
     var redirectTo = pageName + ".html#" + hashPart;
     alert("checkForAnchorOnOtherPage " + redirectTo);
     document.location = redirectTo;
  }
}
*/

function checkForXPathOnOtherPage(anchorName, pageName, xpath)
{
  // alert("checkForXPathOnOtherPage: xpath " + xpath);
  var hashPart = document.location.hash;
  // alert("checkForXPathOnOtherPage: hashPart " + hashPart);
  if (xpath == hashPart) {
     var redirectTo = pageName + ".html#" + anchorName;
     // alert("checkForXPathOnOtherPage " + redirectTo);
     document.location = redirectTo;
  }
}

function checkForXPointerHash(anchorName, xpath)
{
  var hashPart = document.location.hash;
  if (xpath == hashPart) {
     var node = getByID(anchorName);

     var n = node;
     var y = 0;
     if (n.offsetParent) {
       for (y = 0; n.offsetParent; n = n.offsetParent ) {
          y += n.offsetTop;
       }
     }
     scrollTo(0,y);
  }
}


function moveFootnote (fromID) {
  /*
  alert ("Moving from ");
  var fromNode = getByID(fromID);
  alert ("Moving from " + fromNode);
  var toNode = document.documentElement.lastChild; // body 
  alert ("Moving from " + fromNode + " to " + toNode);
  if (fromNode != null && toNode != null) {
    var fromChild = fromNode.firstChild;
    while (fromChild != null) {
      toNode.appendChild(fromChild.cloneNode(true));
      var nextChild = fromChild.nextSibling;
      fromNode.removeChild(fromChild);
      fromChild = nextChild;
    }
  }
  */
}

function quickNav(e)
{
  var code;
  if (!e) var e = window.event;
  if (e.keyCode) code = e.keyCode;
  else if (e.which) code = e.which;
  if (code >= 37 && code <= 39) {
      if (code == 37) { // ctrl-shift left-arrow
        gotoPrev();
      } else if (code == 38) { // ctrl-shift up-arrow
        gotoUp();
      } else if (code == 39) { // ctrl-shift right-arrow
        gotoNext();
      }
    // var character = String.fromCharCode(code);
    // alert('Character was ' + character + '  code: ' + code);
    return false;
  } else {
    return true;
  }
}
document.onkeyup = quickNav;
