﻿function userForm() {
    if (document.getElementById("yzm").style.display != "block") {
        changeVcode();
        document.getElementById("yzm").style.display = "block";
    }

}

function changeVcode() {
    document.getElementById("img_CheckCode").src = "/xn/comm_CheckCode.aspx?k=" + Math.random();
}

function qqhInfo() {
    if (document.getElementById("chk_QQH").checked) {
        alert("您选择了悄悄话，您所提交的评论信息只有管理员才能看到！\r\n\r\n如果您希望得到管理员的回复，请在内容中留下您的联系方式。");
    }
    document.getElementById("txt_Content").focus();
}

function alertCharNums(content) {
    var MaxLength = 2000;
    var txt_Content = document.getElementById("txt_Content");
    if (txt_Content.value.length > MaxLength) {
        txt_Content.value = txt_Content.value.substring(0, MaxLength);
    }
    document.getElementById("char_nums").innerHTML = txt_Content.value.length;
}

function comment_check() {
    var txt_Content = document.getElementById("txt_Content").value;
    var txt_CheckCode = document.getElementById("txt_CheckCode").value;
    var chk_QQH = document.getElementById("chk_QQH").checked ? 1 : 0;

    if (txt_Content == "") {
        alert("您输入的评论内容为空!");
        document.getElementById("txt_Content").focus();
        return false;
    }

    if (txt_Content.length < 5) {
        alert("您输入的字数太少!");
        document.getElementById("txt_CheckCode").focus();
        return false;
    }

    if (txt_Content.length > 600) {
        alert("您输入的长度超过600字节!");
        document.getElementById("txt_CheckCode").focus();
        return false;
    }

    txt_Content = encodeURIComponent(txt_Content);

    if (txt_CheckCode.length == 0) {
        alert("请填写验证码!");
        document.getElementById("txt_CheckCode").focus();
        return false;
    }
    if (txt_CheckCode.length != 4) {
        alert("验证码长度不对!");
        document.getElementById("txt_CheckCode").focus();
        return false;
    }


    var AddUrl = "/xn/comment_add.aspx?CheckCode=" + txt_CheckCode + "&QQH=" + chk_QQH + "&ID=" + com_ArticleID + "&Content=" + txt_Content;

    var xhttp = GetHttp();

    xhttp.open("GET", AddUrl, false);

    xhttp.send(null);

    GetResult(com_ArticleID);

    alert("评论发表成功！");
}

function GetHttp() {
    var xhttp = null;
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    }
    else {
        if (window.ActiveXObject) {
            try {
                xhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
            }
            if (xhttp == null) {
                try {
                    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {
                }
            }
        }
    }
    return xhttp;
}

function GetResult(id) {
    var xhttp = GetHttp();

    xhttp.open("GET", "/xn/comment_read.aspx?id="+id, false);

    xhttp.send(null);

    var Result = xhttp.responseText;
    xhttp.abort();
    xhttp = null;

    var count_wz = Result.indexOf(",");
    var comment_count = Result.substring(0, count_wz);
    Result = Result.substr(count_wz+1);

    document.getElementById("comment_count").innerHTML = comment_count;
    document.getElementById("comment_read").innerHTML = Result;
}
var com_ArticleID = document.getElementById("comment_read").innerHTML;
GetResult(com_ArticleID);
