﻿
// JScript 文件
function LoadGame() {
    try {
        AjaxMethod.GetGamelist(LoadGame_CallBack);
    }
    catch (e) {

    }
}
function LoadGame_CallBack(response) {
    try {
        if (response.error != null) {
            //alert(response.error);
            return;
        }
        var GameTable = response.value;
        var dic_Game = document.getElementById("GameList");
        if (GameTable != null) {
            dic_Game.length = 0;
            if (GameTable != null && typeof (GameTable) == "object") {
                dic_Game.options.add(new Option("Choose Game", 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();
    }
    catch (e) {

    }
}

function gameSelect() {
    try {
        var dic_Game = document.getElementById("GameList");

        var GameID = dic_Game.options[dic_Game.selectedIndex].value;
        AjaxMethod.GetAmountList(GameID, gameSelect_CallBack);
    }
    catch (e) {
    }
}

function gameSelect_CallBack(response) {
    try {
        if (response.error != null) {
            //alert(response.error);
            return;
        }
        var dic_Game = document.getElementById("GameList");
        var GameID = dic_Game.options[dic_Game.selectedIndex].value;
        var AmountTable = response.value;
        var dic_Amount = document.getElementById("AmountList");
        if (GameID != 0) {

            if (GameID == 54) {
                if (AmountTable != null && typeof (AmountTable) == "object") {
                    dic_Amount.disabled = false;
                    dic_Amount.length = 0;
                    dic_Amount.options.add(new Option("Choose Amount", 0));
                    for (var i = 0; i < AmountTable.Rows.length; i++) {
                        var Num = 0;
                        if (AmountTable.Rows[i].SpecialNum != "0") {
                            Num = AmountTable.Rows[i].NUM + " + " + AmountTable.Rows[i].SpecialNum + " M Free Gold";
                        }
                        else {
                            Num = AmountTable.Rows[i].NUM;
                        }
                            var ID = AmountTable.Rows[i].NUM;
                        dic_Amount.options.add(new Option(Num, ID));
                    }
                }

            }
            else {
                if (AmountTable != null && typeof (AmountTable) == "object") {
                    dic_Amount.disabled = false;
                    dic_Amount.length = 0;
                    dic_Amount.options.add(new Option("Choose Amount", 0));
                    for (var i = 0; i < AmountTable.Rows.length; i++) {
                        var Num = AmountTable.Rows[i].NUM;
                        var ID = AmountTable.Rows[i].NUM;
                        dic_Amount.options.add(new Option(Num, ID));
                    }
                }
                for (var i = 0; i < dic_Amount.length; i++) {
                    if (GameID == 1 && dic_Amount.options[i].value == "20000") {
                        dic_Amount.selectedIndex = i;
                        document.getElementById("Amount").value = "20000"; //给文本框Amount赋值
                    }
                }
            }
        }
        else {
            dic_Amount.disabled = true;
        }
        getServerList();
    }
    catch (e) {

    }
}

function amountSelect() {
    try {
        var dic_Amount = document.getElementById("AmountList");
        var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
        document.getElementById("Amount").value = dic_Amount.options[dic_Amount.selectedIndex].value; //给文本框Amount赋值
        currencySelect();
    }
    catch (e) {
    }
}

function getServerList() {
    try {
        var dic_Game = document.getElementById("GameList");
        AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value, getServerList_CallBack);
    }
    catch (e) {
    }
}

function getServerList_CallBack(response) {
    try {
        var dic_Game = document.getElementById("GameList");
        var GameID = dic_Game.options[dic_Game.selectedIndex].value;
        var ServerTable = response.value;
        var dic_ServerList = document.getElementById("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].fullservername;
                    var id = ServerTable.Rows[i].ServerID;
                    dic_ServerList.options.add(new Option(name, id));
                }
            }
        }
        else {
            dic_ServerList.disabled = true;
        }
        return
    }
    catch (e) {

    }
}

function serverSelect() {
    try {
        var dic_Currency = document.getElementById("CurrencyList");
        var dic_ServerList = document.getElementById("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;
        }
        currencySelect();
    }
    catch (e) {
    }
}
//换算价格
function currencySelect() {
    try {
        var dic_ServerList = document.getElementById("ServerList");
        var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
        var dic_Amount = document.getElementById("AmountList");
        var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
        var dic_Currency = document.getElementById("CurrencyList");
        var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
        document.getElementById("CurrencySign").value = Currency;
        dic_Currency.disabled = false;
        AjaxMethod.GetPrice(ServerID, Amount, Currency, currencySelect_CallBack);
    }
    catch (e) {
    }
}

function currencySelect_CallBack(response) {
    try {
        var btn_buy = document.getElementById("btn_buysoon");
        var price = response.value;
        var lbb = document.getElementById("txt_Price");
        var dic_Currency = document.getElementById("CurrencyList");
        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("GameList");
            var servername = document.getElementById("ServerList");
            document.getElementById("ProductName").value = game.options[game.selectedIndex].innerHTML + "-" + servername.options[servername.selectedIndex].innerHTML;   //ProductName
            //---begin 生成vip 价格--------- 
            var UserId = document.getElementById("txt_UserId").value;
            var noCurrencyPrice = price.replace(Currency, "");
            if (parseInt(UserId) > 0 && parseFloat(noCurrencyPrice) > 0) {
                AjaxMethod.VipPrice(UserId, noCurrencyPrice, Currency, VipPrice_CallBack);
            }
            else {
                return;
            }
            //--end生成vip价格------------         
        }
        else {
            btn_buy.disabled = true;
            lbb.value = '';
        }
        return;
    }
    catch (e) {

    }
}

//begin vip价格
function VipPrice_CallBack(response) {
    if (response.error != null) {
        return;
    }
    document.getElementById("txt_VipPrice").value = response.value;
}
//end vip 价格

function CheckPostData() {
    var dic_ServerList = document.getElementById("ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("AmountList");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("CurrencyList");
    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 loadSelect() {

    var dic_Game = document.getElementById("GameList");

    if (parent.location.href.toLowerCase().indexOf("mage") > 0) {
        var i;
        for (i = 0; i < dic_Game.options.length; i++) {
            if (dic_Game.options[i].value == "28") {
                dic_Game.options[i].selected = true;
            }
        }
    }
    if (parent.location.href.toLowerCase().indexOf("mage_eu") > 0) {
        var i;
        for (i = 0; i < dic_Game.options.length; i++) {
            if (dic_Game.options[i].value == "29") {
                dic_Game.options[i].selected = true;
            }
        }
    }
    //gameSelect();
    //begin vip 价格用,用户登陆的情况下显示vip price文本框
    var UserId = document.getElementById("txt_UserId").value;
    if (parseInt(UserId) > 0) {
        document.getElementById("tr_vipprice").style.display = "inline";
    }
    //end vip 价格用,用户登陆的情况下显示vip price文本框    
}
