function init_tinyMCE_advanced() {
	tinyMCE.init({
		theme : "advanced",
		editor_selector : "largeBoxContent",
		language: "de",
		mode : "none",
		/*
		theme_advanced_buttons1 : "bold,italic,underline,undo,redo,link,unlink,fontsizeselect,forecolor,cleanup",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		plugins : "autoresize",
		*/
		
	    theme_advanced_buttons1 : "save,preview,mykimage,emotions,separator,bold,italic,underline,strikethrough,separator,"+
	    "charmap,forecolor,backcolor,separator,bullist,numlist,undo,redo",
	    theme_advanced_buttons2 : "justifyleft,justifycenter,"+
	    "justifyright,justifyfull,outdent,indent,separator,"+
	    "link,unlink,separator,justifyleft,justifycenter,justifyright,fontsizeselect,separator,spellchecker",
		theme_advanced_buttons3 : "",
		plugins : "autoresize,spellchecker,preview,save,emotions,mykimage,mykyoutube,media",
		/*
		 plugins : "spellchecker,fullscreen,searchreplace,preview,print,save,table",
	    theme_advanced_buttons1 : "preview,print,save,fullscreen,separator,image,separator,"+
	    "spellchecker,separator,tablecontrols ",
	    theme_advanced_buttons2 : "code,separator,bold,italic,underline,strikethrough,"+
	    "charmap,forecolor,backcolor,separator,bullist,numlist,undo,redo",
	    theme_advanced_buttons3 : "removeformat,formatselect,justifyleft,justifycenter,"+
	    "justifyright,justifyfull,outdent,indent,separator,"+
	    "link,unlink,separator,justifyleft,justifycenter,justifyright,separator,"+
	    "cut,copy,paste,separator,search,replace,separator",
	    */
	    convert_fonts_to_spans : false,
	    spellchecker_languages : "+Deutsch=de",
	    
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_link_targets: false,
		content_css : "/styles/wysiwyg.css",
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		font_size_style_values : "8,10,12,14,16,18,20",
		popup_css_add : "/styles/tinymcepopup.css",
		
	    relative_urls : false,
	    convert_urls : false
	});
}
function init_tinyMCE_simple() {
	tinyMCE.init({
		theme : "advanced",
		editor_selector : "smallBoxContent",
		language: "de",
		mode : "none",
		
		theme_advanced_buttons1 : "save,bold,italic,underline,link,fontsizeselect",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		plugins : "autoresize,save",
		
	    convert_fonts_to_spans : false,
	    spellchecker_languages : "+Deutsch=de",
	    
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_link_targets: false,
		content_css : "/styles/wysiwyg.css",
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		font_size_style_values : "8,10,12,14,16,18,20",
		popup_css_add : "/styles/tinymcepopup.css",
		
	    relative_urls : false,
	    convert_urls : false
	});
}
function init_tinyMCE_PN() {
	tinyMCE.init({
		theme : "advanced",
		editor_selector : "smallBoxContent",
		language: "de",
		mode : "none",
		
		theme_advanced_buttons1 : "bold,italic,underline,link,fontsizeselect,forecolor",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		plugins : "autoresize,save",
		
	    convert_fonts_to_spans : false,
	    spellchecker_languages : "+Deutsch=de",
	    
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "center",
		theme_advanced_link_targets: false,
		content_css : "/styles/wysiwyg.css",
		entity_encoding : "raw",
		add_unload_trigger : false,
		remove_linebreaks : false,
		inline_styles : false,
		font_size_style_values : "8,10,12,14,16,18,20",
		popup_css_add : "/styles/tinymcepopup.css",
		
	    relative_urls : false,
	    convert_urls : false
	});
}

var last_wysiwyg_edit=false;
var edid_cnt=0;
function makeeditable(contentdiv, sethidden)
{
	var edid=false;
	if (!$(contentdiv).id)
	{
		edid_cnt=edid_cnt+1;
		$(contentdiv).set('id',"edid_"+edid_cnt);
	}
	edid=$(contentdiv).id;
	
	if ( $(contentdiv).hasClass('MCE_PN'))
	{
		init_tinyMCE_PN();
	}
	else if ($(contentdiv).hasClass('largeBoxContent') || $(contentdiv).hasClass('MCE_advanced'))
	{
		init_tinyMCE_advanced();
	} else {
		init_tinyMCE_simple();
	}
	
	if (last_wysiwyg_edit!=false)
	{
//		makeuneditable(last_wysiwyg_edit);
	}
	
	if (tinyMCE.execCommand('mceAddControl',false,edid))
	{
		last_wysiwyg_edit=contentdiv;
		if ($(sethidden))
		{
			$(sethidden).addClass('hidden');
		}
	}
}

/* remove wysiwyg-editor from control */
function makeuneditable(contentdiv)
{
	if ((last_wysiwyg_edit==contentdiv) || (!contentdiv && last_wysiwyg_edit!=false))
	{
		tinyMCE.execCommand('mceRemoveControl',false,last_wysiwyg_edit);
		last_wysiwyg_edit = false;
	}
}

function makeuneditable2(name)
{
	tinyMCE.execCommand('mceRemoveControl',false,name);
}

function savewysiwyg(form, sendtourl, variable)
{
	var contentdiv=$(form).getElements('div');
	contentdiv=contentdiv[0].get('id');
	var content = tinyMCE.get(contentdiv).getContent();
				makeuneditable(contentdiv);
			
				var postdata = {};
				postdata['js_profil_user_id'] = js_profil_user_id;
				postdata[variable] = content;
				
				new Request({
					method: 'post',
					url: sendtourl,
					data: postdata,
					onSuccess: function(){reloadbox(contentdiv);}
				}).send();	
	return false;
}

function wysiwyg_focus()
{
	tinyMCE.execCommand('mceFocus',false);
}

function wysiwyg_cleanup()
{
	tinyMCE.execCommand('mceCleanup',false);
}

function wysiwyg_setcontent(html)
{
	tinyMCE.execCommand('mceInsertContent',false,html);
}

