﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Windows");

Windows.DropdownContentBehavior = function(element)
{
    Windows.DropdownContentBehavior.initializeBase(this, [element]);
    
    
    this.dropdownOnChangeDelegate = Function.createDelegate(this, this.dropdownOnChange);
    this.topContentRecievedDelegate = Function.createDelegate(this, this._onTopContentRecieved);
    this.middleContentRecievedDelegate = Function.createDelegate(this, this._onMiddleContentRecieved);
    this.bottomContentRecievedDelegate = Function.createDelegate(this, this._onBottomContentRecieved);
    this.errorDelegate = Function.createDelegate(this, this._onErrorContentRecieved);
    
    this.changeTextDivClickDelegate = Function.createDelegate(this, this.changeTextDivClick);
}

Windows.DropdownContentBehavior.prototype = {
    initialize: function()
    {
        Windows.DropdownContentBehavior.callBaseMethod(this, 'initialize');


        this.DropdownControl = document.getElementById(this.get_DropDownControlID());
        this.TopRowContent = document.getElementById(this.get_DropdownContentTopRowID());
        this.MiddleRowContent = document.getElementById(this.get_DropdownContentMiddleRowID());
        this.BottomRowContent = document.getElementById(this.get_DropdownContentBottomRowID());
        this.ChangeTextDiv = document.getElementById(this.get_ChangeTextDivID());

        $addHandler(this.DropdownControl, "change", this.dropdownOnChangeDelegate);
        $addHandler(this.ChangeTextDiv, "click", this.changeTextDivClickDelegate);
        this.dropdownSelectedIndex = 0;

        this.DropdownControl.style.visibility = "hidden";
    },
    dispose: function()
    {
        Windows.DropdownContentBehavior.callBaseMethod(this, 'dispose');
    },


    dropdownOnChange: function()
    {
        for (var index = 0; index < this.DropdownControl.length; index++)
        {
            if (this.DropdownControl[index].selected == true)
            {
                this.dropdownSelectedIndex = index;
                window.location = this.DropdownControl[index].value;
                break;
            }
        }
    },
    changeTextDivClick: function()
    {
        this.DropdownControl.style.visibility = "visible";
    },


    _onTopContentRecieved: function(result, userContext)
    {
        this.TopRowContent.innerHTML = result;
    },
    _onMiddleContentRecieved: function(result, userContext)
    {
        this.MiddleRowContent.innerHTML = result;
    },
    _onBottomContentRecieved: function(result, userContext)
    {
        this.BottomRowContent.innerHTML = result;
    },
    _onErrorContentRecieved: function()
    {
    },
















    //Properties:
    get_DropdownContentTopRowID: function()
    {
        return this._DropdownContentTopRowID;
    },
    set_DropdownContentTopRowID: function(value)
    {
        if (this._DropdownContentTopRowID != value)
        {
            this._DropdownContentTopRowID = value;
            this.raisePropertyChanged('DropdownContentTopRowID');
        }
    },
    get_DropdownContentMiddleRowID: function()
    {
        return this._DropdownContentMiddleRowID;
    },
    set_DropdownContentMiddleRowID: function(value)
    {
        if (this._DropdownContentMiddleRowID != value)
        {
            this._DropdownContentMiddleRowID = value;
            this.raisePropertyChanged('DropdownContentMiddleRowID');
        }
    },
    get_DropdownContentBottomRowID: function()
    {
        return this._DropdownContentBottomRowID;
    },
    set_DropdownContentBottomRowID: function(value)
    {
        if (this._DropdownContentBottomRowID != value)
        {
            this._DropdownContentBottomRowID = value;
            this.raisePropertyChanged('DropdownContentBottomRowID');
        }
    },
    get_DropDownControlID: function()
    {
        return this._DropDownControlID;
    },
    set_DropDownControlID: function(value)
    {
        if (this._DropDownControlID != value)
        {
            this._DropDownControlID = value;
            this.raisePropertyChanged('DropDownControlID');
        }
    },
    get_DropdownContentTopRowID: function()
    {
        return this._DropdownContentTopRowID;
    },
    set_DropdownContentTopRowID: function(value)
    {
        if (this._DropdownContentTopRowID != value)
        {
            this._DropdownContentTopRowID = value;
            this.raisePropertyChanged('DropdownContentTopRowID');
        }
    },
    get_ChangeTextDivID: function()
    {
        return this._ChangeTextDivID;
    },
    set_ChangeTextDivID: function(value)
    {
        if (this._ChangeTextDivID != value)
        {
            this._ChangeTextDivID = value;
            this.raisePropertyChanged('ChangeTextDivID');
        }
    },
    get_DropdownContentDiv: function()
    {
        return this._DropdownContentDiv;
    },
    set_DropdownContentDiv: function(value)
    {
        if (this._DropdownContentDiv != value)
        {
            this._DropdownContentDiv = value;
            this.raisePropertyChanged('DropdownContentDiv');
        }
    },
    get_BackgroundImageFilePath: function()
    {
        return this._BackgroundImageFilePath;
    },
    set_BackgroundImageFilePath: function(value)
    {
        if (this._BackgroundImageFilePath != value)
        {
            this._BackgroundImageFilePath = value;
            this.raisePropertyChanged('BackgroundImageFilePath');
        }
    }
}
Windows.DropdownContentBehavior.registerClass('Windows.DropdownContentBehavior', Sys.UI.Behavior);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
