function toggle_year() {
  clicked_li = this.parentNode;
  if (clicked_li.className == "collapsed")
    clicked_li.className = "";
  else
    clicked_li.className = "collapsed";
  return true;
}

div = document.getElementById("archive");

for (top_ul = div.firstChild; top_ul; top_ul = top_ul.nextSibling) {
  if (top_ul.tagName == 'ul' || top_ul.tagName == 'UL')
    break;
}

current_year = null;
current_year_li = null;
current_year_ul = null;

for (li = top_ul.firstChild; li; li = next) {
  next = li.nextSibling;
  if (li.tagName != 'li' && li.tagName != 'LI')
    continue;
  for (a = li.firstChild; a; a = a.nextSibling) {
    if (a.tagName == 'a' || a.tagName == 'A')
      break;
  }
  if (!a)
    continue;
  text = a.firstChild.nodeValue;
  split = text.split("\xa0", 2);
  month = split[0];
  year = split[1];
  a.firstChild.nodeValue = month;
  if (year != current_year) {
    current_year = year;
    current_year_li = document.createElement('li');
    text = document.createTextNode(year);
    a = document.createElement('a');
    a.href = "javascript:;";
    a.onclick = toggle_year;
    a.appendChild(text);
    current_year_li.appendChild(a);
    current_year_li.className = 'collapsed';
    current_year_ul = document.createElement('ul');
    current_year_li.appendChild(current_year_ul);
    top_ul.insertBefore(current_year_li, li);
  }
  current_year_ul.appendChild(li);
}
