﻿// JScript 文件
function LoadServer()
{
    document.getElementById("Right1_txt_ServerID").value = 0;
    var dic_Amount = document.getElementById("Right1_dic_Amount");
    document.getElementById("Right1_txt_Amount").value = 0;
    var dic_Currency = document.getElementById("Right1_dic_Currency");
    document.getElementById("Right1_txt_CurrencyType").value = "";
    var txt_Price = document.getElementById("Right1_txt_Price");
    dic_Amount.length = 0;
    dic_Amount.options.add(new Option("Choose Amount",0));   
    dic_Currency.disabled = true;
    dic_Currency.selectedIndex = 0;
    txt_Price.value = "";

    var dic_Game = document.getElementById("Right1_dic_Game");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    AjaxMethod.LoadServer(GameID,LoadServer_CallBack);
}
function LoadServer_CallBack(response)
{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var dic_Server = document.getElementById("Right1_dic_Server");
    var ServerTable = response.value;
    if(ServerTable != null && typeof(ServerTable) == "object")
    {
        dic_Server.disabled = false;
        dic_Server.length = 0;
        dic_Server.options.add(new Option("Choose Server",0));
        for(var i = 0;i < ServerTable.Rows.length;i++)
        {
            var ServerName = ServerTable.Rows[i].ServerName;
            var ServerID = ServerTable.Rows[i].ServerID;
            dic_Server.options.add(new Option(ServerName,ServerID));
        }
    }
    return;
}

function LoadAmount()
{
    document.getElementById("Right1_txt_Amount").value = 0;
    var dic_Currency = document.getElementById("Right1_dic_Currency");
    document.getElementById("Right1_txt_CurrencyType").value = "";
    var txt_Price = document.getElementById("Right1_txt_Price");
    dic_Currency.disabled = true;
    dic_Currency.selectedIndex = 0;
    txt_Price.value = "";

    var dic_Game = document.getElementById("Right1_dic_Game");
    var GameID = dic_Game.options[dic_Game.selectedIndex].value;
    AjaxMethod.LoadAmount(GameID,LoadAmount_CallBack);
}
function LoadAmount_CallBack(response)
{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var dic_Server = document.getElementById("Right1_dic_Server");
    var ServerID = dic_Server.options[dic_Server.selectedIndex].value;
    document.getElementById("Right1_txt_ServerID").value = ServerID;
    var dic_Amount = document.getElementById("Right1_dic_Amount");
    var AmountTable = response.value;
    if(ServerID != 0)
    {
        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));
            }
        }
    }
    else
    {
        dic_Amount.disabled = true;
    }
    return;
}

function AmountChange()
{  
    var txt_Price = document.getElementById("Right1_txt_Price");
    var dic_Amount = document.getElementById("Right1_dic_Amount");
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    document.getElementById("Right1_txt_Amount").value = Amount;
    var dic_Currency = document.getElementById("Right1_dic_Currency");
    document.getElementById("Right1_txt_CurrencyType").value = "";
    dic_Currency.disabled = false;
    dic_Currency.selectedIndex = 0;
    txt_Price.value = "";
//    txt_Price.value = "";
//    if(Amount != 0)
//    {
//        dic_Currency.disabled = false;
//    }
//    else
//    {
//        dic_Currency.disabled = true;
//    }
}

function CurrencyChange()
{
    var dic_Server = document.getElementById("Right1_dic_Server");
    var dic_Amount = document.getElementById("Right1_dic_Amount");
    var dic_Currency = document.getElementById("Right1_dic_Currency");
    var ServerID = dic_Server.options[dic_Server.selectedIndex].value;
    var Amount = dic_Amount.options[dic_Amount.selectedIndex].value;
    var Currency = dic_Currency.options[dic_Currency.selectedIndex].value;
    if(Currency == "0") 
    {
        document.getElementById("Right1_txt_CurrencyType").value = "";
    }
    else
    {        
        document.getElementById("Right1_txt_CurrencyType").value = Currency;
    }
    
    AjaxMethod.GerPrice(ServerID,Amount,Currency,CurrencyChange_CallBack);
}
function CurrencyChange_CallBack(response)
{
    if(response.error != null)
    {
        //alert(response.error);
        return;
    }
    var Price = response.value;
    var txt_Price = document.getElementById("Right1_txt_Price");
    txt_Price.value = Price;
    var Btn_Post = document.getElementById("Right1_ImageButton1");
    Btn_Post.disabled = false;
    var dic_Game = document.getElementById("Right1_dic_Game");
    var GameName = dic_Game.options[dic_Game.selectedIndex].innerHTML;
    var dic_Server = document.getElementById("Right1_dic_Server");
    var ServerName = dic_Server.options[dic_Server.selectedIndex].innerHTML;
    document.getElementById("Right1_txt_ProductName").value =GameName + "-" + ServerName;
}

function CheckPostData()
{
    var ServerID = document.getElementById("Right1_txt_ServerID").value;
    var Amount = document.getElementById("Right1_txt_Amount").value;
    var CurrencyType = document.getElementById("Right1_txt_CurrencyType").value;
    var Price = document.getElementById("Right1_txt_Price").value;
    if(parseInt(ServerID) == 0)
    {
        alert("Choose Server");
        return false;
    }
    if(Amount == 0)
    {
        alert("Please Choose Amount");
        return false;
    }
    if(CurrencyType == 0)
    {
        alert("Please Choose Currency");
        return false;
    }
    if(Price = "")
    {
        alert("Please Choose parameter");
        return false;        
    }
}

