﻿//----------------------------------------------------------
// Copyright (C) Burton Group. All rights reserved.
//----------------------------------------------------------
// ClickExtender.js

// Register the namespace for the control
Type.registerNamespace('BurtonGroup.WebControls');

// ClickExtender Class
BurtonGroup.WebControls.ClickExtender = function(element)
{
	// Initialize the base class, passing a reference to the DOM element
	BurtonGroup.WebControls.ClickExtender.initializeBase(this, [element]);

	// Private class properties
	this._sourceControlID = null;
	this._onKeyDownHandler = null;
	
	// INVESTIGATE: Is there a define already available in the DOM or ASP.NET AJAX?
	this._keyCode = null;
}

// Create the prototype for the control
BurtonGroup.WebControls.ClickExtender.prototype =
{
	initialize : function()
	{
		BurtonGroup.WebControls.ClickExtender.callBaseMethod(this, 'initialize');

		// Create the event delegates and associate them with their handlers 
		this._onKeyDownHandler = Function.createDelegate(this, this._onKeyDown);
		
		var sourceControlElement = $get(this._sourceControlID);

		//Attach the event handlers to the DOM element associated with the control.
		$addHandlers(sourceControlElement, { 'keydown' : this._onKeyDownHandler }, this);
	},

	dispose : function()
	{
		// Call the base class dispose() method
		BurtonGroup.WebControls.ClickExtender.callBaseMethod(this, 'dispose');
	},
	
	_onKeyDown : function(eventObject)
	{
		if (eventObject.keyCode == this._keyCode)
		{
			this.get_element().focus();
		}
		
		return true;
	},

	get_sourceControlID : function()
	{
		return this._sourceControlID;
	},

	set_sourceControlID : function(value)
	{
		if (this._sourceControlID != value)
		{
			this._sourceControlID = value;
			this.raisePropertyChanged('sourceControlID');
		}
	},
	
	get_keyCode : function()
	{
		return this._keyCode;
	},

	set_keyCode : function(value)
	{
		if (this._keyCode != value)
		{
			this._keyCode = value;
			this.raisePropertyChanged('keyCode');
		}
	}
}

// Register the class with the client AJAX library and specify its base class as Sys.UI.Control
BurtonGroup.WebControls.ClickExtender.registerClass(
	'BurtonGroup.WebControls.ClickExtender', Sys.UI.Behavior);

// This has been commented out because this file has been set as an embedded resource.
//  The script manager will add this line automatically to the script.
// Notify the Sys.Application class this script has been loaded
//if (typeof(Sys) !== 'undefined')
//{
//	Sys.Application.notifyScriptLoaded();
//}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();