﻿
var Content_IncludeFCKeditor = false;
function content_edit(id, uniqueId) {
    if (!Content_IncludeFCKeditor) {
        IncludeFile("/FCKeditor/fckeditor.js", "js");
        Content_IncludeFCKeditor = true;
    }
    var content = document.getElementById(id);
    content.ondblclick = null;
    var oldValue = content.innerHTML;
    var textarea = document.createElement("TEXTAREA");
    textarea.id = id + "_textarea";
    var tmpValue = oldValue.toLowerCase().replace(/\s/gi, "");
    if (tmpValue != '<spanstyle="color:#cccccc">双击这里编辑内容</span>' && tmpValue != '<spanstyle="color:rgb(204,204,204);">双击这里编辑内容</span>') {
        textarea.value = oldValue;
    }
    content.innerHTML = "";
    content.appendChild(textarea);

    content.appendChild(document.createElement("BR"));

    var btnOK = document.createElement("INPUT");
    btnOK.type = "button";
    btnOK.value = "确定";
    btnOK.onclick = function() {
        var oEditor = FCKeditorAPI.GetInstance(textarea.id);
        var value = oEditor.GetXHTML(true);
        if (window.__theFormPostData) {
            window.__theFormPostData = "";
        }
        if (window.WebForm_InitCallback) {
            window.WebForm_InitCallback();
        }
        content.uniqueId = uniqueId;
        Content_OnCallback(uniqueId, value, content);
    };
    content.appendChild(btnOK);

    var text1 = document.createTextNode("  ");
    content.appendChild(text1);

    var btnCancel = document.createElement("INPUT");
    btnCancel.type = "button";
    btnCancel.value = "取消";
    btnCancel.onclick = function() {
        content.innerHTML = oldValue;
        content.ondblclick = new Function("content_edit('" + content.id + "','" + uniqueId + "')");
    }
    content.appendChild(btnCancel);

    var oFCKeditor = new FCKeditor(textarea.id);
    oFCKeditor.ToolbarSet = 'Basic';
    oFCKeditor.Height = '200px';
    oFCKeditor.Width = (content.offsetWidth-10) + "px";
    oFCKeditor.ReplaceTextarea();
}

function Content_ReceiveServerData(args, context) {
    var oEditor = FCKeditorAPI.GetInstance(context.id + "_textarea");
    context.innerHTML = oEditor.GetXHTML(true);
    context.ondblclick = new Function("content_edit('" + context.id + "','" + context.uniqueId + "')");
}

function Content_ReceiveServerDataError(args, context) {
    alert(args);
}