﻿// README
//
// There are two steps to adding a property:
//
// 1. Create a member variable to store your property
// 2. Add the get_ and set_ accessors for your property
//
// Remember that both are case sensitive!


/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit" />


Type.registerNamespace('OnLineExt.MPFinder');

OnLineExt.MPFinder.CascadingDropDownHiderBehavior = function(element) {
    OnLineExt.MPFinder.CascadingDropDownHiderBehavior.initializeBase(this, [element]);

    // TODO : (Step 1) Add your property variables here
    this._populatedEventHandler = null;
    this._ControlToHideID = null;
    this._HideOnlyText = null;
    this._HideOnlyValue = null;
}
OnLineExt.MPFinder.CascadingDropDownHiderBehavior.prototype = {
    initialize: function() {
        OnLineExt.MPFinder.CascadingDropDownHiderBehavior.callBaseMethod(this, 'initialize');

        if (this._ControlToHideID) {
            this._populatedEventHandler = Function.createDelegate(this, this._overridedOnPopulated);

            this.add_populated(this._populatedEventHandler);

            $get(this._ControlToHideID).style.display = 'none';
        }
    },

    dispose: function() {
        // TODO: Add your cleanup code here

        OnLineExt.MPFinder.CascadingDropDownHiderBehavior.callBaseMethod(this, 'dispose');
    },

    _overridedOnPopulated: function(args) {

        var dispText = this._element.options[this._element.selectedIndex].text;
        
        if (!dispText)
            return;

        var selectedText = dispText.trim();
        var isNeedDisplay = true;

        if ((selectedText == this._loadingText || selectedText == this._promptText || selectedText == this._emptyText) && this._element.options.length <= 1) {
            isNeedDisplay = false;
        } else {
            if ((this._promptText != null && this._promptText != '' && this._element.options.length == 2) || this._element.options[0].length == 1) {
                for (var i = 0; i < this._element.options.length; i++) {
                    var optText = this._element.options[i].text.trim();
                    var optValue = this._element.options[i].value.trim();
                    if (optText == this._HideOnlyText || optValue == this._HideOnlyValue) {
                        isNeedDisplay = false;
                        break;
                    }
                }
            }
        }

        var controlToNeedHide = $get(this._ControlToHideID);
        controlToNeedHide.style.display = (isNeedDisplay) ? 'block' : 'none';
    },

    // TODO: (Step 2) Add your property accessors here
    get_ControlToHideID: function() {
        return this._ControlToHideID;
    },

    set_ControlToHideID: function(value) {
        this._ControlToHideID = value;
    },

    get_HideOnlyText: function() {
        return this._HideOnlyText;
    },

    set_HideOnlyText: function(value) {
        this._HideOnlyText = value;
    },

    get_HideOnlyValue: function() {
        return this._HideOnlyValue;
    },

    set_HideOnlyValue: function(value) {
        this._HideOnlyValue = value;
    }
}
OnLineExt.MPFinder.CascadingDropDownHiderBehavior.registerClass('OnLineExt.MPFinder.CascadingDropDownHiderBehavior', AjaxControlToolkit.CascadingDropDownBehavior);
