
function checkall (allof) {
  $$('.'+allof).each(function (el) {
    el.checked = true;
  });
}

function uncheckall (allof) {
  $$('.'+allof).each(function (el) {
    el.checked = false;
  });
}

function checktoggle (allof, me) {
  var anyoff = false;
  var boxes = $$('.'+allof);
  boxes.each(function (box) {
    if (!box.checked) anyoff = true;
  });
  if (anyoff) {
    checkall(allof);
    $(me).checked = true;
  } else {
    uncheckall(allof);
    $(me).checked = false;
  }
  
}