﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("iucon.sip.Controls");

iucon.sip.Controls.ScooterSelection = function(element) {
    iucon.sip.Controls.ScooterSelection.initializeBase(this, [element]);

    this._clientID = null;
    this._expandHandler = null;
    this._collapseHandler = null;
}

iucon.sip.Controls.ScooterSelection.prototype = {

    initialize: function() {
        iucon.sip.Controls.ScooterSelection.callBaseMethod(this, 'initialize');

        var e = this.get_element();

        var modelDropDown = $get(this._clientID + '_DropDownListModel');
        if (modelDropDown && Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version >= 7) {
            this._expandHandler = Function.createDelegate(this, this._onExpand);
            this._collapseHandler = Function.createDelegate(this, this._onCollapse);

            $addHandler(modelDropDown, 'blur', this._collapseHandler);
            $addHandler(modelDropDown, 'change', this._collapseHandler);
            $addHandler(modelDropDown, 'focusin', this._expandHandler);
        }
    },

    dispose: function() {
        var e = this.get_element();

        var modelDropDown = $get(this._clientID + '_DropDownListModel');
        if (modelDropDown) {
            if (this._collapseHandler) {
                $removeHandler(modelDropDown, 'blur', this._collapseHandler);
                $removeHandler(modelDropDown, 'change', this._collapseHandler);
            }

            if (this._expandHandler) {
                $removeHandler(modelDropDown, 'focusin', this._expandHandler);
            }
        }

        this._collapseHandler = null;
        this._expandHandler = null;
        this._clickHandler = null;

        iucon.sip.Controls.ScooterSelection.callBaseMethod(this, 'dispose');
    },

    get_ClientID: function() {
        return this._clientID;
    },
    set_ClientID: function(value) {
        this._clientID = value;
    },

    _onExpand: function(e) {
        var modelDropDown = $get(this._clientID + '_DropDownListModel');
        if (modelDropDown) {
            modelDropDown.style.width = 400;
        }        
    },

    _onCollapse: function(e) {
        var modelDropDown = $get(this._clientID + '_DropDownListModel');
        if (modelDropDown) {
            modelDropDown.style.width = 185;

            var checkBox = $get(this._clientID + '_CheckBoxScooter');
            if (checkBox) checkBox.focus();
        }    
    }
}

iucon.sip.Controls.ScooterSelection.registerClass('iucon.sip.Controls.ScooterSelection', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
