
Type.registerNamespace("CZScripts");

CZScripts.Visibility = function() {    
    CZScripts.Visibility.initializeBase(this);   

    this.Target = null;
    this.Inputs = "";
    this.TurnOn = true;
    this.ReverseAction = true;
    
    this.delegates = [];
}

CZScripts.Visibility.prototype = {

   initialize: function() 
    {       
      CZScripts.Visibility.callBaseMethod(this, 'initialize');

      var oneWasChecked = false; 
      for (var i=0; i<this._inputs.length; i++)
      {
         var rb = $get(this._inputs[i])

         if (rb.checked) oneWasChecked = true;

         // Hook clicks
         this.delegates.push(new CZScripts.Delegate(rb, 'click', this.doAction, this));
      }      
      
      if (oneWasChecked) { $find(this.Target).set_visible(this.TurnOn); } 
      else { if (this.ReverseAction) { $find(this.Target).set_visible(!this.TurnOn); } }
      
   },
   
       // Release resources before control is disposed.
   dispose: function() {   
      for (var i in this.delegates)
      {
         this.delegates[i].dispose();
      }        
      CZScripts.Visibility.callBaseMethod(this, 'dispose');
   },
    
   get_Inputs: function() { return ""; },
   set_Inputs: function(value)
   {
      this._inputs = value.split(";");
   },
   
   doAction: function(e)
   {
      if (e.target.checked) 
      { 
         $find(this.Target).set_visible(this.TurnOn); 
      } 
      else if (this.ReverseAction) 
      { 
         $find(this.Target).set_visible(!this.TurnOn); 
      }
   }
}

CZScripts.Visibility.registerClass('CZScripts.Visibility', Sys.Component);








