
function fill_category_list() {
  clear_lists_after_level(0);
  var opts = [];
  for (var x=0; x<categories.length; x++) {
    opts[x] = { name: categories[x]['name'], id: categories[x]['id'] };
  }
  fill_select('category_list', opts);
}

function fill_topic_list(category) {
  clear_lists_after_level(1);
  var opts = [];
  var topic = topics[category];
  if (!topic) return; // some categories have no topics

  for (var x=0; x<topic.length; x++) {
    opts[x] = { name: topic[x]["name"], id: topic[x]["id"] };
  }
  fill_select('topic_list', opts);
}

function fill_subtopic_list(topic) {
  clear_lists_after_level(2);
  var category = document.getElementById("category_list");
  category = category.options[category.selectedIndex].value;

  var subtopic = subtopics[category+"|"+topic];
  if (!subtopic) return;

  var opts = [];
  for (var x=0; x<subtopic.length; x++) {
    opts[x] = { name: subtopic[x]["name"], id: subtopic[x]["id"] };
  }
  fill_select('subtopic_list', opts);
}

function clear_lists_after_level(level) {
  // if level==0, we want to clear all 3 lists so the "" value is important;
  var lists = ["", "category_list", "topic_list", "subtopic_list"];
  for (var x=level+1; x<lists.length; x++) {
    var node = document.getElementById(lists[x]);
	if (node){
	    node.options.length=0;
	    node.style.background = '#dddddd';  //visually indicate list is no longer active
	}
  }
}

function fill_select(nodeID, opts) {
  var select = document.getElementById(nodeID);
  if (select){
	  select.options.length = 0; // clear existing
	  select.style.background = '#FFFFFF'; //visually indicate that select has been activated
	  for (x=0; x<opts.length; x++) {
    	// IE needs both text & value params to Option;
	    select.options[select.options.length] = new Option(opts[x]["name"], opts[x]["id"]);
	}
  }
}

function init() {
  fill_category_list();
}

function show_faq(number) {
  for(var x=1; x<=num_answers; x++) {
    var node = document.getElementById('faq_answer'+x);
	var faq_on = document.getElementById('faq_on'+x);
	var faq_off = document.getElementById('faq_off'+x);
    node.style.display = 'none';
	faq_on.style.display = '';
	faq_off.style.display = 'none';	
  }
  document.getElementById('faq_answer'+number).style.display = '';
  document.getElementById('faq_on'+number).style.display = 'none';
  document.getElementById('faq_off'+number).style.display = '';  
}
