

function WindowWidget(widgetId, title, height, width, source, content, ignorePageScroll)
{
	this.id = widgetId;
	this.height = height;
	this.width = width;
	if(typeof title != 'undefined')
	{
		this.title = title;
	}
	else
	{
		this.title = widgetId;
	}
	if(typeof source != 'undefined')
	{
		this.source = source;
	}
	else
	{
		this.source = null;
	}
	if(typeof content != 'undefined')
	{
		this.content = content;
	}
	else
	{
		this.content = 'loading...';
	}
	if(typeof ignorePageScroll != 'undefined')
	{
		this.ignoresPageScroll = ignorePageScroll;
	}
}

subclass(Widget, WindowWidget);
//WindowWidget.instance = new Function('id','return widgetengine.deployWidget(new WindowWidget(id))');



WindowWidget.prototype.alertSomething = function(value)
{
	alert(value);
};


WindowWidget.prototype.process = function(value)
{
	alert(value);
};


WindowWidget.prototype.draw = function(left, top)// + mode
{
	if(top != null) this.top = top;
	if(left != null) this.left = left;
	if(this.element != null)
	{
		this.element.style.visibility = 'hidden';

		this.element.style.position = 'absolute';
		this.element.style.top = this.top + 'px';
		this.element.style.left = this.left + 'px';
		this.element.style.height = this.height + 'px';
		this.element.style.width = this.width + 'px';
		this.element.style.margin = '0px';
		this.element.style.padding = '0px';
		this.element.style.background = 'white';
		this.element.style.border = '1px #AAAAAA solid';
		this.element.style.valign = 'top';

		this.writeHTML();
		this.element.style.visibility = 'visible';
	}

};

WindowWidget.prototype.writeHTML = function()
{
	//todo height must be larger than 32
	if(this.element)
	{
		var result = '<div id="' + this.id + '_header" style="margin: 0px; padding: 0px; top: 0px; left: 0px; height: 20px; width: ' +
					 (this.width) + 'px; background: blue; color: white; font: bold 1em Arial">' +
					 '<div style="display: inline; float: left; padding: 2px; padding-left: 5px;">' + this.title + '</div><img src="' + contextroot + '/images/edit_icos/close_window.gif" style="display: inline; float: right;"' +
					 ' onclick="widgetengine.destroyWidget(\'' + this.getId() + '\')"></div>' +
					 '<div id="' + this.id + '_contents" style="margin: 0px; padding: 5px; top: 0px; left: 0px; height: ' + (this.height - 32) + 'px; width: ' + (this.width - 12) + 'px; background: white; color: black; font: normal 1em Arial; border: 1px white solid">';

		result += this.content;

		result += '</div>';

		this.element.innerHTML = result;
		this.dragActivationElement = document.getElementById(this.id + '_header');
	}
};



//destructor
WindowWidget.prototype.onDestroy = function()
{
	//save state
};


WindowWidget.prototype.onDeploy = function()
{
	widgetengine.registerDraggableWidget(this);
	//load state
	this.refresh();
};

WindowWidget.prototype.refresh = function()
{
	//load state
	if(this.source != null)
	{
		ajaxReqeuestManager.doRequest(this.source, this.display, this);
	}
};

//todo rename to activate / deactivate


WindowWidget.prototype.onFocus = function()
{
	document.getElementById(this.id + '_header').style.background = 'blue';
};

WindowWidget.prototype.onBlur = function()
{
	document.getElementById(this.id + '_header').style.background = 'gray';
};


WindowWidget.prototype.display = function(content, element)
{
	if(element != null)
	{
		element.content = content;
		document.getElementById(element.id + '_contents').innerHTML = content;
	}
	else
	{
		this.content = content;
		document.getElementById(this.id + '_contents').innerHTML = content;
	}
};




