﻿/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit" />
/// <reference name="AjaxControlToolkit.MutuallyExclusiveCheckBox.MutuallyExclusiveCheckBoxBehavior.js" assembly="AjaxControlToolkit" />

Type.registerNamespace('ControlExtenders');
Type.registerNamespace('ControlExtenders.SelectionGridCheckBox');

ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior = function(element) {
    ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior.initializeBase(this, [element]);

    this._selectionButtonID = null;
    this._btnImagePath = null;
    this._clickHandlerChild = Function.createDelegate(this, this._onclickChild);
}
ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior.prototype = {
    initialize : function() {
        ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior.callBaseMethod(this, 'initialize');

		// Remove the parent handler and add the child
		$removeHandler(this.get_element(), "click", this._clickHandler);
        $addHandler(this.get_element(), "click", this._clickHandlerChild);
    },

    dispose : function() {
        if (this._clickHandlerChild) {
            $removeHandler(this.get_element(), "click", this._clickHandlerChild);
            this._clickHandlerChild = null;
            $addHandler(this.get_element(), "click", this._clickHandler);
        }
		this._selectionButtonID = null;
		this._buttonImagePath = null;
		
        ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior.callBaseMethod(this, 'dispose');
    },

	_onclickChild : function()
	 {
		// Call the parent onclick
		this._onclick();
		// Select the button
		if (this._selectionButtonID)
		 {
			var btn = $get(this._selectionButtonID);
			if (btn) 
			{
			    if(this.get_element().checked)
			    {
				    btn.disabled = false;
				    if (this._buttonImagePath)
				    {
					    btn.src = this._buttonImagePath;
				    }
			    }
			    else
			    {
			    btn.disabled = true;
			     
				    if (this._buttonImagePath)
				    {
				    var imgpath = '';
				        if(this._buttonImagePath.indexOf('next') != -1)
				            {
				             imgpath = this._buttonImagePath.replace('next','next_disabled');
				             }
				        else if (this._buttonImagePath.indexOf('save') != -1)
				           {
				            var imgpath = this._buttonImagePath.replace('save','save_disabled');
				            }
					    btn.src = imgpath;
				    }
			    }
			}
		}
	},
	
    get_SelectionButtonID : function() {
        return this._selectionButtonID;
    },

    set_SelectionButtonID : function(value) {
        this._selectionButtonID = value;
    },
    
    get_ButtonImagePath : function() {
		return this._buttonImagePath;
	},
	
	set_ButtonImagePath : function(value) {
		this._buttonImagePath = value;
	}
}
ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior.registerClass('ControlExtenders.SelectionGridCheckBox.SelectionGridCheckBoxExtenderBehavior', AjaxControlToolkit.MutuallyExclusiveCheckBoxBehavior);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();