/**
 * Checkboxer is a JavaScript object to handle a single checkbox that should
 * set and unset a form value when it is checked and unchecked.
 *
 * Arguments:
 *  checkbox        - the checkbox itself
 *  property        - the form element to set on checkbox changes
 *  checkedValue    - the value to set when checked
 *  uncheckedValue  - the value to set when unchecked
 *  debug           - optional argument, when true, alerts when property is set
 */
function Checkboxer(checkbox, property, checkedValue, uncheckedValue, debug, additionalOnClick)
{
  this.form              = checkbox.form;
  this.checkbox          = checkbox;
  this.property          = property;
  this.checkedValue      = checkedValue;
  this.uncheckedValue    = uncheckedValue;
  this.debug             = debug;

  if (this.checkbox.onclick == null)
  {
    this.checkbox.checkboxer = this;
    this.checkbox.onclick = function() { this.checkboxer.setProperty(); }
  }

  this.setCheckbox();
}

Checkboxer.prototype.setProperty = function()
{
  if (this.checkbox.checked) this.property.value = this.checkedValue;
  else                       this.property.value = this.uncheckedValue;
  if (this.debug) alert(this.property.name + " = " + this.property.value);
}

Checkboxer.prototype.setCheckbox = function()
{
  this.checkbox.checked = (this.checkedValue == this.property.value);
}