function iniciarTinyMCE(){
	tinyMCE.init({
		theme : "advanced",
		elements : 'nourlconvert',
		convert_urls : false,
		language : "es",						
		mode : "none",
		plugins : "bbcode, paste",
		verify_html:true,
		theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,bullist,numlist,forecolor,removeformat,cleanup,code,image",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,selectall",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		content_css : "css/bbcode.css",
		convert_urls : true,
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		convert_fonts_to_spans : false,
		paste_auto_cleanup_on_paste : true,						
        paste_preprocess : function(pl, o) {
            // Content string containing the HTML from the clipboard
            alert(o.content);
        },
        paste_postprocess : function(pl, o) {
            // Content DOM node containing the DOM structure of the clipboard
            alert(o.node.innerHTML);
        }
																		
	});
}

function iniciarTinyMCE_mensajeriainterna(){
	tinyMCE.init({
		theme : "advanced",
		language : "es",			
				elements : 'nourlconvert',
		convert_urls : false,
		mode : "none",
		plugins : "bbcode, paste",
		verify_html:true,
		theme_advanced_buttons1 : "bold,italic,underline,undo,redo,forecolor,removeformat,cleanup",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		content_css : "css/bbcode.css",
		convert_urls : true,
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		convert_fonts_to_spans : false,
		paste_auto_cleanup_on_paste : true,						
        paste_preprocess : function(pl, o) {
            // Content string containing the HTML from the clipboard
            alert(o.content);
        },
        paste_postprocess : function(pl, o) {
            // Content DOM node containing the DOM structure of the clipboard
            alert(o.node.innerHTML);
        }
																		
	});
}


function iniciarTinyMCE_mensajeriamuro(){
	tinyMCE.init({
		theme : "advanced",
		language : "es",						
		mode : "none",
				elements : 'nourlconvert',
		convert_urls : false,
		plugins : "bbcode, paste",
		verify_html:true,
		theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,bullist,numlist,forecolor,removeformat,cleanup,code,image",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,selectall",
		theme_advanced_buttons3 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		content_css : "css/bbcode.css",
		convert_urls : true,
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		convert_fonts_to_spans : false,
		paste_auto_cleanup_on_paste : true,						
        paste_preprocess : function(pl, o) {
            // Content string containing the HTML from the clipboard
            alert(o.content);
        },
        paste_postprocess : function(pl, o) {
            // Content DOM node containing the DOM structure of the clipboard
            alert(o.node.innerHTML);
        }
																		
	});
}

function ejecutarTinyMCE(){
	tinyMCE.execCommand('mceToggleEditor',false,'Mensaje');
}

function editarMensaje(idM){
	// Llamamos al script PHP
	$("#editar"+idM).hide();
	
	$.post("/ajax/editarMensaje.php", { Mensaje_Id: idM }, function(data){
		$("#"+idM).html(data);
		tinyMCE.execCommand("mceToggleEditor",false,"Mensaje"+idM);
		
		var form = "#formEditarMensaje"+idM;		
		var options = { 
	        target:        '#'+idM,   // target element(s) to be updated with server response 
	        beforeSubmit:  showRequest,  // pre-submit callback 
	        success:       showResponse  // post-submit callback
		};
				
		$(form).ajaxForm(options);
    	
    	function showRequest(formData, jqForm, options) { 
		    var queryString = $.param(formData);
		    //alert('About to submit: \n\n' + queryString);
		    tinyMCE.execCommand('mceRemoveControl', false, "Mensaje"+idM);
		    return true;
		}
		
		function showResponse(responseText, statusText)  {
		    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.');
		    $("#editar"+idM).show(); 
		}
	});
}