﻿function gameChange() 
{     
    var dic_Game = document.getElementById("right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    if(GameID > 0)
    {
        AjaxMethod.GetAmountList(GameID,gameChange_CallBack);
    }
    else
    {
        document.getElementById("right1_dic_Amount").disabled = true;
        document.getElementById("right1_dic_ServerList").disabled = true;
        document.getElementById("right1_dic_Currency").disabled = true;
        document.getElementById("txt_Price").value = "";
        document.getElementById("right1_Imagebutton2").disabled = true
    }
}

function gameChange_CallBack(response)
{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var AmountTable = response.value;
    var dic_Amount = document.getElementById("right1_dic_Amount");
    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));
        }
    }
    LoadServerList();
}

function LoadServerList()
{
    var dic_Game = document.getElementById("right1_dic_GameList");
    AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value,LoadServerList_CallBack);
}

function LoadServerList_CallBack(response)
{
    var dic_Game = document.getElementById("right1_dic_GameList");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("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;
        document.getElementById("right1_Imagebutton2").disabled = true;
    }
    return
}


function amountChange() 
{ 
    var dic_Amount = document.getElementById("right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("right1_Amount").value = dic_Amount.options[dic_Amount.selectedIndex].value;//给文本框Amount赋值
    currencyChange();
}

function serverChange() 
{ 
    var dic_Currency = document.getElementById("right1_dic_Currency");
    var dic_ServerList = document.getElementById("right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("right1_ServerID").value = dic_ServerList.options[dic_ServerList.selectedIndex].value;//给文本框ServerID赋值
    if(ServerID == 0)
    {
        dic_Currency.disabled = true;
        document.getElementById("right1_Imagebutton2").disabled = true;
    }
    else
    {
        dic_Currency.disabled = false;
    }
    currencyChange();
}
//换算价格
function currencyChange()
{
    var dic_ServerList = document.getElementById("right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("right1_dic_Currency");
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    document.getElementById("right1_CurrencySign").value = Currency;
    dic_Currency.disabled = false;
    AjaxMethod.GetPrice(ServerID,Amount,Currency,currencyChange_CallBack);
}
             
function currencyChange_CallBack(response)
{
     var btn_buy=document.getElementById("right1_Imagebutton2");
     var price = response.value;
     var lbb=document.getElementById("txt_Price");
     var dic_Currency = document.getElementById("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("right1_Price").value = price;
         var game = document.getElementById("right1_dic_GameList");
         var servername = document.getElementById("right1_dic_ServerList");
         document.getElementById("right1_ProductName").value =game.options[game.selectedIndex].innerHTML+"-"+ servername.options[servername.selectedIndex].innerHTML;   //ProductName
     }
     else
     {
        btn_buy.disabled = true;
        lbb.value = '';
     }
     return;
}

function CheckPostData()
{
    var dic_ServerList = document.getElementById("right1_dic_ServerList");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    var dic_Amount = document.getElementById("right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var dic_Currency = document.getElementById("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;
    }
}