/**
 *	JavaScript to initialize TinyMCE in several versions for DataNavigator
 *	
 *	TinyMCE.init doesn't get called when the page loads but it is called 
 *	when the control appears in the form.
 *	And then it is also possible to init the demanded instance. And it will 
 *	be possible to add specific instances within certain projects.
 *
 *	DataNavigator has the following TinyMCE instances:
 *		1.	basiceditor:	only bold, underline, italics and bullets
 *		2.	cmseditor:		basic including links, styles, several tags
 *		3.	fulleditor:		advanced
 *
 *	The editors have initialization options that can be passed by listing them
 *	in the displaytype like html-attributes.
 */

/**
 *	To be called before posting the forms data
 *	It will have all editors to write back their contents to the textarea
 *	And the editors of the form will be removed
 */
function endTinyMCE(form) {
	tinyMCE.triggerSave();
	form.getElements().each(function(s) {
		if (tinyMCE.getInstanceById($(s).identify())) {
			tinyMCE.execCommand('mceFocus', false, $(s).identify());                    
			tinyMCE.execCommand('mceRemoveControl', false, $(s).identify());
		}
	});
}

/**
 * Inititalize basic editor
 */
function dn_initbasiceditor(id, options) {
	var tinyI;	// object array to init tinyMCE
	tinyI = {
		theme : "simple",
		mode : "exact",
		language : "nl",
		docs_language : "en",
		fix_list_elements : true,
		fix_table_elements : true,
		gecko_spellcheck : true
	};
	// merge
	tinyI = tinymce.extend(tinyI, options);
	tinyI = tinymce.extend({ elements: id }, tinyI);
	tinyMCE.init(tinyI);
}

/**
 * Inititalize cms editor
 */
function dn_initcmseditor(id, options) {
	var tinyI;	// object array to init tinyMCE
	tinyI = {
		theme : "advanced",
		plugins : "table,heading,safari",
		heading_clear_tag : "p",
		theme_advanced_buttons1_add_before : "h1,h2,h3,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		extended_valid_elements : "h1,h2,h3",
		convert_urls : false,
		document_base_url : "/"
	};
	// merge
	tinyI = tinymce.extend(tinyI, options);
	dn_initbasiceditor(id, tinyI);
}


/**
 * Inititalize full editor
 */
function dn_initfulleditor(id, options) {
	var tinyI;	// object array to init tinyMCE
	tinyI = {
		theme : "advanced",
		plugins : "autoresize,table,heading,insertdatetime,style,safari",
		heading_clear_tag : "p",
		theme_advanced_buttons1_add_before : "h1,h2,h3,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "insertdate,inserttime,styleprops",
		plugin_insertdate_dateFormat : "%d-%m-%Y",
		plugin_insertdate_timeFormat : "%H:%M:%S"
	};
	// merge
	tinyI = tinymce.extend(tinyI, options);
	dn_initcmseditor(id, tinyI);
}



