var pay_html_game = "您将为游戏充值,请确认下面的信息:<br/><br/>";
pay_html_game += "充值游戏:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}<br/>";
pay_html_game += "充值服务器: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{1}<br/>";
pay_html_game += "充值账户: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{2}<br/>";
pay_html_game += "付款方式: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{3}<br/>";
pay_html_game += "付款金额: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{4}<br/>";
pay_html_game += "将获得游戏币: &nbsp;{5}<br/>";

var pay_html_station = "您将为账户充值,请确认下面的信息:<br/><br/>";
pay_html_station += "充值账户: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}<br/>";
pay_html_station += "付款方式: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{1}<br/>";
pay_html_station += "付款金额: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{2}<br/>";
pay_html_station += "将获得虚拟货币: &nbsp;{3}<br/>";

var pay_end_html = "<span style='font-size:14px;color:#f44;font-weight:bold'>如果您的浏览器没有打开新的窗口,请点击允许新的弹出窗口.</span><br/><br/>请您在新的窗口中完成付款<br/>付款完成请不要关闭或刷新页面,等待支付结果的返回<br/>付款后请根据您的情况点击下面按钮";

var para = {
            scriptPath: "/api/payment/",
            gamepay: "游戏充值",
            stationpay: "账户充值",
            title: "请再次确认您的充值信息：",
            noBtn: "返回修改",
            okBtn: "确认充值",
            etitle: "错误提示",
            err1: "充值账户不能为空",
            err2: "充值账号不一致",
            err3: "充值账户不存在",
            err4: "请选择游戏",
            err5: "请选择服务器",
            err6: "请选择充值金额",
            err7: "充值金额错误，请选择金额",
            err8: "请选择付款银行",
            err9: "参数检查",
            err10:"请先选择充值方式",
            msg1: "选择服务器",
            msg2:"请选择服务器",
            msg3: "验证参数中请稍后...",
            msg4:"充值遇到问题",
            msg5:"充值成功",
            pay_end_url:"/user/order.html",
            msg6:"用户充值"
        };
var pay_module =
{
    PayTo: "game",
    PayAwy: "",
    PayMoney: 1,
    GetMoney: 0,
    PayUser: "",
    GameId: -1,
    GameName: "",
    ServerId: -1,
    ServerName: "",
    BankCode: "",
    PayTypeName: "",
    PayCard: "",
    PayPassword: ""
}


/// <summary>
/// 点击一个游戏选项[第三步]
/// </summary>
function onselectgame(self) {
    var gid = $(self).attr("data");
    if (gid != pay_module.GameId) {
        pay_module.GameId = gid;
        $("#pay_choose_game").html($(self).attr("title"));
        $(".pack-guide em").html($(self).attr("title"));
        $("#game-img").attr("src", $(self).find("img").attr("src"));
        pay_module.GameName = $(self).attr("title");
        pay_module.ServerId = -1;
        $("#pay_choose_server").html(para.msg1);
        $("#packageText").html(para.msg2);
        pay_module.ServerName = "";
        loadHtml();
    }
    $(".selectBox").hide();
}

/// <summary>
/// 点击一个服务器[第三步]
/// </summary>
function onselectserver(self) {
    var sid = $(self).attr("data");
    if (sid != pay_module.ServerId) {
        pay_module.ServerId = sid;
        $(".selectBox").hide();
        $("#pay_choose_server").html($(self).attr("title"));
        $("#packageText").html($(self).attr("title"));
        pay_module.ServerName = $(self).attr("title");
        loadHtml();
    }
    $(".selectBox").hide();
}

function loadHtml() {
    var parm = {
        payto: pay_module.PayTo,
        PayAwy: pay_module.PayAwy,
        PayMoney: pay_module.PayMoney,
        GetMoney: pay_module.GetMoney,
        PayUser: pay_module.PayUser,
        GameId: pay_module.GameId,
        GameName: pay_module.GameName,
        ServerId: pay_module.ServerId,
        ServerName: pay_module.ServerName
    };
    $.get(para.scriptPath + "payment.ashx", parm, function (data) { });
}
/// <summary>
/// 错误提示框
/// </summary>
function Error(info) {
    art.dialog({
        icon: "error",
        content: info,
        title: para.etitle,
        cancel: true,
        cancelVal: "确 定"
    });
}
/// <summary>
/// 页面加载完成后执行
/// </summary>
$(document).ready(function () {
    showLogin();
    (function (config) {
        config['lock'] = true;
        config['fixed'] = true;
        config['fixed'] = true;
        config['resize'] = false;
        config['background'] = '#000'; // 背景色
        config['opacity'] = 0.6; // 透明度
        config['okVal'] = 'Ok';
        config['cancelVal'] = 'Cancel';
    })(art.dialog.defaults);




    /// <summary>
    /// 选择充值方式[第一步]
    /// </summary>
    $("#pay_setup_1 li").click(function () {
        if (showLogin()) { return; }

        $("#pay_setup_1 li").removeClass("current");
        $(this).addClass("current");

        var type = $(this).find("a").attr("data");
        pay_module.PayAwy = type;
        loadHtml();
    })


    /// <summary>
    /// 兑换平台币 充值方式[第二步]
    /// </summary>
    $("#pay_to_station").click(function () {
        if (showLogin()) { return; }
        pay_module.PayTo = "station";
        $("#siderbar").hide();
        $("#paytarget-game").hide();

        $("#siderbar2").show();
        loadHtml();
    });

    /// <summary>
    /// 游戏币 充值方式[第二步]
    /// </summary>
    $("#pay_to_game").click(function () {
        if (showLogin()) { return; }
        $("#siderbar").show()
        $("#paytarget-game").show()
        pay_module.PayTo = "game";
        $("#siderbar2").hide();
        loadHtml();
    });

    /// <summary>
    /// 点击选择游戏[第三步]
    /// </summary>
    $("#pay_choose_game").click(function () {
        if (showLogin()) { return; }
        $(".selectBox").hide();
        $.ajax({
            url: para.scriptPath + "loadgame.ashx?wasda=" + Math.random(),
            success: function (d) {
                $("#load_game_catch").html(d);
                $(".g_s_close").click(function () { $(".selectBox").hide(); })
            }
        });
    });

    /// <summary>
    /// 点击选择服务器[第三步]
    /// </summary>
    $("#pay_choose_server").click(function () {
        if (showLogin()) { return; }
        $(".selectBox").hide();
        $.ajax({
            url: para.scriptPath + "loadgame.ashx?gid=" + pay_module.GameId + "&nav=server&wasda=" + Math.random(),
            success: function (d) {
                $("#load_server_catch").html(d);
                $(".g_s_close").click(function () { $(".selectBox").hide(); })
            }
        });
    });
    /// <summary>
    /// 充值金额选择[第四步]
    /// </summary>
    $("#prixCon .sqr-sel").click(function () {
        if (showLogin()) { return; }

        $("#prixCon .sqr-sel").removeClass("cur");
        var _money = $(this).attr("data");
        pay_module.PayMoney = _money;
        $(this).addClass("cur");
        loadHtml();
    })

    function c_Element(n, v) {
        var _input = document.createElement("input");
        _input.setAttribute("name", n);
        _input.setAttribute("value", v);
        _input.setAttribute("type", "hidden");
        return _input;
    }
    $("#onpay").click(function () {
        if (showLogin()) { return; }

        /**  检查页面参数  ****/
        if ($("#pay_type_name").html() == "未知充值方式" || $("#pay_type_name").html() == "请选择充值方式") {
            Error(para.err10)
            return;
        }
        if ($("#acc1").val() == "") {
            Error(para.err1); return;
        }
        if ($("#acc1").val() != $("#acc2").val()) {
            Error(para.err2); return;
        }
        if (pay_module.PayTo == "game") {
            if (pay_module.GameId == -1) {
                Error(para.err4); return;
            }
            if (pay_module.ServerId == -1) {
                Error(para.err5); return;
            }
        }

        if (pay_module.PayMoney < 1) {
            Error(para.err6); return;
        }

        if (isBank == "on") {
            if (bankcode == "") {
                Error(para.err8); return;
            }

        }
        /**  检查页面参数  **/
        pay_module.PayCard = $("#pay_card_no").val();
        pay_module.PayPassword = $("#pay_card_pw").val();

        pay_module.BankCode = bankcode;
        pay_module.GetMoney = $("#pay_money_count").html();
        pay_module.PayUser = $("#acc1").val();
        var pay_html = "";
        if (pay_module.PayTo == "game") {
            pay_html = pay_html_game.replace("{0}", pay_module.GameName)
                .replace("{1}", pay_module.ServerName)
                .replace("{2}", pay_module.PayUser)
                .replace("{3}", pay_module.PayTypeName)
                .replace("{4}", pay_module.PayMoney)
                .replace("{5}", pay_module.GetMoney + $("#pay_money_name").html())
        } else {
            pay_html = pay_html_station.replace("{0}", pay_module.PayUser)
                .replace("{1}", pay_module.PayTypeName)
                .replace("{2}", pay_module.PayMoney)
                .replace("{3}", pay_module.GetMoney + $("#pay_money_name").html())
        }
        art.dialog({
            id: "{D8B33FA6-85B2-4729-9364-709AD58B04A8}",
            title: para.title,
            icon: "question",
            cancelVal: para.noBtn,
            okVal: para.okBtn,
            width: "300px",
            height: "200px",
            margin: "0px",
            padding: "0px",
            cancel: true,
            ok: function () {
                art.dialog({ id: "load_load_load", content: para.msg3, title: para.err9 });
                $.get(para.scriptPath + "checkparams.ashx", pay_module, function (jon) {
                    var list = art.dialog.list;
                    for (var i in list) { list[i].close(); };
                    if (jon == "200") {
                        try { $("#post_form_pay").remove(); } catch (x) { }
                        var post_form = document.createElement("form");
                        post_form.setAttribute("id", "post_form_pay");
                        //post_form.setAttribute("target","_blank");/** 弹出窗口提交 **/
                        post_form.setAttribute("action", para.scriptPath + "moneypay.ashx");
                        post_form.setAttribute("method", "post");
                        post_form.appendChild(c_Element("BankCode", pay_module.BankCode));
                        post_form.appendChild(c_Element("GameId", pay_module.GameId));
                        post_form.appendChild(c_Element("GameName", pay_module.GameName));
                        post_form.appendChild(c_Element("GetMoney", pay_module.GetMoney));
                        post_form.appendChild(c_Element("PayAwy", pay_module.PayAwy));
                        post_form.appendChild(c_Element("PayCard", pay_module.PayCard));
                        post_form.appendChild(c_Element("PayMoney", pay_module.PayMoney));
                        post_form.appendChild(c_Element("PayPassword", pay_module.PayPassword));
                        post_form.appendChild(c_Element("PayTo", pay_module.PayTo));
                        post_form.appendChild(c_Element("PayTypeName", pay_module.PayTypeName));
                        post_form.appendChild(c_Element("PayUser", pay_module.PayUser));
                        post_form.appendChild(c_Element("ServerId", pay_module.ServerId));
                        post_form.appendChild(c_Element("ServerName", pay_module.ServerName));

                        /**信用卡支付 参数**/
                        post_form.appendChild(c_Element("p1", $("#xyk_p1").attr("value")));
                        post_form.appendChild(c_Element("p2", $("#xyk_p2").attr("value")));
                        post_form.appendChild(c_Element("p3", $("#xyk_p3").attr("value")));
                        post_form.appendChild(c_Element("p4", $("#xyk_p4").attr("value")));
                        post_form.appendChild(c_Element("p5", $("#xyk_p5").attr("value")));
                        post_form.appendChild(c_Element("p6", $("#xyk_p6").attr("value")));
                        post_form.appendChild(c_Element("p7", $("#xyk_p7").attr("value")));
                        post_form.appendChild(c_Element("p8", $("#xyk_p8").attr("value")));
                        post_form.appendChild(c_Element("p9", $("#xyk_p9").attr("value")));
                        post_form.appendChild(c_Element("p10", $("#xyk_p10").attr("value")));
                        post_form.appendChild(c_Element("p11", $("#xyk_p11").attr("value")));
                        /**信用卡支付 参数**/
                        /***************/
                        post_form.appendChild(c_Element("sp_money", $("#sp_money").attr("value")));
                        post_form.appendChild(c_Element("sp_card", $("#sp_card").attr("value")));
                        post_form.appendChild(c_Element("sp_password", $("#sp_password").attr("value")));

                        /****************/
                        document.body.appendChild(post_form); 
                        $("#post_form_pay").submit();
                        /*
                        art.dialog({ content: pay_end_html,
                            cancelVal: para.msg4,
                            okVal: para.msg5,
                            title:para.msg6,
                            cancel: function(){ window.location.href=para.pay_end_url },
                            ok: function(){ window.location.href="/play/"+pay_module.ServerId +".html" },
                        });*/

                    } else {
                        art.dialog({ content: jon, icon: "warning", title: para.err9, cancel: true, cancelVal: para.noBtn })
                    }

                })
            },
            content: pay_html
        });

    })
});

$(".title_close").click(function () { $(".crvbg").hide(); $("#login").slideUp(120) });
function showLogin() {
    return false;
    if (mastLogin == "on") {
        if (need_login) {
            $(".crvbg").height($(window.document.body).height() + 100).show()
            $("#login").css("left", $(window).width() / 2 - $(this).width() / 2 + 500).slideDown(160)
            return true;
        }
    }
    return false;
}
$("#user_login_sysn").click(function () {

    $.post(para.scriptPath + "../webaction.ashx", { posttype: "user_login", username: $("#user_name").val(), password: $("#user_pwd").val() }, function (data) {
        if (data == "200") {
            window.location.href = window.location.href;
        } else {
            alert(data)
        }
    })
});

window.onerror = function (s, k, j) {
    k = k.substring(k.lastIndexOf("/") + 1)
    k = k.substring(0, k.indexOf("?"));
    Error(s + "<br/>" + k + " : " + j);
    return true;
}