function KeyPress() {
    if (event.keyCode == 13) {
        UserLogin();
    }
}

function CommentUserLogin() {
    var username = document.getElementById("txtCommentUserName").value;
    var password = document.getElementById("txtCommentPassWord").value;
    var code = document.getElementById("txtComment_Code").value;
    D.BLL.B_User.CommentAjaxLogin(username, password, "no", code, UserLogCommentCallBack);
}

function UserLogCommentCallBack(res) {
    if (res.value.split("|")[0] == "True") {
        document.getElementById("UserLogin").style.display = "none";
        document.getElementById("AddComment").style.display = "";
        switch (res.value.split("|")[1]) {
            case "text":
                document.getElementById("Text").style.display = "";
                document.getElementById("Ubb").style.display = "none";
                document.getElementById("Html").style.display = "none";
                break;
            case "ubb":
                document.getElementById("Text").style.display = "none";
                document.getElementById("Ubb").style.display = "";
                document.getElementById("Html").style.display = "none";
                break;
            case "html":
                document.getElementById("Text").style.display = "none";
                document.getElementById("Ubb").style.display = "none";
                document.getElementById("Html").style.display = "";
                break;
        }
        if (document.getElementById("imgVerify2") != null)
            document.getElementById("imgVerify2").src = document.getElementById("imgVerify2").src + Math.random();
    }
    else {
        alert(res.value.split("|")[0]);
    }
}

function SetComment() {
    var ModelId = document.getElementById("txtModelId").value;
    var ColId = document.getElementById("txtColId").value;
    var InfoId = document.getElementById("txtInfoId").value;
    var editor = document.getElementById("txtEditorType").value;
    var _editor = document.getElementById("txtEditor").value;
    var star = document.getElementById("txtStar").value;
    var TypeCount = document.getElementsByName("RadioPosition");
    var position;
    var p = 0;
    if (navigator.appName == "Microsoft Internet Explorer") {
        p = 1;
    }
    for (var i = p; i < TypeCount.length; i++) {
        if (TypeCount[i].checked) {
            position = TypeCount[i].value;
            break;
        }
    }
    var content = "";

    switch (editor) {
        case "text":
            content = document.getElementById("txtContent").value;
            break;
        case "ubb":
            content = document.getElementById("Ubb1_Content").value;
            break;
        case "html":
            switch (_editor) {
                case "fckeditor":
                    var oEditor = FCKeditorAPI.GetInstance("DianCMS_Content");
                    content = oEditor.GetXHTML(true);
                    break;
                case "ckeditor":
                    content = CKEDITOR.instances.DianCMS_Content.getData()
                    break;
                case "ueditor":
                    content = UE.getEditor('DianCMS_Content').getContent();
                    break;
                case "kindeditor":
                    content = DianCMS_Content_editor.html();
                    break;
            }
            break;
    }
    var code = "";
    if (document.getElementById("txtCommentCode") != null)
        code = document.getElementById("txtCommentCode").value;
    D.BLL.B_Comment.Add(ModelId, ColId, InfoId, content, code, star, position, InfoCallBack);
}

function InfoCallBack(res) {
    if (res.value == "True") {
        alert("成功发布评论");
        window.location.reload();
    }
    else {
        alert(res.value);
    }
}

function __start() {
    var initialize_width = 0;
    if (document.getElelmentById) { return false };
    if (document.getElementsByTagName == null) { return false; }
    var startLevelObj = document.getElementById("www_diancms_com");
    if (startLevelObj == null) { return false; }
    initialize_width = parseInt(startLevelObj.getAttribute("star_width"), 10);
    if (isNaN(initialize_width) || initialize_width == 0) { return false; }
    var ul_obj = startLevelObj.getElementsByTagName("ul");
    if (ul_obj.length < 1) { return false; }
    var length = ul_obj.length;
    var li_length = 0;
    var a_length = 0;
    var li_obj = null;
    var a_obj = null;
    var defaultInputObj = null;
    var defaultValue = null;
    for (var i = 0; i < length; i++) {
        li_obj = ul_obj[i].getElementsByTagName("li");
        li_length = li_obj.length;
        if (li_length < 0) { return false; }
        //获取默认值
        defaultInputObj = li_obj[0].getElementsByTagName("input"); if (!defaultInputObj) { return false; }
        defaultValue = parseInt(defaultInputObj[0].value, 10);
        if (!isNaN(defaultValue) && defaultValue != 0) {
            //alert("有初始值!");
            //li_obj[1].style.width=initialize_width*defaultValue+"px";
            //defaultValue=0;
        }
        for (var j = 0; j < li_length; j++) {
            a_obj = li_obj[j].getElementsByTagName("a");
            if (a_obj.length < 1) { continue; }
            if (a_obj[0].className.indexOf("star") > 0) {
                a_obj[0].onclick = function() {
                    return give_value(this);
                }
                a_obj[0].onfocus = function() {
                    this.blur();
                }
            }
        }
    }
}
function give_value(obj) {
    var status = true;
    var parent_obj = obj.parentNode;
    var i = 0;
    while (status) {
        i++;
        if (parent_obj.nodeName == "UL") { break; }
        parent_obj = parent_obj.parentNode;
        if (i > 1000) { break; } //防止找不到ul发生死循环
    }
    var hidden_input = parent_obj.getElementsByTagName("input")[0];
    if (hidden_input.length < 1) { /*alert("sorry?\nprogram error!")*/; }
    var txt = obj.firstChild.nodeValue; //确保不能存在空格哦，因为这里用的firstChild
    if (isNaN(parseInt(txt, 10))) { /*alert('level error!')*/; return false; }
    hidden_input.setAttribute("value", txt.toString());
    //固定选中状态,先找到初始化颜色那个li
    var current_li = parent_obj.getElementsByTagName("li");
    var length = current_li.length;
    var ok_li_obj = null;
    for (var i = 0; i < length; i++) {
        if (current_li[i].className.indexOf("current_rating") >= 0) {
            ok_li_obj = current_li[i]; break; //找到
        }
    }
    __current_width = txt * 14;
    document.getElementById("txtStar").value = txt;
    ok_li_obj.style.width = __current_width + "px";
    return false;
}
__start();