﻿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 GetQueryString(name) {
   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
   var r = window.location.search.substr(1).match(reg);
   if (r!=null) return unescape(r[2]); return null;
}

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;
    var ID = GetQueryString("ID");
    
    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;
    }

    window.location.href = "/xn/comment_add.aspx?CheckCode=" + txt_CheckCode + "&QQH=" + chk_QQH + "&ID="+ID+"&Content=" + txt_Content;
}
