function show(theid) {
    var switch_id = document.getElementById(theid);
    var button_id = document.getElementById(theid+'Button');
    button_id.className = 'buttonminus';
    switch_id.className = 'shown';
}

function hide(theid) {
    var switch_id = document.getElementById(theid);
    var button_id = document.getElementById(theid+'Button');
    button_id.className = 'buttonplus';
    switch_id.className = 'hidden';
}

function setCookie(key,value) {
  var url = document.URL;
  var string = key+"="+value;
  var idx = url.indexOf("://");
  var idx2;
  if (idx!=-1) {
    idx2 = url.indexOf("/",idx+3);
    if (idx2==-1)
      idx2=url.length;
    string = string+";domain="+url.substring(idx+3,idx2);
  }
  else {
    idx2 = url.indexOf(":")+1;
  }
  var idx3 = url.lastIndexOf("/");
  if (idx3!=-1) {
    string = string+";path="+url.substring(idx2,idx3+1);
  }
  document.cookie=string;
}

function toggleSheet(theid) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    if (switch_id.className == 'hidden') {
      openSheet(theid);
    } else {
      closeSheet(theid);
    }
  }
}

function closeSheet(theid) {
      hide(theid);
      setCookie("toggle"+theid,'hide');
}

function openSheet(theid) {
  show(theid);
  setCookie("toggle"+theid,'show');
}

function put(assignment,offset) {
  var idx=assignment.indexOf("=",offset);
  if (idx!=-1) {
    var key=assignment.substring(offset,idx);
    if (key.substring(0,6)=="toggle") {
      var theid=key.substring(6,key.length);
      var end=assignment.indexOf(";",offset);
      if(end==-1)
        end=assignment.length;
      var value=assignment.substring(idx+1,end);
      if (value == "show")
        show(theid);
      else if (value == "hide")
        hide(theid);
    }
  }
}

function setMenu() { // read cookies and set menus to last visited state
  if (document.getElementById) {
    var cookies = document.cookie;
    var start=0;
    while(true) {
      var idx=cookies.indexOf(" ",start);
      put(cookies,start);
      if(idx==-1) {
        return;
      }
      start=idx+1;
    }
  }
}

