﻿var editorLoaded = false;
function InitializeTinyMCE(id, dotsToRoot) {
	editorLoaded = true;
	var dots = '';
	for (var i = 0; i < dotsToRoot; i++) {
		dots += "../";
	}
	$("textarea#" + id).tinymce({
		// Location of TinyMCE script
		script_url: dots + 'scripts/tiny_mce/tiny_mce.js',
		relative_urls: false,
		remove_script_host: true,
		// General options
		theme: "advanced",
		plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,inlinepopups,preview,searchreplace,contextmenu,paste,fullscreen,noneditable,xhtmlxtras,imagemanager,filemanager",
		media_strict: false,
		// Theme options
		theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,bullist,numlist,|,outdent,indent,blockquote,sub,sup,|",
		theme_advanced_buttons2: "styleselect,formatselect",
		theme_advanced_buttons3: "pastetext,pasteword,|,search,replace,|,undo,redo,|",
		theme_advanced_buttons4: "link,unlink,anchor,image,insertfile,|",
		theme_advanced_buttons5: "table,visualaid,|,hr,removeformat",
		theme_advanced_buttons6: "fullscreen,cleanup,help,code,|,preview",
		theme_advanced_toolbar_location: "top",
		theme_advanced_toolbar_align: "left",
		theme_advanced_statusbar_location: "bottom",
		theme_advanced_styles: "Required=required,Float Left=floatLeft,Float Right=floatRight,Modal Popup=fancyBox,Caption=caption",
		theme_advanced_resizing: true,
		forced_root_block: false,
		encoding: "xml",
		extended_valid_elements: "div[*],iframe[src|width|height|name|align|frameBorder],pre[*],code,embed",
		invalid_elements: "form",
		cleanup_callback: "myCustomCleanup",
		save_callback: "myCustomSaveContent"

	});
}
function myCustomCleanup(type, value) {
	if (type == "insert_to_editor") {
		value = value.replace(/&lt;/gi, "<");
		value = value.replace(/&gt;/gi, ">");
	}
	return value;
}
function myCustomSaveContent(element_id, html, body) {
	html = html.replace(/</gi, "&lt;");
	html = html.replace(/>/gi, "&gt;");
	return html;
}
