﻿   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 pro="";
    var isFirefox = (window.navigator.userAgent).indexOf( "Firefox/" ) != -1;
    
    $(document).ready(function(){
        var gameServerCode = document.getElementById('dlistServerSelect').value;init();document.getElementById("select").value="USD";
    });
    
    
    
        
        function getCountry()
        {

            var sCountry = document.getElementById("seleCountry");
//            var dlGoldSelect = document.getElementById("dlistGoldSelect");
//            var dlGoldSelect = document.getElementById("selectgold").innerHTML;
//            var selec = dlGoldSelect.options[dlGoldSelect.selectedIndex].text;
            var selec = document.getElementById("selectgold").innerHTML;



            if(selec.substring(selec.length-1,selec.length)==" ")
            {
                selec = selec.substring(selec.length-1);
            }
            window.location.href="/WOWBuyGoldInfo.aspx?GameCode=019&GameName=World_of_Warcraft - EU&country=" + sCountry.value + "&Product=" + selec.toLowerCase();
            
//            $.ajax({
//                url : '/WOWBuyGoldInfo.aspx',
//                type : 'get',
//                data : 'operate=getCountryServer&GameCode=019&GameName=World_of_Warcraft - EU&country=' + sCountry.value + '&rd=' + Math.random(),
//                dataType : 'html',
//                success : function(html){
//                }
//            });
        }
    

    function getProductPrice(){
    
    var productName = document.getElementById("selectgold").innerHTML;

    var gameServerCode = document.getElementById("dlistServerSelect").value
    $('#right_foot').show();
    var productListtd="<table cellspacing=\"0\" style=\"margin:0\">";
        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){
                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];
                    var produSplit = priceList.split('^');
                    var price="";
                    if(moneyType == 'USD'){
                        price=produSplit[0];
                    }else if(moneyType == 'EUR'){
                        price=produSplit[1];
                    }else if(moneyType == 'GBP'){
                        price=produSplit[2];
                    }
                    if(i%2==0)
                    {
                        productListtd = productListtd + "<tr  style=\"cursor:pointer\" onmouseover=\"javascript:this.style.backgroundColor='#FFA800'\" onmouseout=\"javascript:this.style.backgroundColor=''\"  onclick=\"productChange('"+name+"','"+priceList+"','"+i+"') \">"
                        +"<td><img src=\"/images/arrow11.gif\">"+name+"</td>"
                        + "<td><b>"+price+"</b></td></tr>";
                    }
                    else
                    {
                        productListtd = productListtd + "<tr  style=\"cursor:pointer\" onmouseover=\"javascript:this.style.backgroundColor='#FFA800'\" onmouseout=\"javascript:this.style.backgroundColor='#F0F5F9'\"  onclick=\"productChange('"+name+"','"+priceList+"','"+i+"') \">"
                        +"<td><img src=\"/images/arrow11.gif\">"+name+"</td>"
                        + "<td><b>"+price+"</b></td></tr>";
                    }
                    
                    //document.getElementById('dlistGoldSelect').options.add(new Option(name, priceList));
                    if(name==productName)
                    {
                        document.getElementById("selectgold").innerHTML=name;
                        document.getElementById("selectPrice").innerHTML = priceList;
                        document.getElementById("hidden_ProductIndex").value=i;
                    }
                }
            productListtd = productListtd + "</table>";
            $('#top16').html(productListtd);
              getMoneyType(moneyType);
               
                $('#div_wait').hide();dlGoldSelectIndex();
            }
        });
        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 getProduct(gameServerCode){
   
    $('#right_foot').show();
    var productListtd="<table cellspacing=\"0\" style=\"margin:0\">";

        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];




                    var produSplit = priceList.split('^');
                    var price="";
                    if(moneyType == 'USD'){
                        price=produSplit[0];
                    }else if(moneyType == 'EUR'){
                        price=produSplit[1];
                    }else if(moneyType == 'GBP'){
                        price=produSplit[2];
                    }
//                    productListtd = productListtd + "<tr  style=\"cursor:pointer;\" onmouseover=\"javascript:this.style.backgroundColor='#FFA800'\" onmouseout=\"javascript:this.bgColor=''\"  onclick=\"productChange('"+name+"','"+priceList+"','"+i+"')\">"
//                    +"<td><img src=\"/images/arrow11.gif\">"+name+"</td>"
//                    + "<td><b>"+price+"</b></td></tr>";
                    if(i%2==0)
                    {
                        productListtd = productListtd + "<tr  style=\"cursor:pointer\" onmouseover=\"javascript:this.style.backgroundColor='#FFA800'\" onmouseout=\"javascript:this.style.backgroundColor=''\"  onclick=\"productChange('"+name+"','"+priceList+"','"+i+"') \">"
                        +"<td><img src=\"/images/arrow11.gif\">"+name+"</td>"
                        + "<td><b>"+price+"</b></td></tr>";
                    }
                    else
                    {
                        productListtd = productListtd + "<tr  style=\"cursor:pointer\" onmouseover=\"javascript:this.style.backgroundColor='#FFA800'\" onmouseout=\"javascript:this.style.backgroundColor='#F0F5F9'\"  onclick=\"productChange('"+name+"','"+priceList+"','"+i+"') \">"
                        +"<td><img src=\"/images/arrow11.gif\">"+name+"</td>"
                        + "<td><b>"+price+"</b></td></tr>";
                    }
                    //document.getElementById('dlistGoldSelect').options.add(new Option(name, priceList));
                    if(i==0)
                    {
                        document.getElementById("selectgold").innerHTML=name;

                        document.getElementById("selectPrice").innerHTML = priceList;
                        document.getElementById("hidden_ProductIndex").value=i;

                    }
                    if(pro!=null && pro!="")
                    {
                        if(name.substring(name.length-1,name.length)==" ")
                        {
                            name = name.substring(0,name.length-1);
                        }
                        if(name.toLowerCase()==pro.toLowerCase())
                        {
                            document.getElementById("selectgold").innerHTML=pro;
                            document.getElementById("selectPrice").innerHTML = priceList;
                            document.getElementById("hidden_ProductIndex").value=i;
                        }
                    }
                }
            productListtd = productListtd + "</table>";
            $('#top16').html(productListtd);
              getMoneyType(moneyType);
              if(gameCode == "001"){
              initFFXIProductTable(html);
              }else{
                 initWOWProductTable(html);
              }
               
                $('#div_wait').hide();uninit();dlGoldSelectIndex();
            }
        });
        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 dlGoldSelectIndex()
    {
//        var productIndex = document.getElementById("dlistGoldSelect").selectedIndex+1;
var productin=document.getElementById("hidden_ProductIndex").value;
var productIndex = parseInt(productin)+1;
            if(productIndex != 0){
                $('#ul_gold > li').each(function(i){
                    if(i == productIndex-1){
                        $(this).css('background','#FFF386');
                    }else{
                        $(this).css('background','');
                    }
                });
            }else{
               $(this).css('background','#FFF386');
            }
    }

    
    
        function initFFXIProductTable(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];
            }
           var oldPrice = formatFloat(parseFloat(price.split(' ')[1]) * 1.1, 2);
                     tblBody += '<li style="cursor: pointer;" onclick=\'clickGoldTable('+ (i + 1) +',"'+name+'","'+priceList+'");\'>\
			        <div class="gold_box_G">'+ name +'</div>\
                     <p class="heng">' + moneyChar + ' ' + oldPrice + '</p>\
			            <p class="red">' + price + '</p>\
		            </li>'

        }

        document.getElementById('ul_gold').innerHTML =  tblBody;
    }
    
    
            function initWOWProductTable(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];
            }
           var oldPrice = formatFloat(parseFloat(price.split(' ')[1]) * 1.1, 2);

                     tblBody += '<li style="cursor: pointer;" onclick=\'clickGoldTable('+ (i + 1) +',"'+name+'","'+priceList+'");\'>\
			        <div class="gold_box_G">'+ name +'</div>\
			            <p class="red">' + price + '</p>\
		            </li>'

        }
        
        document.getElementById('ul_gold').innerHTML =  tblBody;
    }
    
    
    
//    function productChange(){
//        getMoneyType(moneyType);
//    }































    
    function productChange(name,priceList,productIndex){

        if(document.getElementById("dlistServerSelect").value=="-1")
        {
            alert("please choose server!");
            return;
        }
        getMoneyType1(moneyType,name,priceList);
        document.getElementById("hidden_ProductIndex").value=productIndex;
        dlGoldSelectIndex();
        DIVShow('top16');












    }
    
    clickGoldTable = function(index,name,priceList){
            //var ddlProduct = setData.domProduct;
           // document.getElementById("")
            //document.sfsdf.dlistGoldSelect.options[index-1].selected = true ;
            getMoneyType1(moneyType,name,priceList);
      var productIndex = parseInt(index);
            if(productIndex != 0){
                $('#ul_gold > li').each(function(i){
                    if(i == productIndex-1){
                        $(this).css('background','#FFF386');
                    }else{
                        $(this).css('background','');
                    }
                });
            }else{
               $(this).css('background','#FFF386');
            }
        }
    
    /////////////////////////////////////
    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_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;
//        
//          if(gameCode == "001"){
//              initFFXIProductTable(dataHtml);
//              }else{
//                 initWOWProductTable(dataHtml);
//              }
//    }
    
    
    function getMoneyType(mType){
        moneyType = mType;
        var sp_priceId = 'sp_' + mType;
        //var a_moneyTypeId = 'a_' + mType;
        
        
        document.getElementById('sp_sign').style.color = '';
        
        var priceListProduct = document.getElementById("selectPrice").innerHTML;
        var priceList = priceListProduct.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];
        }
                
//        document.getElementById('sp_sign').innerHTML=priceList;
      
        
        // 改变选中货币类型的颜色（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 = document.getElementById("selectgold").innerHTML;

        
          if(gameCode == "001"){
              initFFXIProductTable(dataHtml);
              }else{
                 initWOWProductTable(dataHtml);
              }
              
    }
    
    function getMoneyType1(mType,name,priceListProduct){
        moneyType = mType;
//        var sp_priceId = 'sp_' + mType;
//        var a_moneyTypeId = 'a_' + mType;
        
        
        document.getElementById('sp_sign').style.color = '';
        document.getElementById("selectPrice").innerHTML=priceListProduct;
        var priceList = priceListProduct.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];
        }
        document.getElementById("selectgold").innerHTML=name;

//        document.getElementById('sp_sign').innerHTML=priceList;
      
        
        // 改变选中货币类型的颜色（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 = name;
        
          if(gameCode == "001"){
              initFFXIProductTable(dataHtml);
              }else{
                 initWOWProductTable(dataHtml);
              }
    }
    
    function getMoneyTypeProduct(mType)
    {
        moneyType = mType;
        document.getElementById("sp_signtype").innerHTML = moneyType;
        if(document.getElementById("dlistServerSelect").value=="-1")
        {
            alert("please choose server!");
            return;
        }
        getProductPrice();
    }
    
    
    function GetServerStorage(gameServerCode){
        if(gameServerCode == '-1'){
            return;
        }
        var gmCode = gameServerCode.substr(0, 3);
          if(gameCode=="019" || gameCode =="013" || gameCode =="001" || gameCode =="083" || gameCode =="087"){
//            return;
        
        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);
            }
        });
        }
    }


