function widgets_checkall(frm) {
  all_checkboxes = $(frm).getInputs('checkbox');
  all_checkbox = all_checkboxes.first();
  elements = all_checkboxes.reject(function(n) { return n.getAttribute('id') == 'all_pages'})
  if (all_checkbox.checked) {
    elements.invoke('setAttribute', 'checked', true);
    $$('.placement').invoke('removeAttribute', 'disabled');
    $$('.should_destroy').value = 1;
  }
  else {
    elements.invoke('removeAttribute', 'checked');
    $$('.placement').invoke('setAttribute', 'disabled', 'disabled');
    $$('.should_destroy').value = 0;
  }
}
function mark_for_destroy(element, hide) {
    $(element).next('.should_destroy').value = 1;
    $(element).up('.' + hide).hide();
}

function toggle_disable(elem) {
  elem = $(elem);
  if (elem.getAttribute('disabled')) {
    elem.removeAttribute('disabled');
    elem.next('.should_destroy').value = 0;
  }
  else {
    elem.setAttribute('disabled', true);
    elem.next('.should_destroy').value = 1;
  }
}

var TreeState = Class.create({
                               initialize: function(reorder_url) {
                                 this.reorder_url = reorder_url;
                               },
                               update: function(element, direction, dropon) {
                                 this.element = element;
                                 this.direction = direction;
                                 this.dropon = dropon;
                               },
                               sendRequest: function () {
                                 new Ajax.Updater('status', this.reorder_url, {
                                                    parameters: 'element=' + this.element.id.replace(/^\D+/,'') + '&direction=' + this.direction + '&dropon=' + this.dropon.id.replace(/^\D+/,'')
                                                  });
                               }});
