﻿
function AddNew(name, email, home, comment, articleid, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?articleid=" + articleid + "&action=save&name=" + escape(name) + "&email=" + escape(email) + "&home=" + escape(home) + "&comment=" + escape(comment),
        success: function(result) {
            GetCommetList(articleid, sp);

        }
    });
}

function ReplyNone(name, email, home, comment, articleid, id, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?articleid=" + articleid + "&id=" + id + "&action=reply&name=" + name + "&email=" + email + "&home=" + home + "&comment=" + comment + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            $("#" + sp).append(result);
        }
    });
}

function Approve(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?id=" + id + "&action=approve" + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            if (result > 0) {
                $("#" + sp).empty();
                $("#" + sp).append(result);
            }
            else {
                alert("您不能重复投票!!");
            }
        }
    });
}

function Against(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?id=" + id + "&action=against" + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            if (result > 0) {
                $("#" + sp).empty();
                $("#" + sp).append(result);
            }
            else {
                alert("您不能重复投票!!");
            }
        }
    });
}

function ReportError(id) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?id=" + id + "&action=reporterror",
        success: function(result) {
            alert("举报成功!!");
        }
    });
}

function GetCommetList(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?" + "action=getcommentlist&articleid=" + id + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            $("#" + sp).empty();
            $("#" + sp).append(result);

        }
    });
}

function GetHotComment(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?action=gethotcomment&articleid=" + id + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {

            $("#" + sp).empty();
            $("#" + sp).append(result);

        }
    });
}


function getNewList(page, sp, type) {
    $.ajax({
        url: "/zh-CN/Info/InforAction.aspx?action=getlist&key=" + type + "&page=" + page,
        success: function(result) {
            $("#" + sp).empty();
            $("#" + sp).append(result);
        }
    });
}

function ApproveArticle(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/InforAction.aspx?action=approvearticle&id=" + id + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            if (result > 0) {
                $("#" + sp).empty();
                $("#" + sp).append(result);

            } else {
                alert("您已经顶过了。");
            }
        }
    });
}

function GetApproveArticleCount(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/InforAction.aspx?action=getapprovecount&id=" + id + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {
            $("#" + sp).empty();
            $("#" + sp).append(result);
        }
    });
}

function GetPageList(type, page, sp) {
    $.ajax({
        url: "/zh-CN/Info/InforAction.aspx?action=getpage&key=" + type + "&page=" + page,
        success: function(result) {

            $("#" + sp).empty();
            $("#" + sp).append(result);

        }
    });
}


function ClickArticle(id, sp) {
    $.ajax({
        url: "/zh-CN/Info/InforAction.aspx?action=clickarticle&id=" + id + "&random=" + Math.round(Math.random() * 10000),
        success: function(result) {

            $("#" + sp).empty();
            $("#" + sp).append(result);

        }
    });
}

function CheckCode(code, sp, articleid) {
    $.ajax({
        url: "/zh-CN/Info/comment.aspx?action=getcode&code=" + code,
        success: function(result) {
            if (result.indexOf("Enable") >= 0) {
                AddNew($("#txtName").val(), $("#txtEmail").val(), $("#txtHome").val(), $("#txtContent").val(), articleid, sp);

                $("#txtName").val('');
                $("#txtEmail").val('');
                $("#txtHome").val('');
                $("#txtContent").val('');
                $("#txtCode").val('');
            }
            else {
                alert('验证码输入错误!');
                getCodeFromAjax(sp);
            }
        }
    });
}

function getCodeFromAjax(sp) {
    $.ajax({
        url: "/Library/ValidateCode.aspx",
        success: function(result) {
            $("#" + sp).empty();
            $("#" + sp).append("<img alt='验证码' src='/Library/ValidateCode.aspx?id=" + Math.round(Math.random() * 10000) + "' style='vertical-align: middle;' />");
        }
    });
}

function getCode(sp) {
    if ($("#sShow").css("display") == "none") {
        $.ajax({
            url: "/Library/ValidateCode.aspx",
            success: function(result) {
                $("#" + sp).empty();
                $("#" + sp).append("<img alt='验证码' src='/Library/ValidateCode.aspx?id=" + Math.round(Math.random() * 10000) + "' style='vertical-align: middle;' />");
                $("#sShow").show();
            }
        })
    }
}

function getPage(key, page) {
    $('#newscontent').empty();
    $('#newscontent').append("<div style='width: 100%; text-align: center;'><img src='/zh-CN/img/indicator_medium.gif' width='32px;' height='32px;' /></div>");
    getNewList(page, 'newscontent', key);
    createPage(key, page);
}

function getLable(key) {
    getPage(key, 1);
}

function createPage(key, page) {
    GetPageList(key, page, 'newspage')
}
