﻿// 快捷购买
function LoadGame() {
    AjaxMethod.GetGamelist(LoadGame_CallBack);
}
function LoadGame_CallBack(response) {
    if (response.error != null) {
        //alert(response.error);
        return;
    }
    var GameTable = response.value;
    var dic_Game = document.getElementById("Main1_GameList");
    if (GameTable != null) {
        dic_Game.length = 0;
        if (GameTable != null && typeof (GameTable) == "object") {
            dic_Game.options.add(new Option("Spiel wählen", 0));
            for (var i = 0; i < parseInt(GameTable.Rows.length); i++) {
                var GameName = GameTable.Rows[i].GameName_en;
                var GameID = GameTable.Rows[i].GameId;
                dic_Game.options.add(new Option(GameName, GameID));
            }
        }
        for (var i = 0; i < dic_Game.length; i++) {
            if (dic_Game.options[i].value == "1") {
                dic_Game.selectedIndex = i;
            }
        }
    }
    gameSelect();
    getServerList();
}
function gameSelect() {
    var dic_Game = document.getElementById("Main1_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    AjaxMethod.GetAmountList(GameID, gameSelect_CallBack);
}
function gameSelect_CallBack(response) {
    if (response.error != null) {
        //alert(response.error);
        return;
    }
    var dic_Game = document.getElementById("Main1_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var AmountTable = response.value;
    var dic_Amount = document.getElementById("Main1_AmountList");
    if (GameID != 0) {
        if (AmountTable != null && typeof (AmountTable) == "object") {
            dic_Amount.disabled = false;
            dic_Amount.length = 0;
            dic_Amount.options.add(new Option("Menge wählen", 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));
                }
            }
            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));
                }
            }
            //数量赠送金币百分比活动20100623---END----------------
        }
        for (var i = 0; i < dic_Amount.length; i++) {
            if (GameID == 1 && dic_Amount.options[i].value == "20000") {
                dic_Amount.selectedIndex = i;
                document.getElementById("Main1_Amount").value = "20000"; //给文本框Amount赋值
            }
        }
    }
    else {
        dic_Amount.disabled = true;
    }
    getServerList();
}
function amountSelect() {
    var dic_Amount = document.getElementById("Main1_AmountList");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("Main1_Amount").value = dic_Amount.options[dic_Amount.selectedIndex].value; //给文本框Amount赋值
    currencySelect();
}

function getServerList() {
    var dic_Game = document.getElementById("Main1_GameList");
    AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value, getServerList_CallBack);
}
function getServerList_CallBack(response) {
    var dic_Game = document.getElementById("Main1_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("Main1_ServerList");
    if (GameID != 0) {
        dic_ServerList.disabled = false;
        dic_ServerList.length = 0;
        if (ServerTable != null && typeof (ServerTable) == "object") {
            dic_ServerList.options.add(new Option("Server wählen", 0));
            for (var i = 0; i < parseInt(ServerTable.Rows.length); i++) {
                var name = ServerTable.Rows[i].fullservername;
                var id = ServerTable.Rows[i].ServerID;
                dic_ServerList.options.add(new Option(name, id));
            }
        }
    }
    else {
        dic_ServerList.disabled = true;
    }
    return
}

function serverSelect() {
    var dic_Currency = document.getElementById("Main1_CurrencyList");
    var dic_ServerList = document.getElementById("Main1_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("Main1_ServerID").value = dic_ServerList.options[dic_ServerList.selectedIndex].value; //给文本框ServerID赋值
    if (ServerID == 0) {
        dic_Currency.disabled = true;
    }
    else {
        dic_Currency.disabled = false;
    }
    currencySelect();
}
//换算价格
function currencySelect() {
    var dic_ServerList = document.getElementById("Main1_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("Main1_AmountList");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("Main1_CurrencyList");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    document.getElementById("Main1_CurrencySign").value = Currency;
    dic_Currency.disabled = false;
    AjaxMethod.GetPrice(ServerID, Amount, Currency, currencySelect_CallBack);
}

function currencySelect_CallBack(response) {
    var btn_buy = document.getElementById("Main1_btn_Buy");
    var price = response.value;
    var lbb = document.getElementById("Main1_txt_Price");
    var dic_Currency = document.getElementById("Main1_CurrencyList");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if (price != null && Currency != '0') {
        btn_buy.disabled = false;
        lbb.innerHTML = price;
        document.getElementById("Main1_Price").value = price;
        var game = document.getElementById("Main1_GameList");
        var servername = document.getElementById("Main1_ServerList");
        document.getElementById("Main1_ProductName").value = game.options[game.selectedIndex].innerHTML + "-" + servername.options[servername.selectedIndex].innerHTML;   //ProductName
    
    }
    else {
        btn_buy.disabled = true;
        lbb.innerHTML = '';
    }
    return;
}

function CheckPostData() {
    var dic_ServerList = document.getElementById("Main1_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("Main1_AmountList");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("Main1_CurrencyList");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if (ServerID == 0) {
        alert("Server wählen");
        return false;
    }
    if (Amount == 0) {
        alert("wählen Sie bitte die Menge aus");
        return false;
    }
    if (Currency == 0) {
        alert("wählen Sie bitte die Währung aus");
        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 "";
    }
}
