﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference path="../ExtenderBase/BaseScripts.js" />
/// <reference path="../Compat/Timer/Timer.js" />
/// <reference path="../Common/Common.js" />

Type.registerNamespace('LF.Controls.Ajax');
LF.Controls.Ajax.LinkedDropdownBehavior = function(element) 
{
    LF.Controls.Ajax.LinkedDropdownBehavior.initializeBase(this, [element]);

    this._changeHandler = null;
}
    
LF.Controls.Ajax.LinkedDropdownBehavior.prototype = { 
	initialize : function() 
	{
		LF.Controls.Ajax.LinkedDropdownBehavior.callBaseMethod(this, 'initialize');
		var e = this.get_element();

		// Create delegates Attach events
		if (!e.readOnly)
		{
			this._changeHandler  = Function.createDelegate(this, this._onChange);
			$addHandler(e, "change", this._changeHandler); 
		}
	}
    //
    // Detach events this.dispose
    //
    , dispose : function() 
    {
        var e = this.get_element();
        if (this._changeHandler) 
        {
            $removeHandler(e, "change", this._changeHandler);
            this._changeHandler = null;
        }

        LF.Controls.Ajax.LinkedDropdownBehavior.callBaseMethod(this, 'dispose');
    }
    //
    // EVENT TARGET
    //
    , _onChange : function(evt) 
    {
		var select = evt.target;
		var selectedIndex = select.selectedIndex;
		if (selectedIndex > -1)
		{
			var url = select.options[select.selectedIndex].value;
			if (url && url.length > 0)
			{
				window.location = url;
			}
		}

        return true;
    }
}

LF.Controls.Ajax.LinkedDropdownBehavior.registerClass('LF.Controls.Ajax.LinkedDropdownBehavior', AjaxControlToolkit.DynamicPopulateBehaviorBase);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();