﻿
Type.registerNamespace('DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates');

/// <summary>
/// LocalRatesExtender
///    Extender that helps control the local rates container.  This behavior sets up
///      public behavior methods for hidding and showing the local rates panel.  The container
///      must support the style.display property.  This extender control also blanks out
///      the local rates text box, if exists.
/// </summary>
/// <remarks>
///    properties: 
///      {name: 'TargetControlID', type: String} : Default value for extenders identifing the container control
///      {name: 'LocalRatesTextBoxId', type: String} : id value for identifing the Textbox control
///
/// </remarks>
/// <history>
///     <change date="01/15/2007 12:00:00" ticket="">
///         <author>Steven Berenbrock</author>
///         <description>Initial version.</description>
///     </change>
/// </history>

DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior = function(element) {
    DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.initializeBase(this, [element]);
    ///<summary>LocalRatesBehavior Extender</summary>
    ///<param name="element">Associated element</param>

    //Properties
    this._localRatesTextBoxId = null;
    this._containerExpanded = false;    
}

DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.prototype = {
    //*****************************************************************
    //Override methods
    //
    initialize : function() {
        DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.callBaseMethod(this, 'initialize');

        //var targetElement = this.get_element();
        
        // Check our client state.  If it's present,
        // that means this is a postback, so we restore the state.
        var lastState = DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.callBaseMethod(this, 'get_ClientState');                
        if (lastState && lastState != "") {
            var wasExpanded = Boolean.parse(lastState);  
            if (this._containerExpanded != wasExpanded) {
                this._containerExpanded = wasExpanded;
            }
        }        
        if (this._containerExpanded) {
            this.show();
        }        
        else {
            this.hide();
        }
    },

    dispose : function() {

        DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.callBaseMethod(this, 'dispose');
    },

    //*****************************************************************
    // Property get/set methods
    //
    get_LocalRatesTextBoxId : function() {
        return this._localRatesTextBoxId;
    },

    set_LocalRatesTextBoxId : function(value) {
        this._localRatesTextBoxId = value;
    },
    
    get_ContainerExpanded : function() {
        return this._containerExpanded;
    },

    set_ContainerExpanded : function(value) {
        this._containerExpanded = value;
    },
    
    
    //*****************************************************************
    // Custom methods
    //
    _setupState : function(isExpanded) {
        /// <summary>Get all the state set consistently when we change modes</summary>
        /// <param name="isExpanded" type="Boolean">
        /// True to setup the state as if we're exapnded, false to setup the state as if we're collapsed
        /// </param>

        // set our member variable and set the client state to reflect it
        if (this._containerExpanded != isExpanded) {
            this._containerExpanded = isExpanded;        
        }
        DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.callBaseMethod(this, 'set_ClientState', [this._containerExpanded.toString()]);                        
    },
    
    _getLocalRatesTextBox : function() {
        ///<summary>Private method getLocalRatesTextBox</summary>
        ///<remarks>Gets the value attribute of element identified by the localRatesBoolId</remarks>
        var localRatesTextboxElement = null;
        if (this._localRatesTextBoxId) {
            localRatesTextboxElement = $get(this._localRatesTextBoxId);
        }    
        return localRatesTextboxElement;
    },    

    reset : function() {
        ///<summary>Public method reset</summary>
        ///<remarks>Set the textbox value to blank if textbox found</remarks>
        var localRatesTextboxElement = this._getLocalRatesTextBox();
        if (localRatesTextboxElement) {
            localRatesTextboxElement.value = "";
        }
    },
    
    show : function() {
        ///<summary>Public method show</summary>
        ///<remarks>Shows the local rates container using display style block</remarks>
        var targetElement = this.get_element();
        targetElement.style.display = 'block';
        this._setupState(true);
     },  
     
    hide : function() {
        ///<summary>Public method hide</summary>
        ///<remarks>hides the local rates container using display style none</remarks>
        var targetElement = this.get_element();
        targetElement.style.display = 'none';
        this._setupState(false);
     }    
}

DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior.registerClass('DTG.Dollar.Web.Consumer.Common.Ajax.LocalRates.LocalRatesBehavior', AjaxControlToolkit.BehaviorBase);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();