/***
* CheckBox Control
*/
var CtlCheckBox = Class.create({
 initialize: function(wrap_class, bgcolor_on){
  this.wrap_class = wrap_class;
  this.bgcolor_on = bgcolor_on;
  this.wrap_styles = $H({});
 },
 load: function(){
  var h = $H({});
  this.wrapElments = $$('.' + this.wrap_class);
  this.wrapElments.each(function(e){
   var chkbox = e.down('input[type="checkbox"]');
   if(chkbox){
	h.set(chkbox.identify(), e.identify());
	chkbox.observe('click', function() {
	 this.setColor();
	}.bind(this));
	chkbox.observe('change', function() {
	 this.setColor();
	}.bind(this));
	this.wrap_styles.set(e.identify(), e.getStyle('background-color'));
   }
  }.bind(this));
  this.checbox2wrap = h;
  this.setColor();
 },
 showAll: function(){
  this.checbox2wrap.each(function(h){
   $(h.value).show();
  });
 },
 hideAll: function(){
  this.checbox2wrap.each(function(h){
   $(h.value).hide();
  });
 },
 onAll: function(){
  this.checbox2wrap.each(function(h){
   $(h.key).checked = true;
  });
  this.setColor();
 },
 offAll: function(){
  this.checbox2wrap.each(function(h){
   $(h.key).checked = false;
  });
  this.setColor();
 },
 setAll: function(checked){
  this.checbox2wrap.each(function(h){
   $(h.key).checked = checked;
  });
  this.setColor();
 },
 setColor: function(){
  if(!this.bgcolor_on) return;
  this.checbox2wrap.each(function(h){
   var chk = $(h.key);
   if(chk.checked){
	$(h.value).setStyle('background-color:' + this.bgcolor_on);
   }else{
	$(h.value).setStyle('background-color:' + this.wrap_styles.get(h.value));
   }
  }.bind(this));
 },
 showChecked: function(){
  this.checbox2wrap.each(function(h){
   var chk = $(h.key);
   if(chk.checked){
	$(h.value).show();
   }else{
	$(h.value).hide();
   }
  });
 },
 isChecked: function(){
  var ret = false;
  this.checbox2wrap.each(function(h){
   var chk = $(h.key);
   if(chk.checked){
	ret = true
	return;
   }
  });
  return ret;
 },
 getChecked: function(){
  var ret_arr = [];
  this.checbox2wrap.each(function(h){
   var chk = $(h.key);
   if(chk.checked){
	ret_arr.push(chk.value);
   }
  });
  return ret_arr;
 }
});