function image_checkbox(input_id) 
{
  this.img_on_src  = '/i/checkbox/on.gif' ;
  this.img_off_src = '/i/checkbox/off.gif' ;
  this.input       = $(input_id);
  this.image       = $('image_cb_'+ input_id);
  this.label       = $('label_cb_'+ input_id);

  this.image.onclick = function() { eval("checkbox_"+input_id+".flip()"); return false; }
  this.label.onclick = function() { eval("checkbox_"+input_id+".flip()"); return false; } 

  this.preload_img_on_src      = new Image()
  this.preload_img_on_src.src  = this.img_on_src ;
  this.preload_img_off_src     = new Image()
  this.preload_img_off_src.src = this.img_off_src ;

  this.input.style.display = "none";
  this.image.style.display = "block";
  
  this.setState(this.input.checked);
}

image_checkbox.prototype.setState = function(state) 
{
  this.input.checked   = state ;
  this.image.src       = state ? this.img_on_src : this.img_off_src ;
  this.label.className = state ? 'checked' : 'unchecked' ;
}

image_checkbox.prototype.flip = function() 
{
  this.setState(!this.input.checked)
}

function image_checkbox_group(input_id, group) 
{
  this.group       = group ; 
  this.img_on_src  = '/i/checkbox/on.gif' ;
  this.img_off_src = '/i/checkbox/off.gif' ;
  this.input       = $(input_id);
  this.image       = $('image_cb_'+ input_id);
  this.label       = $('label_cb_'+ input_id);

  this.image.onclick = function() { eval("checkbox_"+input_id+".flip()"); return false; }
  this.label.onclick = function() { eval("checkbox_"+input_id+".flip()"); return false; } 

  this.preload_img_on_src      = new Image()
  this.preload_img_on_src.src  = this.img_on_src ;
  this.preload_img_off_src     = new Image()
  this.preload_img_off_src.src = this.img_off_src ;

  this.input.style.display = "none";
  this.image.style.display = "block";
  this.setState(this.input.checked);
}

image_checkbox_group.prototype.setState = function(state) 
{
  this.input.checked   = state ;
  this.image.src       = state ? this.img_on_src : this.img_off_src ;
  this.label.className = state ? 'checked' : 'unchecked' ;
}

image_checkbox_group.prototype.flip = function() 
{
  state = !this.input.checked;

  this.label.innerHTML = state ? 'Снять отметку со всех' : 'Отметить все' ;

  for (var i in this.group)
    eval("checkbox_"+this.group[i]+".setState(state)");

  this.setState(!this.input.checked);
}
