﻿function gameChange() 
{   
    try{
    var dic_Game = document.getElementById("Right1_dic_GameList");
    var gameId = dic_Game.options[dic_Game.selectedIndex].value;
    document.getElementById("Right1_txt_GameId").value = gameId;
    if(parseInt(gameId) > 0)
    {
        AjaxMethod.GetServerList(gameId,GetServerList_CallBack);
    }
    else
    {
        document.getElementById("Right1_dic_ServerList").selectedIndex = 0;
        document.getElementById("Right1_dic_ServerList").disabled = true;
        document.getElementById("Right1_dic_Amount").selectedIndex = 0;
        document.getElementById("Right1_dic_Amount").disabled = true;        
        document.getElementById("Right1_dic_Currency").selectedIndex = 0;
        document.getElementById("Right1_dic_Currency").disabled = true;
        document.getElementById("Right1_txt_ShowPrice").value = "";
        document.getElementById("Right1_txt_BuyPrice").value = "";
        document.getElementById("Right1_QuickBuy").disabled = true;
    }
    }
    catch(e)
    {
    }
}

function GetServerList_CallBack(response)
{
    try{
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("Right1_dic_ServerList");
    if(ServerTable != null && typeof(ServerTable) == "object")
    {
        dic_ServerList.disabled = false;
        dic_ServerList.length=0;            
        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].servername;
            var id = ServerTable.Rows[i].ServerID;
            dic_ServerList.options.add(new Option(name,id));
        }
    }
    else
    {
        dic_ServerList.disabled = true;
    }
    return
    }
    catch(e)
    {
    }
}

function serverChange() 
{ 
    try{
    var dic_Game = document.getElementById("Right1_dic_GameList");
    var gameId = dic_Game.options[dic_Game.selectedIndex].value;
    var dic_ServerList = document.getElementById("Right1_dic_ServerList");
    var serverId = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("Right1_txt_ServerID").value = dic_ServerList.options[dic_ServerList.selectedIndex].value;//给文本框ServerID赋值
    if(parseInt(gameId) > 0 && parseInt(serverId) > 0)
    {
        AjaxMethod.GetAmountList(gameId,GetAmountList_CallBack);
    }
    else
    {
        document.getElementById("Right1_dic_Amount").selectedIndex = 0;
        document.getElementById("Right1_dic_Amount").disabled = true;        
        document.getElementById("Right1_dic_Currency").selectedIndex = 0;
        document.getElementById("Right1_dic_Currency").disabled = true;
        document.getElementById("Right1_txt_ShowPrice").value = "";
        document.getElementById("Right1_txt_BuyPrice").value = "";
        document.getElementById("Right1_QuickBuy").disabled = true;
    }
    }
    catch(e)
    {
    
    }
}

function GetAmountList_CallBack(response)
{
    try{
    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("Produkt wählen",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));
        }
    }
    else
    {
        dic_Amount.disabled = true;
    }
    }
    catch(e)
    {
    }
}


function amountChange() 
{ 
    try{
    var dic_Amount = document.getElementById("Right1_dic_Amount");
    var amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("Right1_txt_Amount").value = amount;//给文本框Amount赋值
    if(parseInt(amount) > 0)
    {
        currencyChange();
    }
    else
    {
        document.getElementById("Right1_dic_Currency").selectedIndex = 0;
        document.getElementById("Right1_dic_Currency").disabled = true;
        document.getElementById("Right1_txt_ShowPrice").value = "";
        document.getElementById("Right1_txt_BuyPrice").value = "";
        document.getElementById("Right1_QuickBuy").disabled = true;
    }
    }
    catch(e)
    {
    }
}

//换算价格
function currencyChange()
{
    try{
    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_txt_CurrencySign").value = currency;
    dic_Currency.disabled = false;
    AjaxMethod.GetPrice(serverId,amount,currency,GetPrice_CallBack);
    }
    catch(e)
    {
    
    }
}
             
function GetPrice_CallBack(response)
{
    try{
    var price = response.value;
    var dic_Currency = document.getElementById("Right1_dic_Currency");
    var currency = dic_Currency.options[dic_Currency.selectedIndex].value;
     if(price!=null && parseFloat(price) > 0)
     {
         document.getElementById("Right1_QuickBuy").disabled = false;
         document.getElementById("Right1_txt_ShowPrice").value = currency + price; //价格显示：币别符号+金额
         document.getElementById("Right1_txt_BuyPrice").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
     {
        document.getElementById("Right1_QuickBuy").disabled = true;
        document.getElementById("Right1_txt_ShowPrice").value = '';
     }
     return;
     }
     catch(e)
     {
     }
}

function Left_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("Server wählen");
        return false;
    }
    if(Amount == 0)
    {
        alert("Produkt wählen");
        return false;
    }
    if(Currency == 0)
    {
        alert("Währung wählen");
        return false;
    }
}
