
Type.registerNamespace("CZScripts");

CZScripts.CO2Editor = function(element) {    
    CZScripts.CO2Editor.initializeBase(this, [element]);   
    
    this.set_visibilityMode(Sys.UI.VisibilityMode.collapse);
    this.CO2 = 0.0;
    this.Output = "";
}

CZScripts.CO2Editor.prototype = {

    initialize: function() 
    {       
      CZScripts.CO2Editor.callBaseMethod(this, 'initialize');
    },
    
   set_CO2: function(value) {
      this.CO2 = value;

      // Update the output label
      if (isNaN(this.CO2)) 
         $setText($get(this.Output), "----");
      else
         $setText($get(this.Output), value.toFixed(2));
      
      // Trigger updated event
      this.raise_Updated();      
   },
   
   get_CO2: function() {
      return this.CO2;
   },
    
    // Create add and remove accessors for the updated event.
    add_updated: function(handler) {
        this.get_events().addHandler("updated", handler);
    },
    remove_updated: function(handler) {
        this.get_events().removeHandler("updated", handler);
    },

    // Create a function to raise the updated event.
    raise_Updated: function() {
        var h = this.get_events().getHandler('updated');
        if (h) h(this, Sys.EventArgs.Empty);
    },
    
    // override the set_visible call so we can trigger update
    set_visible: function(value)
    {
      CZScripts.CO2Editor.callBaseMethod(this, 'set_visible', [value]);
      // Trigger updated event
      this.raise_Updated();            
    },
    
    parseDouble: function(str)
    {
      var regex = /^[0-9]*(\.[0-9]+)?$/; 
      if (regex.test(str))
         return parseFloat(str);
      else
         return NaN;
    },

    parseCurrency: function(str)
    {
      var regex = /^[0-9]*(\.[0-9][0-9])?$/; 
      if (regex.test(str))
         return parseFloat(str);
      else
         return NaN;
    }
}

CZScripts.CO2Editor.registerClass('CZScripts.CO2Editor', Sys.UI.Control);







