﻿
// Register the namespace for the control.
Type.registerNamespace('HttpNet2.Webmail');

//ProgressMessageData = function(text,onDoneType,onDoneText) { 
//  this._text = text;
//  this._onDoneType = onDoneType;
//  this._onDoneText = onDoneText;
//  
//  this.get_text = function() {
//    return this._text;
//  };

//  this.get_onDoneType = function() {
//    return this._onDoneType;
//  };

//  this.get_onDoneText = function() {
//    return this._onDoneText;
//  };
//    
//};


//
// Define the control properties.
//
HttpNet2.Webmail.PageMessage = function(element) { 
    HttpNet2.Webmail.PageMessage.initializeBase(this, [element]);
    
    this._doneAfter = 0;
    this._onDone = null;
    this._onInit = null;

    this._containerId = null;
    this._text = null;
    this._cssClass = null;
   
    this._doneText = null;
    this._doneCssClass = null;
    

    this._tm = null;
    this._action = null;
    
    this._t = 0;
    this._d = 1;
    
    this._fadeInDelay = 40;
    this._fadeInStep = 0.3;
    this._fadeOutDelay = 20;
    this._fadeOutStep = 0.06;
    
    this._isVisible = false;

}

//
// Create the prototype for the control.
//

HttpNet2.Webmail.PageMessage.prototype = {

    initialize : function() {
        HttpNet2.Webmail.PageMessage.callBaseMethod(this, 'initialize');
        
      this.get_element().style.visibility = 'hidden';
      if (this._text != null)
        $get( this._containerId).innerHTML = this._text;
        //this.get_element().innerHTML = this._text;
        
      if (typeof(this._onInit)=='function')
      {
        this._onInit();
      }
      
    },
    
    dispose : function() {
        $clearHandlers(this.get_element());
        HttpNet2.Webmail.PageMessage.callBaseMethod(this, 'dispose');
    },
    
    fade_in : function()
    {
      if (this._tm != null)
        window.clearTimeout(this._tm);
      this._isVisible = true;
      this._t += this._fadeInStep;
      if (this._t > 1.0) this._t = 1.0;
      with (this.get_element())
      {
        style.visibility = 'visible';
		    style.filter = 'alpha(opacity='+String(100*this._t)+')';
		    style.opacity = this._t;
      }
      if (this._t < 1.0)
      {
        this._tm = window.setTimeout('$find("'+this.get_id()+'").fade_in()', this._fadeInDelay);
      }
      else
      {
        if (this._doneAfter > 0)
          this._tm = window.setTimeout('$find("'+this.get_id()+'").done()', this._doneAfter);
      }
    },
    
    fade_out : function()
    {
      if (this._tm != null)
        window.clearTimeout(this._tm);
      this._t -= this._fadeOutStep;
      if (this._t < 0) this._t = 0;
      if (this._t > 0)
      {
        with (this.get_element())
        {
          style.visibility = 'visible';
		      style.filter = 'alpha(opacity='+String(100*this._t)+')';
		      style.opacity = this._t;
        }
        this._tm = window.setTimeout('$find("'+this.get_id()+'").fade_out()', this._fadeOutDelay);
      }
      else
      {
        this._isVisible = false;
        this.hide();
        if (typeof(this._onDone) == 'function')
          this._onDone();
      }
    },
    
    start : function(text) {
      if (this._tm != null)
        window.clearTimeout(this._tm);
      //if (this._isVisible)
      //{
      //  this.cancelDone();
      //}
      //else
      {
        if (this._cssClass != null)
          this.get_element().className = this._cssClass;
        this.get_element().style.visibility = 'hidden';
        if (typeof(text) == 'undefined') text = 'Loading ...';
        $get(this._containerId).innerHTML = text;
        this._t = 0;
        this.fade_in();
      }
    },
    
    done : function()
    {
      if (this._tm != null)
        window.clearTimeout(this._tm);
      if (this._isVisible)
      {
        if (this._doneText != null)
          $get(this._containerId).innerHTML = this._doneText;
        if (this._doneCssClass != null)
          this.get_element().className = this._doneCssClass;
        this._t = 1;
        this._tm = window.setTimeout('$find("'+this.get_id()+'").fade_out()', 100);
      }
      else
      {
        this.hide();
      }
    },
    
    cancelDone: function()
    {
      if (this._tm != null)
        window.clearTimeout(this._tm);
      if (this._isVisible)
      {
        with (this.get_element())
        {
          style.visibility = 'visible';
		      style.filter = 'alpha(opacity='+String(100)+')';
		      style.opacity = 1;
        }
      }
    },
    
    hide : function()
    {
      this.get_element().style.visibility = 'hidden';
    },
    
    get_isVisible : function()
    {
      return this._isVisible;
    },
    
   
    
    //
    // Event delegates
    //
   
 
//    _onClick : function(e) {
//        if (this.get_element() && !this.get_element().disabled && this._enabledState) 
//        {
//          aspPostBack(this.get_id());
//        }
//    },
        

    //
    // Control properties
    //
    
    // Behavior
    
    get_doneAfter : function() {
       return this._doneAfter;
    },
    set_doneAfter : function(value) {
       this._doneAfter = value;
    },
    
    get_onDone : function() {
       return this._onDone;
    },
    set_onDone : function(value) {
       this._onDone = value;
    },
      
    get_onInit : function() {
       return this._onInit;
    },
    set_onInit : function(value) {
       this._onInit = value;
    },
    
    // Appearance

    get_text : function() {
       return this._text;
    },
    set_text : function(value) {
       this._text = value;
    },

    get_containerId : function() {
       return this._containerId;
    },
    set_containerId : function(value) {
       this._containerId = value;
    },

    get_doneText : function() {
       return this._doneText;
    },
    set_doneText : function(value) {
       this._doneText = value;
    },
    
    get_cssClass : function() {
       return this._cssClass;
    },
    set_cssClass : function(value) {
       this._cssClass = value;
    },

    get_doneCssClass : function() {
       return this._doneCssClass;
    },
    set_doneCssClass : function(value) {
       this._doneCssClass = value;
    }
    
}

// Register the class as a type that inherits from Sys.UI.Control.
HttpNet2.Webmail.PageMessage.registerClass('HttpNet2.Webmail.PageMessage', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();



