﻿    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 = '';
        var isIE = document.all?true:false;
    var isNS = document.layers?true:false;
    var isFirefox = (window.navigator.userAgent).indexOf( "Firefox/" ) != -1;
    
    $(document).ready(function(){
        var gameServerCode = document.getElementById('dlistServerSelect').value;
    });

    function getProduct(gameServerCode){
        if(gameServerCode == '-1'){
            return;
        }
           gameCode = gameServerCode.split(',')[0];
        $('#div_wait').show();
        if(gameServerCode=="FFXI Powerleveling")
        {
         window.location.href='/power-leveling/Final-Fantasy-XI/';
        }
        $.ajax({
            url : '/GoldDataDispose.aspx',
            type : 'post',
            data : 'operate=getProduct&gameServerCode=' + gameServerCode + '&rd=' + Math.random(),
            dataType : 'html',
            success : function(html){
                 GetServerStorage(gameServerCode);
                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));
                }
                
                //判断游戏

               var gamecode = gameServerCode.split(',');
              if (gamecode[0] == "001") {
              getFFXIMoneyType(moneyType);
               initFFXIProductTable(html);
              }else{
              getMoneyType(moneyType);
                initProductTable(html);
              }
                $('#div_wait').hide();
            }
        });
                var code="<%=GameCode %>";
      if(gameCode=="019" || gameCode =="013" || gameCode =="001" || gameCode =="083" || gameCode =="087"){
     dlistServerSelect = document.getElementById("dlistServerSelect");
            if(dlistServerSelect.selectedIndex>0){
                  $("#trServerName").show();
              //   $("#trStatus").show() 
                   var serverName="All Servers";
                   //var lblServer=document.getElementById("lblServerName");
                   if(true){
                        GetSalesStatus(gameServerCode);
                       if(dlistServerSelect.selectedIndex>0) {
                            if(isIE){
                                serverName=dlistServerSelect.options[dlistServerSelect.selectedIndex].innerText;
                            }else{
                                serverName=dlistServerSelect.options[dlistServerSelect.selectedIndex].text;
                           }
                       }
                       // document.getElementById("lblServerName").innerHTML=serverName;
                    }
               }else{
                  //  $("#trServerName").hide();
                  $("#trStatus").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><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 initFFXIProductTable(html){
        tblBody = '';
        var data = html.split('|');
        var moneyChar = '$';
        if(moneyType == 'USD'){
            moneyChar = '$';
        }else if(moneyType == 'EUR'){
            moneyChar = '€';
        }else if(moneyType == 'GBP'){
            moneyChar = '￡';
        }
     //  tblBody +='<ul style=\"display: block;\" id=\"ul_gold\">';
        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];
            }
           var oldPrice = formatFloat(parseFloat(price.split(' ')[1]) * 1.1, 2);
//           if(priceConfig > 0){
//                    oldPrice = formatFloat(oldPrice / priceConfig, 2);
//                }
                     tblBody += '<li style="background: #DDFFD5 none repeat scroll 0% 0%; cursor: pointer; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;" onclick=\'clickGoldTable('+ (i + 1) +');\'>\
			        <div class="gold_box_G">'+ name +'</div>\
			            <p class="heng">' + moneyChar + ' ' + oldPrice + '</p>\
			            <p class="red">' + price + '</p>\
		            </li>'
//            }
        }
      //  tblBody +="</ul>"
        document.getElementById('ul_gold').innerHTML =  tblBody;
    }
    
    function productChange(){
        getMoneyType(moneyType);
    }
    
    /////////////////////////////////////
    function formatFloat(src, pos){return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);}
    /////////////////////////////////////
    
    
    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('^');
        if(moneyType == 'USD'){
           document.getElementById('sp_USD').innerHTML = priceList[0];
        }else if(moneyType == 'EUR'){
            document.getElementById('sp_EUR').innerHTML = priceList[1];
        }else if(moneyType == 'GBP'){
             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);
    }
    
    ///////////////////////////////////////////////////////////
      function getFFXIMoneyType(mType){
        moneyType = mType;
        var sp_priceId = 'sp_' + mType;
        var a_moneyTypeId = 'a_' + mType;
        
        if(document.getElementById('dlistGoldSelect').value == '-1'){
            return;
        }
        
        document.getElementById('sp_sign').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('^');
        if(moneyType == 'USD'){
           document.getElementById('sp_sign').innerHTML = priceList[0];
        }else if(moneyType == 'EUR'){
            document.getElementById('sp_sign').innerHTML = priceList[1];
        }else if(moneyType == 'GBP'){
             document.getElementById('sp_sign').innerHTML = priceList[2];
        }
        
        
      
        
        // 改变选中货币类型的颜色（red）
        document.getElementById('sp_sign').style.color = 'red';
        document.getElementById(a_moneyTypeId).style.color = 'red';
        
        // 设置货币类型、价格、产品名称
        document.getElementById('hidden_price').value = document.getElementById('sp_sign').innerHTML;
        document.getElementById('hidden_moneyType').value = moneyType;
        document.getElementById('hidden_productName').value = ddlProduct.options[ddlProduct.selectedIndex].text;
        
        initFFXIProductTable(dataHtml);
    }
    
    
        function GetServerStorage(gameServerCode){
        if(gameServerCode == '-1'){
            return;
        }
        var gmCode = gameServerCode.substr(0, 3);
          if(gmCode=="019" || gmCode =="013" || gmCode =="001" || gmCode =="083" || gmCode =="087"){       
        document.getElementById('trStatus').style.display = 'block';
        for(var i = 1; i <= 10; i++){
            var id = 'colorTd' + i;
            var nocolor = $('#' + id).attr('nocolor');
            $('#' + id).attr('style', 'BACKGROUND:' + nocolor);
        }
        $.ajax({
            url : '/GoldDataDispose.aspx?rd=' + Math.random(),
            type : 'get',
            data : 'operate=getServerStorage&gameServerCode=' + gameServerCode,
            dataType : 'html',
            success : function(data){
                var storage = parseInt(data);
                if(parseInt(storage) > 1500000){
                    document.getElementById('storage').innerHTML ='1500000+';
                }else{
                    document.getElementById('storage').innerHTML = storage;
                }
                            var count = Math.round((parseFloat(storage* 10) / 1500000));
                 if (gameCode == "001") {
                       count = Math.floor(1+Math.random()*(10));
                }
                else if (gameCode == "083" || gameCode == "087") {
                        count = Math.floor(1+Math.random()*(10));
                }
                var i = 1;
                var interValId = window.setInterval(function(){
                    if(count >= 10){
                        count = 10;
                    }
                    if(i <= count){
                        var id = 'colorTd' + i;
                        var old = $('#' + id).attr('old');
                        $('#' + id).attr('style', 'BACKGROUND:' + old);
                        i++;
                    }else{
                        window.clearInterval(interValId);
                    }
                }, 120);
            }
        });
        }
    }