﻿function QuickProductGamechanged() 
{   
    try{
    var dic_Game = document.getElementById("Left1_quick_game_select");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    AjaxMethod.GetAmountList(GameID,QuickProductGamechanged_CallBack);
    }
    catch(e)
    {
    }
}
  
function QuickProductGamechanged_CallBack(response)
{
    try{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var dic_Game = document.getElementById("Left1_quick_game_select");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var AmountTable = response.value;
    var dic_Amount = document.getElementById("Left1_quick_amount_select");
    if(GameID != 0)
    {
        if(AmountTable != null && typeof(AmountTable) == "object")
        {
            dic_Amount.disabled = false;
            dic_Amount.length = 0;
            dic_Amount.options.add(new Option("Choisissez Montant",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 QuickProductAmountchanged()
{
    try{
    var dic_Game = document.getElementById("Left1_quick_game_select");
    AjaxMethod.GetServerList(dic_Game.options[dic_Game.selectedIndex].value,QuickProductAmountchanged_CallBack);
    }
    catch(e)
    {
    }
}

function QuickProductAmountchanged_CallBack(response)
{
    try{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var dic_Game = document.getElementById("Left1_quick_game_select");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    var dic_Amount = document.getElementById("Left1_quick_amount_select");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("Left1_input_Amount").value = Amount;
    var ServerTable = response.value;
    var dic_ServerList = document.getElementById("Left1_quick_server_select");
    if (GameID > 0 && Amount > 0)
    {
        dic_ServerList.disabled = false;                    
        dic_ServerList.length=0;
        if(ServerTable != null && typeof(ServerTable) == "object")
        {   
            dic_ServerList.options.add(new Option("Choisir 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 QuickProductServerchanged()
{
    try{
    var dic_ServerList = document.getElementById("Left1_quick_server_select");
    var ServerID = dic_ServerList.options[dic_ServerList.selectedIndex].value;
    document.getElementById("Left1_input_ServerID").value = ServerID;
    var dic_Amount = document.getElementById("Left1_quick_amount_select");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var currencyName = document.getElementById("Left1_input_CurrencyName").value;
    var Currency = currencyFun(currencyName);    
//    var Currency = "£";
    AjaxMethod.GetPrice(ServerID,Amount,Currency,QuickProductServerchanged_CallBack);
    }
    catch(e)
    {
    
    }
}

function QuickProductServerchanged_CallBack(response)
{
    try{
     var price = response.value;
     if(price!=null && price != '' && price != '0')
     {
         document.getElementById("Left1_btn_quickbuy").disabled = false;
         document.getElementById("Left1_input_Price").value = price;
//         document.getElementById("Left1_lab_PriceShow").innerHTML = "GBP " + price;
         document.getElementById("Left1_lab_PriceShow").innerHTML = document.getElementById("Left1_input_CurrencyName").value + " " + price;
         
        var dic_Game = document.getElementById("Left1_quick_game_select");
        var dic_ServerList = document.getElementById("Left1_quick_server_select");
        document.getElementById("Left1_input_Product").value =dic_Game.options[dic_Game.selectedIndex].innerHTML+"-"+ dic_ServerList.options[dic_ServerList.selectedIndex].innerHTML;
     }
     else
     {
        document.getElementById("Left1_btn_quickbuy").disabled = true;
        document.getElementById("Left1_input_Price").value = "";
        document.getElementById("Left1_lab_PriceShow").innerHTML = "";
     }
     return;
     }
     catch(e)
     {
     }
}

function currencyFun(currencyName)
{
    var currency = "";
    if(currencyName.toUpperCase() == "EUR")
    {
        currency = "€";
    }
    if(currencyName.toUpperCase() == "GBP")
    {
        currency = "£";
    }
    if(currencyName.toUpperCase() == "USD")
    {
        currency = "$";
    }
    return currency;
}


