﻿cn.liusoft.createNameSpace("page");

$().ready(function() {


    /*-----设定控件当焦点进入离开时的事件----*/
    $("#ui_txtGuestBookContent").focus(function() {
        if ($(this).val() == "在此填写您的问题，问题被默认回复到本页面，请您记得回来查看！") {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val("在此填写您的问题，问题被默认回复到本页面，请您记得回来查看！");
        }
    })


    $("#ui_txtName").focus(function() {
        if ($(this).val() == "联系姓名") {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val("联系姓名");
        }
    })

    $("#ui_txtTel").focus(function() {
        if ($(this).val() == "联系电话") {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val("联系电话");
        }
    })

    $("#ui_txtQQ").focus(function() {
        if ($(this).val() == "联系QQ") {
            $(this).val("");
        }
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val("联系QQ");
        }
    })
    /*-----end设定控件当焦点进入离开时的事件----*/

    //设置checkbox控件的click事件
    $("#chk").click(function() {
        if ($(this).attr("checked") == true) {

            $("#btn").fadeTo("slow", 0, function() {
                $(this).attr("class", "input-big");
            })
            $(".row-3").show("3000");
            // $(".row-3").css("display", "block");
            $(".reply").height("160px");
            $("#btn").fadeTo("slow", 1);
            $("#btn").show("slow");
        } else {
            $("#btn").fadeTo("slow", 0, function() {
                $(this).attr("class", "input-small");
            })
            $(".row-3").hide("3000");
            // $(".row-3").css("display", "none");
            $(".reply").height("130px");
            $("#btn").fadeTo("slow", 1);
            $("#btn").show("slow");
        }

    });

    //鼠标滑过时改变样式
    $("#chk-text").mouseover(function() {
        $(this).css("text-decoration", "underline");
    }).mouseout(function() {
        $(this).css("text-decoration", "none");
    });


}
);
        
        
//提交留言
page.addGuestBook = function() {


    var errorInfo = "请您修改以下错误：";
    var replayContent = document.getElementById("ui_txtGuestBookContent").value;
    if (replayContent.length < 5 || replayContent == "在此填写您的问题，问题被默认回复到本页面，请您记得回来查看！") {
        errorInfo += "\n留言内容少于5个字符！";
    }

    if (document.getElementById("chk").checked == true) {
        var replyName = document.getElementById("ui_txtName").value;
        if (replyName.length < 2 || replyName == "联系姓名") {
            errorInfo += "\n联系姓名输入有误！";
        }

        var replyTel = document.getElementById("ui_txtTel").value;
        var replyQQ = document.getElementById("ui_txtQQ").value;

        if (replyQQ == "联系QQ" && replyTel == "联系电话") {
            errorInfo += "\n联系电话或联系QQ至少应输入一个！";
        } else {
            if (replyTel.length < 8 && replyQQ.length < 7 && replyQQ != "联系QQ" && replyTel != "联系电话") {
                errorInfo += "\n联系电话输入有误！";
                errorInfo += "\n联系QQ输入有误！";
            } else {

                if (replyTel.length < 8 && replyQQ == "联系QQ") {
                    errorInfo += "\n联系电话输入有误！";
                }

                if (replyQQ.length < 7 && replyQQ == "联系电话") {
                    errorInfo += "\n联系QQ输入有误！";
                }
            }
        }

    }

    if (errorInfo != "请您修改以下错误：") {
        alert(errorInfo);
        return;
    }

    if (replyName == undefined) {
        replyName = "";
    }

    if (replyQQ == "联系QQ" || replyQQ == undefined) {
        replyQQ = "";
    }
    if (replyTel == "联系电话" || replyTel == undefined) {
        replyTel = "";
    }

    cn.liusoft.importJS("cn.liusoft.ajax.HttpRequest");
    var xmlhttp = new cn.liusoft.ajax.HttpRequest("/product/ajaxaction.aspx", page.addGuestBook_onComplete, page.addGuestBook_onError);

    xmlhttp.addFormData("AjaxAction", "添加留言");
    xmlhttp.addFormData("replayContent", escape(replayContent));
    xmlhttp.addFormData("replyName", replyName);
    xmlhttp.addFormData("replyTel", replyTel);
    xmlhttp.addFormData("replyQQ", replyQQ);
    xmlhttp.addFormData("subjectType", "2");

    xmlhttp.doCallBack();
}

page.addGuestBook_onComplete = function(responseText, responseXML) {
    eval(responseText);

    if (isOK)
    {
        if (commentID > 0) { //没有填写联系资料
            tb_show('', '/comment/commentContactInfo-edit.aspx?id=' + commentID + '&KeepThis=true&TB_iframe=true&height=185&width=370', false);
            return;
        } else {
            document.getElementById("ui_txtGuestBookContent").value = "在此填写您的问题，问题被默认回复到本页面，请您记得回来查看！";
            document.getElementById("ui_txtName").value = "联系姓名";
            document.getElementById("ui_txtTel").value = "联系电话";
            document.getElementById("ui_txtQQ").value = "联系QQ";

            window.location.reload();
        }
        alert("恭喜，您的问题已成功提交！");
    }
    else {
        if (commentID == -1) {
            alert("留言超时！");
        } else if (commentID == -2) {
            alert("请您一分钟后再进行留言！");
        } else {
            alert("提交失败，请重试！");
        }
    }
};
page.addGuestBook_onError = function(status, statusText, responseText) {
    alert("发生错误，请重试！");
};

