$(function () {
    var BuyNum = $("#BuyNum"), agreement = $("#agreement"),
    allFields = $([])
    .add(agreement).add(BuyNum)
    ;
    function ValidTemp() {
        var bValid = true;
        allFields.removeClass("ui-state-error");
        bValid = bValid && checkNumlength(BuyNum, "购买数量", 1, 2147483647);
        bValid = bValid && checkCheckBoxIsCheck(agreement, "");
        return bValid;
    }
    $("#CreateForm").submit(function () {
        showDiv("<img src=\"/common/images/loading.gif\">订单处理中，请稍候...", false);
        //return false;
    });
    $("a[name=CreateSubmit]").click(function () {
        if (ValidTemp()) {
            $("#CreateForm").submit();
        }
    });
    /*数据初始化开始*/
    var DefaultMonPrice = 0;
    var DefaultThPrice = 0;
    var DefaultHfPrice = 0;
    var DefaultYearPrice = 0;
    if ($(".RelMon").length > 0) {
        DefaultMonPrice = $(".RelMon").html() - 0;
    }
    if ($(".RelTh").length > 0) {
        DefaultThPrice = $(".RelTh").html() - 0;
    }
    if ($(".RelHf").length > 0) {
        DefaultHfPrice = $(".RelHf").html() - 0;
    }
    if ($(".RelYear").length > 0) {
        DefaultYearPrice = $(".RelYear").html() - 0;
    }
    //初始化订单价格
    var BuyType = $("[name=BuyType]").val();

    var BuyTypeHolderName = "";//购买方式容器名称
    if (BuyType == "1")//月付
    {
        BuyTypeHolderName = "Mon";
    }
    else if (BuyType == "2")//季付
    {
        BuyTypeHolderName = "Th";
    }
    else if (BuyType == "3")//半年付
    {
        BuyTypeHolderName = "Hf";
    }
    else if (BuyType == "4")//年付
    {
        BuyTypeHolderName = "Year";
    }
    $(".PayPrice").html($(".Rel" + BuyTypeHolderName).html());//填充订单价格
    /*初始化结束*/
    $(".ProAttr li").mouseover(function () {
        $(this).css("background-color", "#eee");
    });
    $(".ProAttr li").mouseout(function () {
        $(this).css("background-color", "");
    });
    $("[name=UseFree],[name=BuyType]").change(function () {//试用按钮、付款方式
        CheckBuyMoney();
    });
    $("[name=BuyNum]").keyup(function () {//购买期限
        CheckBuyMoney();
    });
    function CheckBuyMoney() {
        //填充本次订单价格
        if ($("[name=UseFree]").attr("checked")) {//如果是试用，则填充本次价格为0元
            $(".PayPrice").html("0");//填充订单价格
        } else {
            BuyType = $("[name=BuyType]").val();
            if (BuyType == "1")//月付
            {
                BuyTypeHolderName = "Mon";
            }
            else if (BuyType == "2")//季付
            {
                BuyTypeHolderName = "Th";
            }
            else if (BuyType == "3")//半年付
            {
                BuyTypeHolderName = "Hf";
            }
            else if (BuyType == "4")//年付
            {
                BuyTypeHolderName = "Year";
            }
            $(".PayPrice").html($(".Rel" + BuyTypeHolderName).html() * $("[name=BuyNum]").val());//填充订单价格
        }
    }
});