//Fichero javascript con las funciones propias del CMS

tinyMCE.init({
        mode : "specific_textareas", 
        editor_selector : "mceEditor",
        theme: "advanced",
        language: "es",
        plugins: "table, uploadimage, template, preview, searchreplace, fullscreen, gestorficheros, gestorenlaces, paste",
        enlaceImage: "/album/list?source=tiny",
		enlaceGestorFicheros: "/ficheros/list_folders",
		enlaceGestorEnlaces: "/enlaces/ver_carpetas",
        force_br_newlines:true,
        debug:"false",
		/*Para que no ponga ../../../ antes de las urls de las imagenes */
		convert_urls:false,
        
        theme_advanced_buttons1_add_before : "newdocument, separator",
        theme_advanced_buttons1:"styleselect,formatselect, separator, bold, italic, underline, strikethrough, separator, justifyleft, justifycenter, justifyright, justifyfull, separator, bullist, numlist, outdent, indent, separator, cut,copy,paste, pastetext, pasteword, selectall, separator, search,replace",
        theme_advanced_buttons2:"undo,redo, gestorenlaces, unlink, anchor, cleanup, help, code, separator, sub, sup,separator,charmap,removeformat, separator",
        theme_advanced_buttons2_add: "uploadimage,  gestorficheros, template, preview, fullscreen, tablecontrols",
        theme_advanced_buttons3: "",      
        
        extended_valid_elements:"a[name|href|target|title|onclick],font[face|size|color|style],span[class|align|style]",
        theme_advanced_toolbar_location: "top",
        width: "100%",
        height: "395",
        template_external_list_url : "/javascripts/template_list.js",
        content_css : "/stylesheets/contenidos_tiny.css",
		
		paste_create_paragraphs : false,
		paste_create_linebreaks : false,
		paste_use_dialog : true,
		paste_auto_cleanup_on_paste : true,
		paste_convert_middot_lists : false,
		paste_unindented_list_class : "unindentedList",
		paste_convert_headers_to_strong : true,
		paste_insert_word_content_callback : "convertWord"
     });

/* Función para pegar desde word, usada por el plugin paste */
function convertWord(type, content) {
	switch (type) {
		// Gets executed before the built in logic performes it's cleanups
		case "before":
			content = content.toLowerCase(); // Some dummy logic
			break;

		// Gets executed after the built in logic performes it's cleanups
		case "after":
			content = content.toLowerCase(); // Some dummy logic
			break;
	}

	return content;
}

function SetContenidoAvanzado (id, nombre, alt) {
    var tiny = tinyMCE;
    if ( tiny != null ) {
        tiny.execCommand( 'mceInsertContent', true, '<img style="float:left;" src=\"/upload/images/' + id + '/' + nombre + '\" alt=\"' + alt + '\"/>');
    }
    else {
        alert("El sistema no puede insertar el contenido avanzado." );
    }
}

function EnlazarFichero (id, nombre, titulo_enlace) {
    var tiny = tinyMCE;
    if ( tiny != null ) {
        tiny.execCommand( 'mceInsertContent', true, '<a href=\"/privado/fichero/' + id + '\">' + titulo_enlace + '</a>');
    }
    else {
        alert("El sistema no puede insertar el contenido avanzado." );
    }
}