﻿function MessageAdd() {
    var oUserID = document.getElementById("UserID");
    
    if (oUserID.value == "0") {
        alert("请选会员登录后发帖！");
      
        return;
    }
    var oContent = document.getElementById("mContent");
    var strContent = oContent.value.RepHTML().trim();
    if (strContent== "") {
        alert("发帖内容不能为空");
        oContent.focus();
        return;
    }


    var oShopUserID = document.getElementById("ShopUserID");
    var URL = "AsynMessageAdd.aspx";
    var postStr = "ShopUserID=" + oShopUserID.value + "&strContent=" + escape(strContent);
   
    function MessageAddCallback(ajax) {

        var ret = ajax.responseText;
        if (ret == "succeed") {
            oContent.value = "";
            alert("留言成功！");          
        }    
        else
        {
         alert("留言失败！");
        }

    }
    DataRequest(URL, postStr, MessageAddCallback);

}
function ShowReply(id, type) {

    var DivReply = document.getElementById("divReply");
    var oA = document.getElementById("a-" + id);
    var oTitleReply = document.getElementById("titleReply");
    var oContent = document.getElementById("Content");
    var oDataID = document.getElementById("DataID");
    oDataID.value = id;

    if (type == "1") {
        oTitleReply.innerHTML = "回复（500汉字内）";
        oContent.value = "";
    }
    else {
        oTitleReply.innerHTML = "编辑回复（500汉字内）";

        var oSpan = document.getElementById("span-" + id);
        oContent.value = oSpan.innerText;
    }
    DivReply.style.left = getAbsoluteLeft(oA) - 400;
    DivReply.style.top = getAbsoluteTop(oA) - 8;
    DivReply.style.display = "";


}
function CanCelReply() {

    var DivReply = document.getElementById("divReply");
    DivReply.style.display = "none";
}
function SaveReply() {

    var oContent = document.getElementById("Content");
    var oDataID = document.getElementById("DataID");
    var strContent = oContent.value.RepHTML().trim();
    if (strContent == "") {
        alert("发帖内容不能为空");
        oContent.focus();
        return;
    }
    if (strContent.ByteCount() > 1000) {
        alert("发帖内容不能大于500个汉字或者1000个英文字母");
        oContent.focus();
        return;
    }
    var URL = "AsynShopExchangeReply.aspx";
    var postStr = "DataID=" + oDataID.value + "&strContent=" + escape(strContent);
    function SaveReplyCallback(ajax) {

        var ret = ajax.responseText;
        if (ret == "succeed") {
            window.location.href = "/?ndnum=" + Math.random() + "#shopexchange";

        }
        else if (ret == "faile") {
            alert("回复失败！");
        }
        else {
            alert(ret);
        }

    }
    DataRequest(URL, postStr, SaveReplyCallback);

}

function ShowPublish() {

    var oUserID = document.getElementById("UserID");

    if (oUserID.value == "0") {
        alert("请选登录会员后发帖！");

        return;
    }

    var DivPublish = document.getElementById("divPublish");
    var oA = document.getElementById("a-Publish");
    var oContent = document.getElementById("NewContent");
    DivPublish.style.left = getAbsoluteLeft(oA) - 400;
    DivPublish.style.top = getAbsoluteTop(oA) - 8;
    DivPublish.style.display = "";

}
function CancelPublish() {
    var DivPublish = document.getElementById("divPublish");
    DivPublish.style.display = "none";
}
function SavePublish() {

    var oShopUserID = document.getElementById("ShopUserID");
    var oContent = document.getElementById("NewContent");
    var strContent = oContent.value.RepHTML().trim();
    if (strContent == "") {
        alert("发帖内容不能为空");
        oContent.focus();
        return;
    }

    if (strContent.ByteCount() > 1000) {
        alert("发帖内容不能大于500个汉字或者1000个英文字母");
        oContent.focus();
        return;
    }
    var oAnony = document.getElementById("Anony");
    var Anony = "0";
    if (oAnony.checked) {
        Anony = "1";
    }
    var URL = "AsynShopExchangeAdd.aspx";
    var postStr = "ShopUserID=" + oShopUserID.value + "&Anony=" + Anony + "&strContent=" + escape(strContent);

    function SaveAddCallback(ajax) {

        var ret = ajax.responseText;
        if (ret == "succeed") {

            window.location.href = "/?ndnum=" + Math.random() + "#shopexchange";

        }
        else if (ret == "faile") {
            alert("发帖失败！");
        }
        else {
            alert(ret);
        }

    }
    DataRequest(URL, postStr, SaveAddCallback);
}
