
// - TinyMCE ------------------------------------------------------------------
//
// Have adopted the standard textEditor_id as textarea identifier. This means we only need
// to pass  the id. This is so we can set the richText flag in the form, to preserve the stat in
// a submit request
function toggleEditor(id) {
    $("richText_" + id).value=!tinyMCE.getInstanceById("textEditor_" + id);
    id="textEditor_" + id;
    if (!tinyMCE.getInstanceById(id))
        tinyMCE.execCommand('mceAddControl', false, id);
    else
        tinyMCE.execCommand('mceRemoveControl', false, id);
}
// Alternative version which also toggles the message in the toggle button
function toggleEditorAndButton(button,id,onText,offText) {
    var datalen = button.firstChild.nodeValue.length;
    $("richText_" + id).value=!tinyMCE.getInstanceById("textEditor_" + id);
    id="textEditor_" + id;
    if (!tinyMCE.getInstanceById(id)) {
        tinyMCE.execCommand('mceAddControl', false, id);
        button.firstChild.deleteData(0,datalen);
        button.firstChild.insertData(0,onText);
    }
    else {
        tinyMCE.execCommand('mceRemoveControl', false, id);
        button.firstChild.deleteData(0,datalen);
        button.firstChild.insertData(0,offText);
    }
    return false;
}
// Extended version of the submitForm functions, which can handle the possible presence
// if a tinyMCE editor. 
function submitFormWithTinyMCE(id) {
    var form = $("comment_"+id+"_form");
    var update = $("comment_" +id);
    if (!tinyMCE.getInstanceById("textEditor_" + id));
    else tinyMCE.execCommand('mceRemoveControl', false, "textEditor_" + id);
    var args = { method: 'post', update: update, evalScripts: true };
    form.send(args);
    return false;
}