
tinyMCE.init({
	theme : "humanique",
	language : "nl",
	mode : "textareas",
	editor_selector : "mceEditor",
	content_css : "web/editor_preview.css",
	//extended_valid_elements : "a[href]",

	//plugins : "table",
	plugins : "hulink,huimage,paste,humedia,table",

	theme_advanced_buttons1 : "bold,italic,separator,formatselect,separator,bullist,numlist,separator,undo,redo,separator,link,unlink,image,media,separator,removeformat,separator",
	theme_advanced_buttons2 : "tablecontrols,visualaid",

	theme_advanced_resizing : false,
	theme_advanced_resize_horizontal : false,


	forced_root_block : 'p',
	object_resizing : false,
	remove_trailing_nbsp : false,			// fix removal of enters at the end of the paragraphs (we fix it later in the php)
	force_br_newlines : false,
	force_p_newlines : true,
	cleanup_on_startup : false,			// do not set this to true without checking for media links in firefox

	paste_create_paragraphs : true,
	paste_create_linebreaks : false,
	paste_use_dialog : false,
	paste_auto_cleanup_on_paste : true,
	paste_convert_middot_lists : false,
	paste_unindented_list_class : "unindentedList",
	paste_convert_headers_to_strong : false,
	paste_insert_word_content_callback : "convertWord",

	debug : false
});

tinyMCE.init({
	theme : "humanique",
	language : "nl",
	mode : "textareas",
	editor_selector : "mceSimpleEditor",
	content_css : "web/editor_preview.css",

//	plugins : "hulink,huimage,paste,humedia",

	theme_advanced_buttons1 : "bold,italic,separator,undo,redo,separator,removeformat",

	theme_advanced_resizing : false,
	theme_advanced_resize_horizontal : false,


	forced_root_block : 'p',
	object_resizing : false,
	remove_trailing_nbsp : false,			// fix removal of enters at the end of the paragraphs (we fix it later in the php)
	force_br_newlines : false,
	force_p_newlines : true,
	cleanup_on_startup : false,			// do not set this to true without checking for media links in firefox

	paste_create_paragraphs : true,
	paste_create_linebreaks : false,
	paste_use_dialog : false,
	paste_auto_cleanup_on_paste : true,
	paste_convert_middot_lists : false,
	paste_unindented_list_class : "unindentedList",
	paste_convert_headers_to_strong : false,
	paste_insert_word_content_callback : "convertWord",

	debug : false
});


function convertWord(type, content) {
	switch (type) {
		// Gets executed before the built in logic performes it's cleanups
		case "before":
			break;

		// Gets executed after the built in logic performes it's cleanups
		case "after":
			old = content;

			// remove starting space
			re = new RegExp("^[ \t\r\n]*&nbsp;[ \t\r\n]*");
			content = content.replace(re,"","ig");

			// convert newlines to spaces
			re = new RegExp("[\r\n]","g");
			content = content.replace(re," ","g");

			// remove all tag-attributes
			re = new RegExp("<([a-z]+) [^>]+>","ig");
			content = content.replace(re,"<$1>","ig");

			// remove script's and images
			re = new RegExp("<script[^>]*>(.+)</script>","ig");
			content = content.replace(re,"","ig");
			re = new RegExp("<img[^ >]*>","ig");
			content = content.replace(re,"","ig");

			// replace block tags with <p> and </p>
			re = new RegExp("<(p|h[1-6]|pre|td)>","ig");
			content = content.replace(re,"<p>","ig");
			re = new RegExp("</(p|h[1-6]|pre|td)>","ig");
			content = content.replace(re,"</p>","ig");

			// special case
			re = new RegExp("<(br)>","ig");
			content = content.replace(re,"","ig");

			// remove all soft tags
			var soft_tags = "strong|em|b|i|tr";
			re = new RegExp("<("+soft_tags+")>","ig");
			content = content.replace(re,"","ig");
			re = new RegExp("</("+soft_tags+")>","ig");
			content = content.replace(re,"","ig");

			// remove space paragraphs
			re = new RegExp("<p>&nbsp;</p>[ \r\n\t]*","ig");
			content = content.replace(re,"");

			// re-insert enters after closing paragraphs
			re = new RegExp("</p>","ig");
			content = content.replace(re,"</p>\n","ig");

			if (true) {
				//alert(old + "\n---\n" + content);
				//alert(old);
				//alert(content);
			}
			break;
	}

	return content;
}
