﻿    var gameCode;
    var moneyType = 'USD';
    
    var tblHead = "<table border=\"0\" width=\"600px;\" cellpadding=\"0\" cellspacing=\"0\" class=\"VolumeDiscountbig\" style='margin-left: 6px;'>";
    var tblBody = '';
    var tblFoot = '</table>';
    
    var dataHtml = '';
    
    $(document).ready(function(){
        document.getElementById('dlistServerSelect').selectedIndex = 0;
        var gameServerCode = document.getElementById('dlistServerSelect').value;
    });

    function getProduct(gameServerCode){
        if(gameServerCode == '-1'){
            return;
        }
        $('#div_wait').show();
        $.ajax({
            url : '/GoldDataDispose.aspx',
            type : 'post',
            data : 'operate=getProduct&gameServerCode=' + gameServerCode + '&rd=' + Math.random(),
            dataType : 'html',
            success : function(html){
                dataHtml = html;
                document.getElementById('dlistGoldSelect').length = 0;
                var data = html.split('|');
                for(var i = 0; i < data.length; i++){
                    var product = data[i].split('@');
                    var guid = product[0];
                    var name = product[1];
                    var priceList = product[2];
                    document.getElementById('dlistGoldSelect').options.add(new Option(name, priceList));
                }
                getMoneyType(moneyType);
                initProductTable(html);
                $('#div_wait').hide();
            }
        });
    }
    
    function initProductTable(html){

        tblBody = '';
        var data = html.split('|');
        var moneyChar = '$';
        if(moneyType == 'USD'){
            moneyChar = '$';
        }else if(moneyType == 'EUR'){
            moneyChar = '€';
        }else if(moneyType == 'GBP'){
            moneyChar = '￡';
        }
        
        for(var i = 0; i < data.length; i++){
            var product = data[i].split('@');
            var guid = product[0];
            var name = product[1];
            var priceList = product[2]; 
            var price;
            if(moneyChar == priceList.split('^')[0].substring(0,1)){
                price = priceList.split('^')[0];
            }else if(moneyChar == priceList.split('^')[1].substring(0,1)){
                price = priceList.split('^')[1];
            }else{
                price = priceList.split('^')[2];
            }
            tblBody += "<td style=\"cursor: pointer;\" onclick=\"GetproductChange('"+i+"','"+priceList+"','"+name+"');\" ><table class=\"VolumeDiscount\" style=\"width:100%;\"><th style=\"height:30px;\">" + name + "</th><tr style=\"height:20px;\"><td>" + price + "</td></tr></table></td>";
            if(i!=0&&(i+1)%7==0){
                tblBody+="</tr><tr>";
            }
        }
        document.getElementById('lblpricetable').innerHTML = tblHead + tblBody + tblFoot;
    }
    
    function GetproductChange(productIndex,priceList,name)
    {
    var select=document.getElementById('dlistGoldSelect');
//        if(select.selectedIndex==productIndex)
//        {
            //select.options[select.selectedIndex].text=select.options[productIndex].selectValue;
        //}
         $("#dlistGoldSelect option:eq("+productIndex+")").attr("selected", "selected");
         productChange();
    }
    
    function productChange(){
    
        getMoneyType(moneyType);
    }
    
    function getMoneyType(mType){

        moneyType = mType;
        var sp_priceId = 'sp_' + mType;
        var a_moneyTypeId = 'a_' + mType;
        
        if(document.getElementById('dlistGoldSelect').value == '-1'){
            return;
        }
        
        document.getElementById('sp_USD').style.color = '';
        document.getElementById('a_USD').style.color = '';
        document.getElementById('sp_EUR').style.color = '';
        document.getElementById('a_EUR').style.color = '';
        document.getElementById('sp_GBP').style.color = '';
        document.getElementById('a_GBP').style.color = '';
        
        var ddlProduct = document.getElementById('dlistGoldSelect');
        var priceList = ddlProduct.value.split('^');
        
        document.getElementById('sp_USD').innerHTML = priceList[0];
        document.getElementById('sp_EUR').innerHTML = priceList[1];
        document.getElementById('sp_GBP').innerHTML = priceList[2];
        
        // 改变选中货币类型的颜色（red）
        document.getElementById(sp_priceId).style.color = 'red';
        document.getElementById(a_moneyTypeId).style.color = 'red';
        
        // 设置货币类型、价格、产品名称
        document.getElementById('hidden_price').value = document.getElementById(sp_priceId).innerHTML;
        document.getElementById('hidden_moneyType').value = moneyType;
        document.getElementById('hidden_productName').value = ddlProduct.options[ddlProduct.selectedIndex].text;
        
        initProductTable(dataHtml);
    }
