﻿// I'll wish I had documented this better in the future.  Oh well.
Type.registerNamespace('ECMS.Controls');

ECMS.Controls.DisableButtonBehavior = function(element) {

    ECMS.Controls.DisableButtonBehavior.initializeBase(this, [element]);
    
    this._WaitTextValue = null;
    this._WaitImageURLValue = null;
}

ECMS.Controls.DisableButtonBehavior.prototype = {

  initialize : function() 
  {
      ECMS.Controls.DisableButtonBehavior.callBaseMethod(this, 'initialize');

      this.registerPartialUpdateEvents();
  },

  dispose : function() 
  {
      ECMS.Controls.DisableButtonBehavior.callBaseMethod(this, 'dispose');
  },
  
  get_WaitText : function()
  {
    return this._WaitTextValue;
  },
  
  set_WaitText : function(value)
  {
    this._WaitTextValue = value;
  },
  
  get_WaitImageURL : function()
  {
    return this._WaitImageURLValue;
  },
  
  set_WaitImageURL : function(value)
  {
    this._WaitImageURLValue = value;
  },
  
  _partialUpdateBeginRequest : function(sender, e) 
  {
    $get(e._postBackElement.id).disabled = true;
    
    if (e._postBackElement.type == "submit" && this._WaitTextValue != "")
    {
      this._oldValue = $get(e._postBackElement.id).value;
      $get(e._postBackElement.id).value = this._WaitTextValue;
    }
    else if (e._postBackElement.type == "image" && this._WaitImageURLValue != "")
    {
      this._oldImageURL = $get(e._postBackElement.id).src;
      $get(e._postBackElement.id).src = this._WaitImageURLValue;
    }
  },
  
  _partialUpdateEndRequest : function(sender, e)
  {
    // Check to make sure the item hasn't been removed during the postback.
    if ($get(sender._postBackSettings.sourceElement.id) != null)
    {
      $get(sender._postBackSettings.sourceElement.id).disabled = false;
      
      if (sender._postBackSettings.sourceElement.type == "submit" && this._WaitTextValue != "")
      {
        $get(sender._postBackSettings.sourceElement.id).value = this._oldValue;
      }
      else if (sender._postBackSettings.sourceElement.type == "image" && this._WaitImageURLValue != "")
      {
        $get(sender._postBackSettings.sourceElement.id).src = this._oldImageURL;
      }
    }
  }
}

ECMS.Controls.DisableButtonBehavior.registerClass('ECMS.Controls.DisableButtonBehavior', AjaxControlToolkit.BehaviorBase);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();