﻿
/* Define support for tinyMCE wysiwyg editing */
function initaliseTinyMCE(sEditor) {
	tinyMCE.init({
		// General options
		mode : "exact",
		elements : sEditor,

		theme : "advanced",
		plugins : "save,iespell,paste,nonbreaking",

		save_enablewhendirty : true,
		save_onsavecallback : "tinySaveContent",

		//this sets auto focus
		setup : function(ed) {
			if(tinymce.isWebKit) {
				//workaround for Webkit to fix focus problems when setting contents to an empty string
				ed.onSetContent.add(function() {
					window.focus();
					ed.focus();
				});                        
			}
		},

		//Set newlines
		forced_root_block : '',

		fix_nesting : true,
		convert_fonts_to_spans: true, 
		theme_advanced_font_sizes : "8px=8px,10px=10px,12px=12px,14px=14px,16px=16px,20px=20px,28px=28px",
		inline_styles : true,


		// Theme options
		theme_advanced_buttons1 : "save,|,bold,italic,underline,|,forecolor,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
		theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,pastetext,pasteword,|,cleanup,removeformat,iespell,code",
		theme_advanced_buttons3 : "fontselect,fontsizeselect,|,link,unlink",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,

		theme_advanced_source_editor_width: "400",
		theme_advanced_source_editor_height: "500",

		// Example content CSS (should be your site CSS)
		content_css : "/application/styles/editor08.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js"

	});
}


function tinySaveContent() {
var sObject=cs_getObjectVariable('editorMenu', 'editobject'), lLayer=cs_getObjectVariable('editorMenu', 'editlayer'), sObjectText=tinyMCE.get('contentEditor').getContent(), sBoundTo='', dTxReference=document.getElementById('txreference').value, sTxCaption=document.getElementById('txcaption').value;

	if(cs_StringLength(sObject)>0) {
		sBoundTo=functionEditor_GetObjectBoundTo(sObject);			
		functionDesigner_SetObjectText(sObject, lLayer, sObjectText);
		if(sBoundTo!='nothing') { functionDesigner_SetObjectTxReference(sBoundTo, dTxReference); functionDesigner_SetObjectTxCaption(sBoundTo, sTxCaption); }
		functionDesigner_UpdateContent(sObject, lLayer);
	} else {
		alert('Information: no active object selected');
	}
	
	functionEditor_ClearEditor();
}

function tinyClearContent() {
	tinyMCE.activeEditor.setContent("");
}

function tinyLoadContent(sContent, sObject, lLayer) {
	cs_setObjectVariable('editorMenu', 'editobject', sObject);
	cs_setObjectVariable('editorMenu', 'editlayer', lLayer);
	tinyMCE.execInstanceCommand('contentEditor', 'mceSetContent', false, sContent, true);	
	return false
}


