var ReloadableControl = Class.create();
ReloadableControl.prototype =
{
	objOverlay: null,
	id: null,
	baseUrl: null,

	initialize: function()
	{
		var id;
		var optionIndex = 0;

		if (0 < arguments.length)
		{
			if ('string' == typeof arguments[0])
			{
				id = arguments[0];
				optionIndex = 1;
			}
			else
			{
				id = arguments[0] ? arguments[0].id : null;
			}
		}
		this.id = id;
		this.baseUrl = (arguments[optionIndex] || {}).baseUrl || getBaseUrl();
	},

	disableScreen: function(className, overlayId, overlayOpacity, contentId, parent)
	{
		if (!this.objOverlay)
		{
			this.objOverlay = document.createElement('div');
			this.objOverlay.className = 'overlay_' + className;
	      	this.objOverlay.style.position = 'absolute';
		}
		if (this.objOverlay)
		{
			this.objOverlay.style.display = 'block';
			var parent = $(this.id);
			parent.insertBefore(this.objOverlay, parent.firstChild);
			Position.clone(/*$('calendar_block')*/this.id, this.objOverlay);
		}
	},

	enableScreen: function()
	{
		if (this.objOverlay)
		{
			this.objOverlay.style.display = 'none';
		}
	},
	load: function(params, onSuccess, onFailure)
	{
		setTimeout(this.enableScreen.bind(this), 20000);

		var parameters = Object.extend(params, {});
		delete parameters['baseUrl'];

		new Ajax.Request(
				this.baseUrl, {
				method : 'get',
				parameters : params,
				onSuccess : onSuccess || this._defaultOnSuccess.bind(this),
				onFailure : onFailure || function(){}
			}
		);
	},
	_defaultOnSuccess: function(t)
	{
		var respObj = t.responseText.evalJSON();
		$(this.id).update(respObj['content']);
		this.enableScreen();
	}
}