/*
Subject : UI Web component of Form CheckBox
Author : Yong-dae Kim
Date : 2006-09-15
*/

var xCheckBox = Class.create();
xCheckBox.prototype = {
  initialize: function(objId) { //  initialize
    this.obj = $(objId);
    if(this.obj.type == 'checkbox') {
      this.Parent = this.obj.parentNode;
      this.reNewal = document.createElement('IMG');
      this.reNewal.setAttribute('align','absmiddle');
      this.check_On = '/Images/uiComponent/form/checkbox/checked.png';
      this.check_Off = '/Images/uiComponent/form/checkbox/default.png';

      this.Parent.insertBefore(this.reNewal, this.obj);
      this.obj.style.display='none';
      this.reNewal.src=(this.obj.checked==true)?this.check_On:this.check_Off;
      this.reNewal.style.width='18px';
      this.reNewal.style.height='18px';
      this.reNewal.style.padding='1px';

      this.reNewal.onmouseup = this.reversal.bindAsEventListener(this);

      if(typeof this.obj.getAttribute('onclick') == 'string') { // FF, Opera
        this.evtClick = function(e) { eval(this.obj.getAttribute('onclick')); }
        this.reNewal.onclick = this.evtClick.bindAsEventListener(this);
      } else if( typeof this.obj.getAttribute('onclick') == 'function') { // IE
        this.evtClick = eval(this.obj.getAttribute('onclick'));
        this.reNewal.onclick = this.evtClick.bindAsEventListener(this);
      }
    }
  },

  reversal: function(e) { // Event onmouseup
    if(this.obj.checked == false) {
      this.reNewal.src =this.check_On;
      this.obj.checked = true;
    } else {
      this.reNewal.src=this.check_Off;
      this.obj.checked = false;
    }
  }
}

document.write('<style type="text/css">img.gray {filter:Alpha(opacity=30);-moz-opacity: 0.3;opacity:0.3;}</style>');
document.write('<div style="display:none;"><img src="/Images/uiComponent/form/checkbox/default.png" /><img src="/Images/uiComponent/form/checkbox/checked.png" /></div>');
