﻿    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(){
//    
//        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('|');
               if(data.length<=0 || data==null || data==""){
               
                $('#div_wait').hide();
                return ;
               }
                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);
                if(html==""||html==null){
                $('#div_wait').hide();
                return;
                }
                initProductTable(html);
                $('#div_wait').hide();
            }
        });
    }
    
    function initProductTable(html){
    
    var tblHead="<table border='0' cellpadding='0' cellspacing='0' class='tab_a'><tr><th>NAME</th><th>-TOTAL</th></tr>";
     var tblBody ="";   
	 var tblFoot="</table>";
	 var tag=1;
        
        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];
            }
            if((tag%2)==0){
                tblBody+="<tr onmouseover=\"javascript:this.bgColor='#FCFEB7'\" onmouseout=\"javascript:this.bgColor=''\"><td>"+product[1]+"</td><td>"+price+"</td></tr>";
            }else{
                tblBody+="<tr onmouseover=\"javascript:this.bgColor='#FCFEB7'\" onmouseout=\"javascript:this.bgColor='#F1F1F1'\" bgcolor='#F1F1F1'><td>"+product[1]+"</td><td>"+price+"</td></tr>";
            } 
            tag++;
        }
        document.getElementById('lblpricetable').innerHTML = tblHead + tblBody + tblFoot;
    }
    
    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);
    }