tinyMCE.init({
	mode : "specific_textareas",
	theme : "advanced",
    editor_selector : "wysiwyg",
	plugins : "contextmenu,paste",
	theme_advanced_buttons1 : "formatselect,bold,italic,bullist,numlist,separator,outdent,indent,link,unlink,separator,undo,redo,separator,charmap,separator,pastetext,pasteword,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_blockformats : "h3,h4,p",
	save_callback : "wrapWithParagraphs",
	invalid_elements : "font"
});

tinyMCE.init({
	mode : "specific_textareas",
	theme : "advanced",
    editor_selector : "wysiwyg_simple",
	theme_advanced_buttons1 : "bold,italic,bullist,numlist,charmap,separator,link,unlink,separator,undo,redo,separator,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	save_callback : "wrapWithParagraphs",
	invalid_elements : "font"
});

tinyMCE.init({
	mode : "specific_textareas",
	theme : "advanced",
    editor_selector : "wysiwyg_forum",
	plugins : "contextmenu,paste",
	theme_advanced_buttons1 : "formatselect,bold,italic,bullist,numlist,separator,outdent,indent,link,unlink,separator,undo,redo,separator,charmap,separator,pastetext,pasteword,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_blockformats : "h3,h4,p",
	save_callback : "wrapWithParagraphs",
	invalid_elements : "font"
});








// FUNCTION wrapWithParagraphs:
// This will attempt to wrap un-formatted text in <p> tags.
// NOTE: This will fail if unformatted text is followed by any other block element than <p>
// so future development may be necessary.

function wrapWithParagraphs(editor_id, html, body) {
    var tmp_html = html;
    tmp_html_arr = tmp_html.split("<p");
    if (tmp_html_arr.length > 0 && tmp_html_arr[0].length > 0 || tmp_html_arr.length == 0) {
        if (tmp_html_arr[0].indexOf("<h") == -1 && tmp_html_arr[0].indexOf("<pre") == -1 && tmp_html_arr[0].indexOf("<ul") == -1 && tmp_html_arr[0].indexOf("<ol") == -1) { // abandon if suspects other block tags (h1, h2, etc) came before first <p>
            tmp_html_arr[0] = "<p>" + tmp_html_arr[0] + "</p>";
            tmp_html = tmp_html_arr.join("<p");
        }
    }
    tmp_html = tmp_html.replace(/<p([^>]*)>\s*&nbsp;\s*<\/p>/gi, ''); // Strip empty paragraphs
    //return tinyMCE.convertStringToXML(tmp_html);
    return tmp_html;
}
