function showAnswer(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("answer") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.display = "none";
    } else {
      divs[i].style.display = "block";
    }
  }
}

function prepareFaqs() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("questions")) return false;
  var nav = document.getElementById("questions");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var answerId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(answerId)) continue;
    document.getElementById(answerId).style.display = "none";
    links[i].destination = answerId;
    links[i].onclick = function() {
      showAnswer(this.destination);
      return false;
    }
  }
}

window.onload = prepareFaqs;
