Source of faq.js

function loadCategories() {
  Ajax.getContentFromURI("categories.asp",xGetElementById("toctop"),updateCategories);
}
 
function updateCategories(xdata,ul) {
  var catlist = xdata.selectNodes("//Category");
  
  for (var i = 0; i < catlist.length; i++) {
    var li = document.createElement("li");
    xAddClass(li,"collapsed");
    
    var a = document.createElement("a");
    Ajax.copyChildren(catlist[i],a);
    a.id = catlist[i].getAttribute("id");
    a.href = "#";
    a.onclick = expandCategoryToc;
    li.appendChild(a);
    ul.appendChild(li);
  }
}
 
xAddEventListener(window,"load",loadCategories);
 
function expandCategoryToc() {
  var li = this.parentNode; 
  if (li.nodeName.toLowerCase() != "li") { throw("Expected LI element as parent of A element"); }
  if (li.nextSibling && li.nextSibling.nodeName.toLowerCase() == "ul") {
    doExpandOrCollapse(li);
  } else {
    var ul = document.createElement("ul");
    li.parentNode.insertBefore(ul,li.nextSibling);
    Ajax.getContentFromURI("questions.asp?category="+this.id,ul,updateCategoryQuestions);
  }
  return false;
}
 
function updateCategoryQuestions(xdata,ul) {
  var qlist = xdata.selectNodes("//Question");
  
  for (var i = 0; i < qlist.length; i++) {
    var li = document.createElement("li");
    var a = document.createElement("a");
    Ajax.copyChildren(qlist[i],a);
    a.id = "qa_" + qlist[i].getAttribute("id");
    a.href = "#";
    a.onclick = displayQAPair;
    li.appendChild(a);
    ul.appendChild(li);
  }
  if (ul.previousSibling) xAddClass(ul.previousSibling,"expanded");
}
 
function doExpandOrCollapse(li) {
  // get second-level UL element
  var tocLev2 = li.nextSibling; 
  if (tocLev2.nodeName.toLowerCase() != "ul") return;
 
  var collapse = tocLev2.style.display == "";
  li.className = collapse ? "collapsed" : "expanded";
  tocLev2.style.display = collapse ? "none" : "";
  return false;
}
 
function displayQAPair() {
  var qadiv = xGetElementById("faq");
  if (!qadiv) {
    qadiv = document.createElement("div");
    qadiv.id = "faq";
    xAddClass(qadiv,"floatLeftBox");
    var tocdiv = xGetElementById("toc"); if (!tocdiv) return;
    tocdiv.parentNode.insertBefore(qadiv,tocdiv.nextSibling);
  }
  Ajax.getContentFromURI("answer.asp?question="+this.id.replace(/qa_/,""),qadiv,updateAnswer);
  return false;
}
 

Top

function updateAnswer(xdata,qadiv) {
  var dl = document.createElement("dl");
  var dt = document.createElement("dt");
  var dd = document.createElement("dd");
  
  Ajax.copyChildren(xdata.selectSingleNode("//Question"),dt);
  Ajax.copyChildren(xdata.selectSingleNode("//Answer"),dd);
  dl.appendChild(dt);
  dl.appendChild(dd);
  qadiv.appendChild(dl);
}