// ************************************************************************************
// BaseWebpartBehavior
// ************************************************************************************
// namespace
Type.registerNamespace("Competir.Web.UI.Webparts.Behaviors");

// constructor
Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior = function(element)
{
	Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior.initializeBase(this, [element]);
	this._onApplicationLoadDelegate = Function.createDelegate(this, this._onApplicationLoad);
	this._Target = null;
};

// prototype
Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior.prototype =
{
	// methods
	initialize: function()
	{
		Sys.Application.add_load(this._onApplicationLoadDelegate);
		this.add_propertyChanged(this._onPropertyChanged);
		Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior.callBaseMethod(this, "initialize");
	},
	dispose: function()
	{
		$clearHandlers(this.get_element());
		Sys.Application.remove_load(this._onApplicationLoadDelegate);
		this.remove_propertyChanged(this._onPropertyChanged);
		Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior.callBaseMethod(this, "dispose");
	},
	findChild: function(id)
	{
		var rv = null;
		if (id)
		{
			rv = $find(this.get_ClientID() + this.get_ClientIDSeparator() + id);
			if (!rv)
			{
				rv = $find(this.get_ClientID() + id);
			}
			if (!rv)
			{
				rv = $find(id);
			}
		}
		return rv;
	},
	getChild: function(id)
	{
		var rv = null;
		if (id)
		{
			rv = $get(this.get_ClientID() + this.get_ClientIDSeparator() + id);
			if (!rv)
			{
				rv = $get(this.get_ClientID() + id);
			}
			if (!rv)
			{
				rv = $get(id);
			}
		}
		return rv;
	},

	// properties
	get_Target: function()
	{
		return this._Target;
	},
	set_Target: function(value)
	{
		if (this._Target !== value)
		{
			this._Target = value;
			this.raisePropertyChanged("Target");
		}
	},
	get_ClientID: function()
	{
		return this.get_Target().get_ClientID();
	},
	set_ClientID: function(value)
	{
		if (this.get_Target().get_ClientID() !== value)
		{
			this.get_Target().set_ClientID(value);
		}
	},
	get_ClientIDSeparator: function()
	{
		return this.get_Target().get_ClientIDSeparator();
	},
	set_ClientIDSeparator: function(value)
	{
		if (this.get_Target().get_ClientIDSeparator() !== value)
		{
			this.get_Target().set_ClientIDSeparator(value);
		}
	},

	// event delegates
	_onApplicationLoad: function(o)
	{
	},
	_onPropertyChanged: function(p)
	{
	},
	_onOperationStarted: function(sender, args)
	{
		throw Error.notImplemented("BaseWebpartBehavior._onOperationStarted no se ha implementado en la aplicación.");
	},
	_onOperationSucceeded: function(sender, args)
	{
		throw Error.notImplemented("BaseWebpartBehavior._onOperationSucceeded no se ha implementado en la aplicación.");
	},
	_onOperationFailed: function(sender, args)
	{
		throw Error.notImplemented("BaseWebpartBehavior._onOperationFailed no se ha implementado en la aplicación.");
	}
};

// registration
Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior.registerClass("Competir.Web.UI.Webparts.Behaviors.BaseWebpartBehavior", Sys.UI.Behavior);