﻿var fee = 0.06;

var selectFace = function() {
    $('.dv_auction').hide();
    $('#dv_face2face').show();
    $("#span_buy_quantity").html(g_obj.quantity);
    g_obj.paymethod = "ftf";
};

var selectAuction = function() {
    $('.dv_auction').hide();
    $('#dv_auction').show()
    g_obj.paymethod = "ah";
    var totalfee = Number(g_obj.quantity * fee) > Math.floor(g_obj.quantity * fee) ? Math.floor(g_obj.quantity * fee) + 1 : Math.floor(g_obj.quantity * fee);
    $('#span_buy_quantity').html(g_obj.quantity + "<span class='sp_fee'> +  " + totalfee + "</span> (" + fee * 100 + "% handling charge for auction)");
    var totalvol = Number(g_obj.quantity) + totalfee;
    $("#sp_count").html(totalvol);
    var str = "";
    var multiple = Math.floor(totalvol / 10000) + 1;
    var unit = multiple * 1000;
    var remain = Math.floor(totalvol % unit) < totalvol % unit ? Math.floor(totalvol % unit) + 1 : Math.floor(totalvol % unit);
    var tmpStr = unit + "*" + Math.floor(totalvol / unit);
    str = unit + " * " + Math.floor(totalvol / unit) + "(Light Shot) = " + unit * Math.floor(totalvol / unit) + "g  <br />";
    if (remain > 0) {
        str += remain + " * 1(Light Shot) = " + remain + "g <br />";
        tmpStr += "+" + remain + "*1";
    }
    $('#lbl_method').html(str);
    $('#lbl_method').attr("title", tmpStr);
};

var collect_usr_info = function () {

    if ($("#sel_server").attr("value") == "" || $("#sel_quantity").attr("value") == "") {

        scroll(0, 0);
    }

    if (validate("dv_usr_info")) {
        var config = new Object();
        config["product"] = $("#gold_unitname").val();
        config["game"] = $("#sel_game>option:selected").val();  //选择的游戏
        config["server"] = $("#sel_server>option:selected").text();  //选择的服务器
        config["currency"] = $("#hdn_currency").val();  //货币类型
        config["price"] = $("#lbl_total").text();  //价格
        config["quantity"] = $("#sel_quantity>option:selected").val();  //选择的游戏币
        config["code"] = $("#discountcode").val();  //用户输入的code
        config["character"] = $("#usr_char").val();  //用户名称
        config["mail"] = $("#contact_method>option:selected").text() + ":" + $("#usr_msn").val();  //用户邮箱
        config["telphone"] = $("#usr_phone").val();  //用户电话
        config["payment"] = $("input:checked[name=pm]").val();  //支付方式
        config["obj"] = json2str(config);
        createForm(config, "GoldConfirm.aspx");
    }
};

$().ready(function() {
    if ($("#contact_method").length) {
        $("#contact_method>option:eq(0)").attr("selected", "true");
    }
});