/**
*
* egRichText Class (egRichText_default.js)
*/

var fckValues = new Array();

function egRichText(id, title, posX, posY, width, height, container, name) {
	 this.objName = 'richText_'+id;
	 this.id = id;
	 this.name = name;
	 this.value = title;
	 this.x = posX;
	 this.y = posY;
	 this.width = width;
	 this.height = height;

	 this.show = egWindow_show;
	 this.hide = egWindow_hide;
	 this.moveTo = egWindow_moveTo;
	 this.displayAt = egWindow_displayAt;

	 this.active = 0;

	 this.getValue = egRichText_getValue;
	 this.setValue = egRichText_setValue;

	 this.onChange = egRichText_onChangeHandler;

	 this.BasePath		= 'interface/fckeditor/';
	 /*this.toolbarSet	= 'ecms_Simple';*/
	 /*this.toolbarSet	= 'ecms_Advanced';*/
	 this.toolbarSet	= 'knine_Simple';

   this.link = this.BasePath + 'editor/fckeditor.html?InstanceName=' + this.id + '&amp;Toolbar=' + this.toolbarSet;

   if (!container) {
      container = 'easy-GUI_mainLayer';
   }

	 fckValues[this.id] = this.value;

	 divRoot = document.getElementById(container);

	 divRoot.innerHTML += '<div id="'+this.id+'_frame" style="position: absolute;">'
		+ '  <input type=\"hidden\" id=\"'+this.id+'\" name=\"'+this.name+'\" value=\"'+this.value+'\" style=\"display:none;\" />'
		+ '  <input type=\"hidden\" id=\"'+this.id+'___Config\" value=\"\" style=\"display:none;\" />'
		+ '  <iframe id=\"'+this.id+'___Frame\" src=\"'+ this.link +'\" width=\"'+ width +'\" height=\"'+ height +'\" frameborder=\"0\" scrolling=\"no\"></iframe>'
		+ '</div>';


	 div = document.getElementById(this.id+'_frame');
	 div.style.width  = width+'px';
	 div.style.height = height+'px';
	 div.style.left = posX + 'px';
	 div.style.top  = posY + 'px';
}

function egRichText_getValue(){
	var oEditor = FCKeditorAPI.GetInstance(this.id);
	return oEditor.GetHTML();
}

function egRichText_setValue(value) {
	var oEditor = FCKeditorAPI.GetInstance(this.id);
	fckValues[this.id] = value;
	return oEditor.SetHTML(value);
}

function egRichText_checkForChange() {
	for (instanceName in fckValues) {
		var oEditor = FCKeditorAPI.GetInstance(instanceName);
		var currentValue = oEditor.GetHTML();
		if (currentValue != fckValues[instanceName]) {
			egRichText_onChange(instanceName+'___Frame');
			fckValues[instanceName] = currentValue;
			document.getElementById(instanceName).value = currentValue;
			egRichText_timerID = window.setTimeout("egRichText_checkForChange()", 5000);
			return;
		}
	}
	egRichText_timerID = window.setTimeout("egRichText_checkForChange()", 5000);
}

var egRichText_timerID = window.setTimeout("egRichText_checkForChange()", 15000);

function egRichText_onChangeHandler() {
}

function egRichText_onChange(id) {
	var append = '___Frame';
	if(typeof(egObjectsArray['richText_'+id.substr(0, id.length-(append.length))].onChange) =='function') {
		egObjectsArray['richText_'+id.substr(0, id.length-(append.length))].onChange();
	}
}