﻿function show_Text(controlId) {
    $('#V2editBackground').hide();
    var controlconfig = GetControlConfigData(controlId);
    var Content = controlmodeldata[controlId];
    var data = { "Content": Content,
        "controlconfig": controlconfig
    };
    $('#' + controlId).html(TrimPath.parseTemplate(textarea).process(data));
}

function show_EditText(controlId) {
    var welcomeMessageModelData = controlmodeldata[controlId];
    $('#V2editBackground').show();
    var controlconfig = GetControlConfigData(controlId);
    var editorsize = GetMaxEditorSize(0, controlconfig.EditorHeightOffset);
    if (controlconfig.EditorHeight != 9999) {
        editorsize.height = controlconfig.EditorHeight;
    }
    if (controlconfig.EditorWidth != 9999) {
        editorsize.width = controlconfig.EditorWidth;
    }
    var content = welcomeMessageModelData.DraftContent;
    content = content.replace(/'/g, "&#39");
    TE_ShowTextEditor(controlId, '', content, '', 'Edit Text', '', editorsize.width, editorsize.height, 1, 'save_EditText', 'close_EditText', '', '', '');
}

function close_EditText(controlId, param1, param2) {
}
function save_EditText(controlId, content, param1, param2) {
    controlmodeldata[controlId].DraftContent = content;
    var data0 = { 'content': controlmodeldata[controlId] };
    var json = JSON.stringify(data0);
    $.ajax({
        type: "POST",
        url: "/Model/CMS/Admin/Model.asmx/SaveContentItem",
        data: json,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            show_Text(controlId);
            hide_EditText(controlId);
        },
        error: updatefailed
    });

}

function hide_EditText(controlId) {
    $('#V2editBackground').hide();
    $('#V2editControl').html("");
    $('#V2editControl').hide();
}

function updatefailed(msg) {
    alert('an error occured while updating this content, please try again');
}

function save_Text(controlId) {
}