var idlist = {
   atopic:1, btopic:1, ctopic:1, dtopic:1, etopic:1, 
   ftopic:1, gtopic:1, htopic:1, itopic:1, jtopic:1,
   ktopic:1, ltopic:1, mtopic:1, ntopic:1, otopic:1,
   ptopic:1, qtopic:1, rtopic:1, stopic:1, ttopic:1,
   utopic:1, vtopic:1, wtopic:1, xtopic:1, ytopic:1,
   ztopic:1
};

function topicSetup() {
   var cookiestate = document.cookie;
   if (cookiestate == null || cookiestate.length == 0) {
      return false;
   }
   var pos = cookiestate.indexOf("state=");
   var start = pos + 6;
   var end = cookiestate.indexOf(";", start);
   if (end == -1) end = cookiestate.length;
   var idstate = cookiestate.substring(start, end);
   idstate = unescape(idstate);
   if (idstate != null) {
      var i = 0;
      for (var x in idlist) {
         idlist[x] = idstate.charAt(i);
         if (idlist[x] == "1") {
            alert("block: idlist[" + x + "] = " + idlist[x]);
            var e = document.getElementById(x);
            if (e == null) continue;
            e.style.display = "block";
            document.images[i].src = "images/collapse.gif";
            document.images[i].title = "Collapse Topic List";
         } else {
            alert("none: idlist[" + x + "] = " + idlist[x]);
            var e = document.getElementById(x);
            if (e == null) continue;
            e.style.display = "none";
            document.images[i].src = "images/expand.gif";
            document.images[i].title = "Expand Topic List";
         }
         ++i;
      }
   }
}

function topicUnload() {
   var idstate = "";
   for (var x in idlist) {
      idstate += idlist[x];
   }
   document.cookie = "state=" + escape(idstate);
}

function collapseAll() {
   for (var x in idlist) {
      var e = document.getElementById(x);
      if (e == null) continue;
      e.style.display = "none";
      idlist[x] = 0;
   }
   for (var i = 0; i < document.images.length; ++i) {
      document.images[i].src = "images/expand.gif";
      document.images[i].title = "Expand Topic List";
   }
}

function expandAll() {
   for (var x in idlist) {
      var e = document.getElementById(x);
      if (e == null) continue;
      e.style.display = "block";
      idlist[x] = 1;
   }
   for (var i = 0; i < document.images.length; ++i) {
      document.images[i].src = "images/collapse.gif";
      document.images[i].title = "Collapse Topic List";
   }
}

function collapse(t, i) {
   if (idlist[t] != undefined) {
      if (idlist[t]) {
         var e = document.getElementById(t);
         if (e != null) {
            e.style.display = "none";
            idlist[t] = 0;
            i.src = "images/expand.gif";
            i.title = "Expand Topic List";
         }
      } else {
         var e = document.getElementById(t);
         if (e != null) {
            e.style.display = "block";
            idlist[t] = 1;
            i.src = "images/collapse.gif";
            i.title = "Collapse Topic List";
         }
      }
   }
}

function collapse_key(t, i, e) {
   k = 0;
   if (!e) {   /* Internet Explorer */
      e = window.event;
      k = e.keyCode;
   } else if (e.which == undefined) {  /* Internet Explorer */
      k = e.keyCode;
   } else {           /* Netscape or Firefox */
      k = e.which;
   }
   if (k == 13) {
      collapse(t, i);
      return true;
   }
   return false;
}


