﻿// JScript 文件
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("dic_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));
            }
        }
    }
    gameChange();
    LoadServerList();
    return;
}

function gameChange() {
    var dic_Game = document.getElementById("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("dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var AmountTable = response.value;
    var dic_Amount = document.getElementById("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("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 (Marketing(GameID, Num) != "") {
//                        NumText = Num + "+" + Marketing(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("dic_GameList");
    AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value, LoadServerList_CallBack);
}

function LoadServerList_CallBack(response) {
    var dic_Game = document.getElementById("dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("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("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 amountChange() {
    var dic_Amount = document.getElementById("dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("Amount").value = dic_Amount.options[dic_Amount.selectedIndex].value; //给文本框Amount赋值
    currencyChange();
}

function serverChange() {
    var dic_Currency = document.getElementById("dic_Currency");
    var dic_ServerList = document.getElementById("dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("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("dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("dic_Currency");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    document.getElementById("CurrencySign").value = Currency;
    dic_Currency.disabled = false;
    AjaxMethod.GetPrice(ServerID, Amount, Currency, currencyChange_CallBack);
}

function currencyChange_CallBack(response) {
    var btn_buy = document.getElementById("ImageButton2");
    var price = response.value;
    var lbb = document.getElementById("txt_Price");
    var dic_Currency = document.getElementById("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("Price").value = price;
        var game = document.getElementById("dic_GameList");
        var servername = document.getElementById("dic_ServerList");
        document.getElementById("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("dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("dic_Currency");
    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 Marketing(gameID, amount) {
    /// <summary>
    /// 数量赠送金币百分比活动20100623
    /// </summary>
    var marketDiscount = 0;
    if (10000 <= amount && amount <= 25000) {
        marketDiscount = 0.1;
        return (marketDiscount * 100) + "%";
    }
    else if (30000 <= amount && amount <= 100000) {
        marketDiscount = 0.15;
        return (marketDiscount * 100) + "%";
    }
    else {
        marketDiscount = 0;
        return "";
    }

}

