﻿// JScript 文件
var curId = null;
function InitBrowse()
{
    curId = gid("curId").value;
    var b = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.UpdateBlogBrowse(curId).value;
    var otherInfo = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.GetBlogOrderInfo(curId).value;
    MyshuiyueSetting["UserID"] = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.GetSessionUser().value;
    var tempVicinage = otherInfo.split("|");
    gid("lb_browse").innerHTML = tempVicinage[0];
    gid("lb_track").innerHTML = tempVicinage[1];
    gid("lb_comment").innerHTML = tempVicinage[2];
    setTimeout("showCommit()",400);
    initCookie();
    setTimeout("showVicinage()", 800);
    //showNewBlogs();
}

function showVicinage() {
    var Vicinage = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.GetBlogVicinage(curId).value;
    var tempVicinage = Vicinage.split("$");
    if (tempVicinage[0].length > 0) {
        gid("a_leftVicinage").style.display = "";
        gid("a_leftVicinage").innerHTML = "&lt;&lt;" + tempVicinage[0].split("@")[0];
        gid("a_leftVicinage").src = tempVicinage[0].split("@")[1];
    }
    else
        gid("a_leftVicinage").style.display = "none";
    if (tempVicinage[1].length > 0) {
        gid("dv_rightVicinage").innerHTML = "<a id=\"a_rightVicinage\" href=\"" + tempVicinage[1].split("@")[1] + "\">" + tempVicinage[1].split("@")[0] + "&gt;&gt;</a>";
    }
    else
        gid("a_rightVicinage").style.display = "none";
}


function initCookie()
{
    gid("ipt_c_Name").value = getCookie('Myshuiyue_blog_commit_Name');
    gid("ipt_c_Email").value = getCookie('Myshuiyue_blog_commit_Email');
    gid("ipt_c_Web").value = getCookie('Myshuiyue_blog_commit_Web');
}

function showCommit()
{
    Myshuiyue.BusinessRules.Blog.BlogViewBusiness.getBlogCommit(curId,cb_showCommit);
}

function cb_showCommit(res)
{
    if(res == null || res.value == null)
    {
        alert("读取数据出错。");
        return;
    }
    var table = res.value;
    if(table.Rows.length > 0)
    {
        var strHtml = "<div style=\"width:100%; border-top:dashed 1px #989898; height:1px; margin:15px 0px;\"></div><div class=\"crosshead\">+ 文章评论</div>", oneRows = null;
        var strlink = "",strdel = "";
        for(var i = 0; i < table.Rows.length; i++)
        {
            oneRows = table.Rows[i];
            if(oneRows.commitWeb == null || oneRows.commitWeb.length == 0)
                strlink = oneRows.commitName
            else
                strlink = "<a href='" + oneRows.commitWeb + "' target='_blank' title='" + oneRows.commitName + "'>" + oneRows.commitName + "</a>";
                
            if(MyshuiyueSetting["UserID"] != -1)
                strdel = " <a href='javascript:void(0);' onclick='delcommit(" + curId + "," + oneRows.ID + ");'>删除</a>";
            else
                strdel = "";
            strHtml += "<ul>\
                            <li style='border:0px; padding:0px; margin:0px;'><span><img src='/images/quote.gif' /> " + strlink + "</span> - " + DateFormat(oneRows.commitTime) + strdel + "</li>\
                            <li>" + oneRows.commitContent + "</li>\
                        </ul>"
        }
        gid("div_commitlist").innerHTML = strHtml;
    }
    
}

function delcommit(aid,cid)
{
    if(!confirm("确定要删除吗？"))
        return;
    Myshuiyue.BusinessRules.Blog.BlogViewBusiness.delBlogCommit(aid,cid,cb_delcommit);
}

function cb_delcommit(res)
{
    if(res == null || res. value == null || res.value == 0)
    {
        alert("操作数据出错。");
        return;
    }
    if(res.value == -1)
    {
        alertLoginError();
        return;
    }
    if(res.value == 1)
        showCommit();
}

function showNewBlogs()
{
    Myshuiyue.BusinessRules.Blog.BlogViewBusiness.getNewBlogs(10,cb_showNewBlogs);
}

function cb_showNewBlogs(res)
{
    if(res == null || res. value == null)
    {
        alert("读取数据出错。");
        return;
    }
    var table = res.value;
    if(table.Rows.length > 0)
    {
        var strHtml = "<div class=\"left_title\">最近发表</div><ul>", oneRows = null;
        for(var i = 0; i < table.Rows.length; i++)
        {
            oneRows = table.Rows[i];
            strHtml += "<li><a href=\"" + oneRows.articleUrl + "\">" + oneRows.Title + "</a></li>";
        }
        gid("left_newblogs").innerHTML = strHtml + "</ul>";
    }
}

function saveCommit()
{
    var cName = Trim(gid("ipt_c_Name").value);
    if(cName == "")
    {
        alert("名称不能为空。");
        return;
    }
    var cContent = Trim(gid("ta_c_content").value);
    if(cContent.length == 0)
    {
        alert("评论内容不能为空。");
        return;
    }
    var cCode = Trim(gid("ipt_c_code").value);
    if(cCode == "")
    {
        alert("验证码不能为空。");
        return;
    }
    var Validator = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.ValidatorCommitCode(cCode).value;
    if(Validator != 0)
    {
        alert("验证码输入错误。");
        return;
    }
    var cEmail = Trim(gid("ipt_c_Email").value);
    var cWeb = Trim(gid("ipt_c_Web").value);
    var cookie = gid("chk_cookie").checked;
    var res = Myshuiyue.BusinessRules.Blog.BlogViewBusiness.addBlogCommit(curId,cName,cEmail,cWeb,cContent).value;
    //alert(res);
    if(res == 1)
    {
        if(cookie)
        {
            SetCookie("Myshuiyue_blog_commit_Name",cName);
            SetCookie("Myshuiyue_blog_commit_Email",cEmail);
            SetCookie("Myshuiyue_blog_commit_Web",cWeb);
        }
        showCommit();
    }
    else
        alertDataError();
}