/** 
 * Permet de configurer l'éditeur
 * @param {String} config configuration voulue (full, minimal...) 
 * @param {Array} tabIdTextareas tableau contenant les id des textareas sur lesquels appliquer TinyMCE
 * @param {String} langue langue de l'éditeur (en, fr)
 * @param {String} SERVER_ROOT server_root
 * @param {String} DMS_CSS dmn_css    
 */ 
function editorInit(config, tabIdTextareas, langue) {

	var mode, elements;
	if (tabIdTextareas.length != 0) {
		mode = 'exact';
		elements = tabIdTextareas.join(',');
	} else {
		mode = 'textareas';
		elements = '';
	}
	
    var myPlugins = "table,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable";
		
	var barreBoutons1 = "bold,italic,separator"
                      + ",justifyleft,justifycenter,justifyright,justifyfull,separator"
                      + ",bullist,numlist,separator,"
          			  + ",outdent,indent,sub,sup";
                      
	var barreBoutons2 = "cut,copy,paste,pastetext,pasteword,separator,"
          						+ "undo,redo,separator,"
          						+ "search,replace,separator,"          						
          						+ "charmap,hr,separator";
	var barreBoutons3 = "";
	var barreBoutons4 = "";
	var blockformats = "p";
    var ext_link_list ="undefined";
    var ext_image_list ="undefined";
    var ext_flash_list ="undefined";
    
	switch (config) {
		case ('paragraphe') :
			barreBoutons1 = "formatselect,separator," + barreBoutons1;		   		    
            barreBoutons2 = barreBoutons2 + ",cleanup,removeformat,separator,"
                                    + "code,separator,"
                                    + "visualaid,fullscreen";
            barreBoutons3 = barreBoutons3 + "link,unlink,anchor";
            barreBoutons3 = barreBoutons3 + ",separator,image,media,emotions,iespell";
            
			barreBoutons4 = "tablecontrols"
			blockformats = blockformats + ",h3,h4,h5";
					
			ext_link_list = "http://www.moulin-piongo.fr/tinymce/link_list.js.php";
            ext_image_list = "http://www.moulin-piongo.fr/tinymce/image_list.js.php";
            ext_flash_list = "http://www.moulin-piongo.fr/tinymce/flash_list.js.php";
            myPlugins = myPlugins + ",advimage,advlink";
		break;
		case ('paragraphe_simple') :
					    
            barreBoutons2 = barreBoutons2 + ",cleanup,removeformat,separator,"
                                    + "code,separator,"
                                    + "visualaid,fullscreen";
            barreBoutons3 = barreBoutons3 + "link,unlink,anchor";
            barreBoutons3 = barreBoutons3 + ",separator,iespell";
            
			barreBoutons4 = "tablecontrols"
			blockformats = blockformats + ",h2,h3,h4,h5";

		break;
		
		case('newsletter') :
            barreBoutons2 = barreBoutons2 + ",cleanup,removeformat,separator,"
                + "code,separator,"
                + "visualaid,fullscreen";
            barreBoutons3 = barreBoutons3 + "link,unlink,anchor";
            barreBoutons3 = barreBoutons3 + ",separator,iespell";        
            barreBoutons4 = "tablecontrols"
            blockformats = blockformats + ",h2,h3,h4,h5";        
        break;
		
	    case ('front_office') :		   		                
            barreBoutons3 = barreBoutons3 + "link,unlink,anchor";
            barreBoutons3 = barreBoutons3 + ",separator,emotions,iespell";	
		break;
							
	}
	
 	
	tinyMCE.init({
		mode : mode,
		elements : elements,
		theme_advanced_blockformats : blockformats,
		theme : "advanced",
		dialog_type : "modal",
		fix_list_elements : true,
		language : "fr",
		plugins : myPlugins,
		forced_root_block : 'p',
		theme_advanced_buttons1 : barreBoutons1,
		theme_advanced_buttons2 : barreBoutons2,
		theme_advanced_buttons3 : barreBoutons3,
		theme_advanced_buttons4 : barreBoutons4,		
		
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		content_css : "/css/tinymce.css",		
		plugin_insertdate_dateFormat : "%d/%m/%Y",
		convert_urls : false,
		extended_valid_elements : "hr,"
								+ "span[class|align|style|lang],"
								+ "-table[border=0|cellspacing|cellpadding|width|height|class|align|summary=|style|dir|id|lang|bgcolor|background|bordercolor],"
								+ "div[style|class|align|id],"
								+ "acronym[title|lang],"
								+ "img[id|dir|lang|longdesc|usemap|style|class|src|border|alt=|title|hspace|vspace|width|height|align|idimage|format],"
								+ "a[id|style|charset|hreflang|lang|tabindex|accesskey|type|name|href|target|title|class|ancre|typelien|onMouseOver]",
		invalid_elements : "h1,font,u",
		external_link_list_url : ext_link_list,
		external_image_list_url : ext_image_list,
		flash_external_list_url : ext_flash_list,
		file_browser_callback : "fileBrowserCallBack",
		paste_use_dialog : false,
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		paste_auto_cleanup_on_paste : true,
		paste_convert_headers_to_strong : false,
		paste_strip_class_attributes : "all"
	});
	function fileBrowserCallBack(field_name, url, type, win) {
		// This is where you insert your custom filebrowser logic
		alert("Example of filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);

		// Insert new URL, this would normaly be done in a popup
		win.document.forms[0].elements[field_name].value = "someurl.htm";
	}
}
