﻿function Right_PostData() {
    /// <summary>
    /// 验证快捷购买提交
    /// </summary>
    var dic_Game = document.getElementById("ctl00_right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    if (GameID == 0) {
        alert("Please choose game.");
        return false;
    }
    var dic_Amount = document.getElementById("ctl00_right1_dic_Amount");
    var amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    if (amount == 0) {
        alert("Please Choose Amount");
        return false;
    }
    var dic_ServerList = document.getElementById("ctl00_right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    if (ServerID == 0) {
        alert("Please Choose Server");
        return false;
    }
    var dic_Currency = document.getElementById("ctl00_right1_dic_Currency");
    var currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if (currency == 0) {
        alert("Please Choose Currency");
        return false;
    }
    return true;

}
function gameChange() {
    var dic_Game = document.getElementById("ctl00_right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    AjaxMethod.GetAmountList(GameID, gameChange_CallBack);
}
function gameChange_CallBack(response) {
    if (response.error != null) {
        //alert(response.error);
        return;
    }
    var dic_Game = document.getElementById("ctl00_right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var AmountTable = response.value;
    var dic_Amount = document.getElementById("ctl00_right1_dic_Amount");
    if (GameID != 0) {
        if (AmountTable != null && typeof (AmountTable) == "object") {
            dic_Amount.disabled = false;
            dic_Amount.length = 0;
            dic_Amount.options.add(new Option("Choose Amount", 0));
            //数量赠送金币百分比活动20100623--START----------------
            var Num; var NumText; var ID;
//            if (GameID == 1) {
//                for (var i = 0; i < AmountTable.Rows.length; i++) {
//                    Num = AmountTable.Rows[i].NUM;
//                    if (MarketingQuick(GameID, Num) != "") {
//                        NumText = Num + "+" + MarketingQuick(GameID, Num);
//                    } else { NumText = Num; }
//                    ID = AmountTable.Rows[i].NUM;
//                    dic_Amount.options.add(new Option(NumText, ID));
//                }
//            } //数量赠送金币百分比活动20100623---END----------------
//            else {
                for (var i = 0; i < AmountTable.Rows.length; i++) {
                    Num = AmountTable.Rows[i].NUM;
                    ID = AmountTable.Rows[i].NUM;
                    dic_Amount.options.add(new Option(Num, ID));
                }
//            }           
        }
    }
    else {
        dic_Amount.disabled = true;
    }
    LoadServerList();
}

function LoadServerList() {
    var dic_Game = document.getElementById("ctl00_right1_dic_GameList");
    AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value, LoadServerList_CallBack);
}

function LoadServerList_CallBack(response) {
    var dic_Game = document.getElementById("ctl00_right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("ctl00_right1_dic_ServerList");
    if (GameID != 0) {
        dic_ServerList.disabled = false;
        dic_ServerList.length = 0;
        if (ServerTable != null && typeof (ServerTable) == "object") {
            dic_ServerList.options.add(new Option("Choose Server", 0));
            for (var i = 0; i < parseInt(ServerTable.Rows.length); i++) {
                var name = ServerTable.Rows[i].servername;
                var id = ServerTable.Rows[i].serverid;
                dic_ServerList.options.add(new Option(name, id));
            }
        }
    }
    else {
        dic_ServerList.disabled = true;
    }
    return
}


function amountChange() {
    var dic_Amount = document.getElementById("ctl00_right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("ctl00_right1_Amount").value = dic_Amount.options[dic_Amount.selectedIndex].value; //给文本框Amount赋值
    currencyChange();
}

function serverChange() {
    var dic_Currency = document.getElementById("ctl00_right1_dic_Currency");
    var dic_ServerList = document.getElementById("ctl00_right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("ctl00_right1_ServerID").value = dic_ServerList.options[dic_ServerList.selectedIndex].value; //给文本框ServerID赋值
    if (ServerID == 0) {
        dic_Currency.disabled = true;
    }
    else {
        dic_Currency.disabled = false;
    }
    currencyChange();
}
//换算价格
function currencyChange() {
    var dic_ServerList = document.getElementById("ctl00_right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("ctl00_right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("ctl00_right1_dic_Currency");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    document.getElementById("ctl00_right1_CurrencySign").value = Currency;
    dic_Currency.disabled = false;
    AjaxMethod.GetPrice(ServerID, Amount, Currency, currencyChange_CallBack);
}

function currencyChange_CallBack(response) {
    var btn_buy = document.getElementById("ctl00_right1_ImgBtn");
    var price = response.value;
    var lbb = document.getElementById("txt_Price");
    var dic_Currency = document.getElementById("ctl00_right1_dic_Currency");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if (price != null && Currency != '0') {
        btn_buy.disabled = false;
        lbb.value = price;
        document.getElementById("ctl00_right1_Price").value = price;
        var game = document.getElementById("ctl00_right1_dic_GameList");
        var servername = document.getElementById("ctl00_right1_dic_ServerList");
        document.getElementById("ctl00_right1_ProductName").value = game.options[game.selectedIndex].innerHTML + "-" + servername.options[servername.selectedIndex].innerHTML;   //ProductName
    }
    else {
        btn_buy.disabled = true;
        lbb.value = '';
    }
    return;
}

function Left_CheckPostData() {
    var dic_ServerList = document.getElementById("ctl00_right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("ctl00_right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("ctl00_right1_dic_Currency");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if (ServerID == 0) {
        alert("Choose Server");
        return false;
    }
    if (Amount == 0) {
        alert("Please Choose Amount");
        return false;
    }
    if (Currency == 0) {
        alert("Please Choose Currency");
        return false;
    }
}
function MarketingQuick(gameID, amount) {
    /// <summary>
    /// 数量赠送金币百分比活动20100623
    /// </summary>
    var marketDiscount = 0;
    if (10000 <= amount && amount <= 25000) {
        marketDiscount = 0.1;
        return (marketDiscount * 100) + "% free";
    }
    else if (30000 <= amount && amount <= 100000) {
        marketDiscount = 0.15;
        return (marketDiscount * 100) + "% free";
    }
    else {
        marketDiscount = 0;
        return "";
    }
}

