﻿var AjaxHtmlEditor = new Class(
{
	initialize : function()
	{
		this._editors = [];
		ui.registerViewStateHandler("HtmlEditor", this.collectViewState);
	},

	collectViewState : function(control)
	{
		var he = $("wysiwyg" + control.id);
		var content;

		if (he == null)
		{
			content = control.innerHTML;
		}
		else
		{
			content = he.contentWindow.document.body.innerHTML;
		}

		return { "__type" : "vs", "Content" : content };
	},

	prepareSize : function(width, height)
	{
		wysiwygWidth = width;
		wysiwygHeight = height;
	},

	initControl : function(dialogID, controlID)
	{
		var control = ui.getNestedControl(dialogID, controlID);
		var htmlControl = $("wysiwyg" + controlID);

		if (control == null)
		{
			return;
		}

		if (htmlControl == null)
		{
			generate_wysiwyg(controlID);
		}
	}
});

var htmlEditor = new AjaxHtmlEditor();