﻿function TE_ShowTextEditor(controlId, buttons, content, texttype, title, subtitle, editorwidth, editorheight, editlayer, finishaction, closeaction, previousaction, param1, param2) {
    if (!param1) {
        param1 = '';
    }
    if (!param2) {
        param2 = '';
    }
    
    var data = { "content": content,
        "title": title,
        "subtitle": subtitle,
        "controlId": controlId,
        "editlayer": editlayer,
        "editorwidth": editorwidth,
        "editorheight": editorheight,
        "param1": param1,
        "param2": param2,
        "closeaction": closeaction,
        "finishaction": finishaction,
        "previousaction": previousaction
    };

    var viewresult = TrimPath.parseTemplate(te_text_edit).process(data);
    if (editlayer == 1) {
        
        document.getElementById('V2editControl').innerHTML = viewresult;
        //window.setTimeout(attachEditor('TextEditing_editor', '/CoreResources/DefaultWelcomeMessage.css', editorheight, 'V2editControl'),50);
        
        $('#V2editBackground').show();
        $('#V2editControl').show();
        centerObject('V2editControl');
        attachEditor('TextEditing_editor', '/CoreResources/DefaultWelcomeMessage.css', editorheight, 'V2editControl', content);
        tinyMCE.execCommand('mceFocus', false, 'TextEditing_editor');       
    }
    else {
        document.getElementById('V2editControl' + editlayer).innerHTML = viewresult;
        
        $('#V2editBackground' + editlayer).show();
        $('#V2editControl' + editlayer).show();
        centerObject('V2editControl' + editlayer);
        attachEditor('TextEditing_editor', '/CoreResources/DefaultWelcomeMessage.css', editorheight, 'V2editControl' + editlayer, content);
        tinyMCE.execCommand('mceFocus', false, 'TextEditing_editor');
    }    
}

function TE_TextEditor_Close(controlId, editlayer, closeaction, param1, param2) {
    if (editlayer == 1) {
        $('#V2editBackground').hide();
        $('#V2editControl').hide();
    }
    else {
        $('#V2editBackground' + editlayer).hide();
        $('#V2editControl' + editlayer).hide();
    }
    var action = closeaction + "('" + controlId + "', '" + param1 + "', '" + param2 + "')";
    eval(action);
}

function TE_TextEditor_Finish(controlId, editlayer, finishaction, param1, param2) {
    var content = $('#TextEditing_editor').tinymce().getContent({ format: 'text' });
    content = content.replace(/'/g, "&#39");
    if (editlayer == 1) {
        $('#V2editBackground').hide();
        $('#V2editControl').hide();
    }
    else {
        $('#V2editBackground' + editlayer).hide();
        $('#V2editControl' + editlayer).hide();
    }
    var action = finishaction + "('" + controlId + "', '" + content + "','" + param1 + "', '" + param2 + "')";
    eval(action);
}

function TE_TextEditor_Previous(controlId, editlayer, previousaction, param1, param2) {
//not implemented
}
