  var rates;
  var credit;
  var curType='0';
  var mingoldnumber=0;
  var load={game:false,server:false,blocklist:false,serverkey:false};//第一次加载
  var serverlist;//server list backup for ddlserverkey change 4.28
 (function($){
  $.fn.rateInit=function(){
       $.ajax({
            url : 'goldData.aspx',
            type :'get',
            data : 'operate=getrates',
            dataType : 'json',
            success : function(json){
               rates={
                    GBP_Rate:json.GBP,
                    EUR_Rate:json.EUR
               };
            }
        });    
  }
  
  $.fn.getGameList=function(){
        $('#gamewait').css('display','inline');
        $.ajax({
            url : 'goldData.aspx',
            type :'get',
            data : 'operate=gamelist',
            dataType : 'html',
            success : function(html){
                $('#ddlGame').html(html.replace("Choose","Wählen"));
                setTimeout(function(){
                    if(load.game==false){
                        load.game=true;
                        $('#ddlGame').val($('#degameid').val());//初始游戏,初始交易方式,初始服务器
                        if($('#ddlGame').val()!='-1'){
                              $(this).getLeftLinks($('#ddlGame').val());//设置左测链接
                              if(ShowKey($('#ddlGame').val()))
                                  $('#ddlServerKey').css('display','inline');
                              else
                                  $('#ddlServerKey').css('display','none');
                              $('#ddlServer').getServerList({gameID:$('#ddlGame').val()});
                              $('.gold_b4R table').getTrade({
                                  gameID:$('#ddlGame').val()
                              });
                              $('#ddlServer').attr('disabled','');
                        }
                     }
                     if(load.serverkey==false){
                          load.serverkey=true; 
                          $("#ddlServerKey").val($("#dekey").val());                     
                     }
                     
                },100)
                $('#gamewait').css('display','none');
                editalt(0); 
            }
        });
  }
  
   $.fn.getServerList=function(game){
        loadserver(game.gameID);
        if(game.gameID!="-1"){
            $('#serverwait').css('display','inline');
            $.ajax({
                url : 'goldData.aspx',
                type :'get',
                data : 'operate=serverlist&gameID='+game.gameID,
                dataType : 'html',
                success : function(html){
                    serverlist=html;//backup to ddlserver key to change
                    $('#ddlServer').html(html.replace("Choose","Wählen"));
                    setTimeout(function(){
                        if(load.server==false){
                            load.server=true;
                            $('#ddlServer').val($('#deserverid').val());//初始服务器
                            if($('#ddlGame').val()!='-1'&&$('#ddlServer').val()!='-1'&&$('#deblockid').val()!='-1'){
                                $('#ddlServer').getBlockList({gameID:$('#ddlGame').val(),serverID:$('#ddlServer').val()});
                                $('#ddlServer').attr('disabled','');
                            }
                        }
                        $('#serverwait').css('display','none');
                        //load server key
                        if(ShowKey($('#ddlGame').val())){
                            $('#ddlServer option').each(function(){
                                if($(this).text().substring(0,1).toUpperCase()!=$('#ddlServerKey').val()&&$(this).val()!='-1')
                                    $(this).remove();
                            })
                        }
                    },100)  
                }
            });
        }
  }
  
  $.fn.getBlockList=function(server){
        loadproducts(server.serverID);
        if(server.serverID!="-1"){
            $('#productwait').css('display','inline');
            $.ajax({
                url : 'goldData.aspx',
                type :'get',
                data : 'operate=blocklist&gameID='+server.gameID+"&serverID="+server.serverID,
                dataType : 'html',
                success : function(html){
                    var strs=html.split('~');
                    //strs[0] blocklist,strs[1] en,strs[2] gbp,strs[3] eur,strs[4] mingoldnum
                    $('#ddlProduct').html(strs[0].replace("Choose","Wählen"));
                    $('#blockdataen').html(strs[1]);
                    $('#blockdatagbp').html(strs[2]);
                    $('#blockdataeur').html(strs[3]);
                    mingoldnumber=parseInt(strs[4]);
                    if(strs[1]!=""){
                        $('.gold_bL div:eq(1) ').removeClass('buygoldleft');
                        $('.gold_bL div:eq(1) ').addClass('buygoldleft_nobg');
                    }else{
                        $('.gold_bL div:eq(1) ').removeClass('buygoldleft_nobg');
                        $('.gold_bL div:eq(1) ').addClass('buygoldleft');
                    }
                    loadBlockListByCurType();
                    setTimeout(function(){
                        if(load.blocklist==false){
                            load.blocklist=true;
                            $('#ddlProduct').val($('#deblockid').val());
                            //$('#ddlProduct').attr('disabled','');
                            if($('#ddlProduct').val()!='-1'){
                                loadDefaultCurType();
                            }
                        }
                        bindBlockList_Event();
                        productchange();//select blockid
                        $('#productwait').css('display','none');
                    },100)  
                }
            });
        }
  }
  $.fn.getPrice=function(server){
    $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=getprice&gameID='+server.gameID+"&serverID="+server.serverID+"&curType="+server.curType+"&amount="+server.amount,
        dataType:'html',
        success:function(html){
            $('#txtPrice').val(html);
        }    
    });
  } 
  
  $.fn.getTrade=function(server){
    $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=gettrademode&gameID='+server.gameID,
        dataType:'html',
        success:function(result){
            disposeTradeMode(result);
        }    
    });
  } 
  
  $.fn.getCredit=function(){
    $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=getcredit&random='+Math.random(),
        dataType:'html',
        success:function(html){
            var resultStr;
            if(html=="0")
                resultStr=html;
            else
                resultStr=html.substring(1);
            credit=resultStr;
            if(parseFloat(resultStr)>0){
                 $('#cu_credit span:eq(1)').text(html);
                 curCreditByCmd(1);
            }else{
                 curCreditByCmd(0);
            }
        }
    })
  }
  
   
  //允许输入包括0的数字(没改)
  $.fn.checkNum=function(){
     var numstr = $(this).val();  
     var num =numstr.replace(/,| /g,"");
        
     if(num.length>1)
     {
         num = num.replace(/\b[0*]/g,"");
     }          
     if(!num.match(/[^0-9]/g))
     { 
        $(this).val(num.replace(/,/g,""));
        return false;
     }
     else
     {
	     $(this).val('1');
	     return true;
     }
  }
  
$.fn.checkDouble=function(){
   var test_value=$(this).val();
   if(test_value.match(/^\d+((\.?\d+)|(\d*))$/)){
        return true;
   }else{
        return false;
   }
 }
 
  $.fn.checkEmail=function(){
      if($(this).val()!=""){
         if(!$(this).val().match(/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/g)){
            return true;
         }else{
            return false;
         }
      }
  }
  
  $.fn.checkConfirm=function(obj){
    if(obj.val()=="")
        $(this.val(''));
    if(obj.val()!=""&&$(this).val()!=""){
        if(obj.val()!=$(this).val()){
            alert('Error Input Compare');
            $(this).val('');
        }
    }
  }
  $.fn.checkNull=function(){
    if($(this).val().trim()==""||$(this)==null){
        return true;
    }else{
        return false;
    }
  }
  $.fn.checkNotNull=function(){
    if($(this).val()==""||$(this)==null){
        return false;
    }else{
        return true;
    }
  }
  
  
  $.fn.hide=function(){
    $(this).css('display','none');
  }
  
  $.fn.show=function(info,obj){
    $('#input_error').text(info);
    if(obj!='none'){
        obj.val('');
        obj.css('border','1px solid red');
        obj[0].focus();
        obj.blur(function(){
            $(this).css('border','1px solid #9D693A');
            $(this).unbind('blur');
        })
    }
  }
  $.fn.ajaxOrder=function(order){
       $.ajax({
            url:'goldData.aspx',
            type:'get',
            data:'operate=toorder&gameID='+order.gameID+'&serverID='+order.serverID+'&saleBlcokID='+order.saleBlockID+'&currecyType='+order.curType+'&'+
            'amount='+order.curAmount+'&curPrice='+order.curPrice+'&couponCode='+encodeURI(order.couponCode)+'&tradeMode='+order.tradeMode+'&tradeAddress='+order.tradeAddress+'&charName='+encodeURI(order.charName)+'&'+
            'trueName='+encodeURI(order.fullName)+'&email='+encodeURI(order.email)+'&phone='+order.usPhone+'&nonUSPhone='+encodeURI(order.nonUSPhone)+'&actName='+encodeURI(order.actName)+'&actPwd='+encodeURI(order.actPwd)+'&credit='+order.credit+'&payMethod='+order.payMethod+'&maxcredit='+order.maxUseCredit,
            dataType:'html',
            success:function(info){
                //下单相关错误提示，若无则不处理
                if(info=="error"){
                    //错误处理
                    $('#sdiv').css('display','none');
                }else{
                    //下单成功，转向订单详细页
                    location.href='Payingfororder.aspx?OrderSerial='+info;
                }
            }
       })
  }
  
  $.fn.useCre_Coupon=function(server){
    $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=usecreorcoupon&gameID='+server.gameID+'&serverID='+server.serverID+'&email='+server.email+'&'+
        'couponCode='+server.couponCode+'&credit='+server.credit+'&curType='+curType+'&amount='+server.amount+'&'+
        'saleBlcokID='+server.saleBlcokID+'&maxcredit='+server.maxUseCredit+'&number='+Math.random(),
        dataType:'json',
        success:function(json){
           if(json[0].error!=""){
                $('#credirorcoupon').html('<center><font style="color:red">'+json[0].error+'</font></center>');
                 $('#txtcredit').val('');
                 $('#txtCoupon').val('');
           }
           else{
               $('#credirorcoupon').html('<span style="color:#000" id="amount">'+json[0].amount+'</span>'+
                           '<span style="color:Red;margin-left:5px;" id="totalamount">'+json[0].totalamount+'</span>'+
                           '<span style="color:#000;margin-left:5px;" id="ch_money">'+json[0].money+'</span>'+
                           '<span style="color:Red;margin-left:5px;" id="di_money">'+json[0].dismoney+'</span>');
               
               if($('#amount').text()==$('#totalamount').text()){
                    $('#totalamount').css('display','none');
                    $('#amount').css('color','red');
                    $('#amount').html('<font style="color:#ff5400;">Amount:</font>'+json[0].amount)
               }else{
                    $('#amount').html('<font style="color:#ff5400;">Amount:</font><s>'+json[0].amount+'</s>')
               }
               if($('#ch_money').text()==$('#di_money').text()){
                    $('#di_money').css('display','none');
                    $('#ch_money').css('color','red');
                    $('#ch_money').html('<font style="color:#ff5400;">Charge:</font>'+json[0].money)
               }else{
                    $('#ch_money').html('<font style="color:#ff5400;">Charge:</font><s>'+json[0].money+'</s>')
               }
           }
           $('#btnuse_cre_cou img').attr('src','http://vcsale.21cge.com/images/replly.jpg');
           $('#credirorcoupon').css('display','block');
        }
    })
  }
  
  $.fn.getLeftLinks=function(gameID){
    $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=leftlinks&gameID='+gameID,
        dataType:'html',
        success:function(html){
            $('#leftlinks').html(html);
        }
    })
  }
  
  $.fn.loadUserInfo=function(){
     $.ajax({
        url:'goldData.aspx',
        type:'get',
        data:'operate=userinfo&number='+Math.random(),
        dataType:'json',
        success:function(json){
            if(json[0].logined=="true"){
                if(json[0].truename!='')
                    $('#txtfullname').val(json[0].truename);
                if(json[0].mail!='')
                    $('#txtemail').val(json[0].mail);
                if(json[0].nonusphone!='')
                    $('#txtnonusphone').val(json[0].nonusphone);
                if(json[0].usphone!=''){
                    var _usphone=json[0].usphone;
                    $('#usphone input:eq(0)').val(_usphone.substring(0,3));
                    $('#usphone input:eq(1)').val(_usphone.substring(3,6));
                    $('#usphone input:eq(2)').val(_usphone.substring(6));
                }
                $('.gold_b4L input[value!=""]').attr('readonly','readonly');
                $('.gold_b4L input[value!=""]').css('background-color','transparent').css('background','#f0e1b0');
                $('.gold_b4L input[value!=""]').css('border','0');
                var _usp;
                $('#usphone input').each(function(){
                    if($(this).checkNull()){
                        _usp+=$(this).val();
                    }else{
                        _usp='';
                        return false;
                    }
                })
                
                if($('#txtnonusphone').checkNull()){
                    $('#cu_nonusphone').css('display','none');
                }
                
                if(_usp=''){
                    $('#cu_usphone').css('display','none');
                }
            }
        }
    })
  }
  
  })(jQuery)
function formatFloat(src, pos){return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);}
String.prototype.trim=function(){return   this.replace(/(^\s*)|(\s*$)/g,"");}








$(document).ready(function(){
    init();
})

function init(){
    curAmountByCmd(0);//隐掉自定义数量
    curCreditByCmd(0);//隐掉点数
    tradeModeByCmd(0);//隐掉trademode
    actByCmd(0);//隐掉帐号，密码输入
    curType=$('#decurtype').val();
    $('.gold_bord:eq(0) a').css('cursor','pointer');
    $('#ddlProduct').attr('disabled','true');
    $('#ddlServer').attr('disabled','true');
    $('#txtAmount').val("");
    clearMoney();//清空当前货币数量
    $('#cuCheck').css('cursor','hand');
    $('#cuCheck').click(function(){
        if($('#cuCheckbox').attr('checked')){
            $('#cuCheckbox').attr('checked',false);
            curAmountByCmd(0);//隐掉自定义
        }else{
            $('#cuCheckbox').attr('checked',true);
            curAmountByCmd(1);//显示自定义
        }
    })
    $(this).getGameList();//获取gamelist
    $(this).rateInit();//初始汇率
    $(this).getCredit();//初始点数
    $(this).loadUserInfo();//加载登陆后的用户信息
    editalt(0);//将select game置成当前操作色
    $('#ddlGame').change(function(){
        actByCmd(0);//隐掉帐号，密码输入
        $('.gold_bL div:eq(1)  ul').html('');
        $('.gold_bL div:eq(1)').removeClass('buygoldleft_nobg');
        $('.gold_bL div:eq(1)').addClass('buygoldleft');
        clearMoney();
        $('#ddlServer').getServerList({gameID:$('#ddlGame').val()})
        $('#txtAmount').val('');
        $('#txtPrice').val('');
        if(ShowKey($('#ddlGame').val()))
            $('#ddlServerKey').css('display','inline');
        else
            $('#ddlServerKey').css('display','none');
        $('#ddlServerKey').val('A');
        $('.gold_b4R table').getTrade({
            gameID:$('#ddlGame').val()
        });
        editalt(0);
    })
    
    $('#ddlServer').change(function(){
        $('#ddlProduct').getBlockList({gameID:$('#ddlGame').val(),serverID:$('#ddlServer').val()})
        editalt(0);
    })
    
    $('#ddlProduct').change(function(){
        productchange();
    })
    
    $('#cuCheckbox').click(function(){
        if($('#cuCheckbox').attr('checked'))
            curAmountByCmd(1);//显示自定义数量
        else
            curAmountByCmd(0);//隐掉自定义
    })
    
    $('#ddlServerKey').change(function(){
        $('#ddlServer').html(serverlist);//restore server list to change
        $('#ddlServer option').each(function(){
            if($(this).text().substring(0,1).toUpperCase()!=$('#ddlServerKey').val()&&$(this).val()!='-1')
                $(this).remove();
        })
        loadproducts($("#ddlServer").val());
    })
    
    $('#a_USD').click(function(){
       $('.gold_bL div:eq(1) ul').html($('#blockdataen').html());
       if(credit!="0")
            $('#cu_credit span:eq(1)').text("$"+credit);
       fontColorClear($(this));
       moneyColorClear(0);
       curType='0';
       bindBlockList_Event();
       calccustomerprice();
    })
    
    $('#a_EUR').click(function(){
        $('.gold_bL div:eq(1) ul').html($('#blockdataeur').html());
        if(credit!="0")
            $('#cu_credit span:eq(1)').text("€"+(formatFloat(credit/rates.EUR_Rate,2)));
        fontColorClear($(this));
        moneyColorClear(1);
        curType='2';
        bindBlockList_Event();
        calccustomerprice();
    })
    
    
    $('#a_GBP').click(function(){
        $('.gold_bL div:eq(1) ul').html($('#blockdatagbp').html())
        if(credit!="0")
            $('#cu_credit span:eq(1)').text("£"+(formatFloat(credit/rates.GBP_Rate,2)));
        fontColorClear($(this));
        moneyColorClear(2);
        curType='1';
        bindBlockList_Event();
        calccustomerprice();
    })
    
    //tradeMode单击事件
    $('#face input').click(function(){
        if($(this).attr('checked')){
            actByCmd(0);//隐掉帐号密码输入
            $('#txtactname').val('');//清空帐号密码,防止非put方式取值
            $('#txtactpwd').val('');
            $('#tradeaddress').css('display','inline');
        }
    })
    
    $('#put input').click(function(){
        if($(this).attr('checked')){
            actByCmd(1);//显示帐号密码输入
            $('#tradeaddress').css('display','none');
        }
    })
    
    $('#sendmail input').click(function(){
        if($(this).attr('checked')){
            actByCmd(0);//隐掉帐号密码输入
            $('#txtactname').val('');
            $('#txtactpwd').val('');
            $('#tradeaddress').css('display','none');
        }
    })
    //tradeMode单击事件结束
    
    
    //使用credit或gifcode
    $('#btnuse_cre_cou img').click(function(){
        var _maxUseCre='false';
        if($('#cu_credit span:eq(1)').text()!=''&&$('#cu_credit span:eq(1)').text().substring(1)==$('#txtcredit').val()){
            _maxUseCre='true';
        }
        if($('#ddlGame').val()=='-1'){
            $(this).show('Bitte wählen Game',$('#ddlGame'));
            return;
        }
          
        if($('#ddlServer').val()=='-1'){
             $(this).show('Bitte wählen Server',$('#ddlServer'));
            return;
        }
            
        var _amount="0";
        var _saleBlockID="0";
            
        if(!$('#cuCheckbox').attr('checked')){    
            if($('#ddlProduct').val()=='-1'){
                $(this).show('Bitte wählen Block',$('#ddlProduct'));
                return;  
            }else{
                 _saleBlockID=$('#ddlProduct').val();
            }
        }else{
            if($('#txtAmount').checkNull()){
                $(this).show('Bitte geben Sie Ihre Kunden Amount',$('#txtAmount'));
                return;  
            }else{
                _amount=$('#txtAmount').val();
            }
        }
         
        if($('#txtcredit').checkNull()&&$('#txtCoupon').checkNull()){
            if($('#cu_credit1').css('display')!='none')
                $('#txtcredit').show('Bitte geben Sie Ihre Kreditkarten',$('#txtcredit'));
            else
                $('#txtCoupon').show('Bitte geben Sie Gutscheincode',$('#txtCoupon'));
            return;
        }

        
        $('#btnuse_cre_cou img').attr('src','http://vcsale.21cge.com/images/process.gif');
        $('#txtcredit').useCre_Coupon({
            gameID:$('#ddlGame').val(),
            serverID:$('#ddlServer').val(),
            email:$('#txtemail').val(),
            couponCode:$('#txtCoupon').val(),
            credit:$('#txtcredit').val().trim()==""?"0":$('#txtcredit').val().trim(),
            curType:curType,
            amount:_amount,
            saleBlcokID:_saleBlockID,
            maxUseCredit:_maxUseCre
        });
    })
    
    //用户输入检测
    $('#txtAmount').keyup(function(event){
       calccustomerprice();
    })
    
//    $('#txtcredit').keyup(function(event){
//        if($(this).checkDouble($('#txtcredit'))){
//            if(parseFloat($(this).val())>parseFloat($('#cu_credit span').text().substring(1)))
//                $(this).val($('#cu_credit span').text().substring(1));
//        }else if($(this).checkDouble($('#txtcredit'))==false){
//            $(this).show('Input Info Type Error!',$('#txtcredit'));
//            return;
//        }
//    })
        
    $('#txtemail').blur(function(){
       if($(this).checkEmail()){
           $(this).show('Geben Sie bitte Ihre E-Mail',$('#txtemail'));
           return;
       }
    })
    
    
    $('#usphone input').each(function(){
        $(this).keyup(function(event){
            //$(this).checkNum();取消美国电话不允输入字母
            if($(this).val().length==$(this).attr('maxlength')){
               switch($(this).attr('id')){
                    case 'usp1':
                        $('#usp2')[0].focus();
                        break;
                    case 'usp2':
                        $('#usp3')[0].focus();
                        break;
                    case 'usp3':
                        $('#txtnonusphone')[0].focus();
                        break;
               }
            }
        })
    })
    
    
    //提交订单
    $('#buygoldsubmit').click(function(){
        if($('#ddlGame').val()=='-1'){
            $(this).show('Bitte wählen Game',$('#ddlGame'));
            return;
        }
          
        if($('#ddlServer').val()=='-1'){
             $(this).show('Bitte wählen Server',$('#ddlServer'));
            return;
        }
            
        if($('#cuCheckbox').attr('checked')==false){
            if($('#ddlProduct').val()=='-1'){
                $(this).show('Bitte wählen Block',$('#ddlProduct'));
                return;  
            }
        }
            
        if($('#cuCheckbox').attr('checked')&&$('#txtAmount').val()==""){
            $('#txtAmount').show('Bitte geben Sie Curstomer Amount',$('#txtAmount'));
            return;
        }
        
         if($('#cuCheckbox').attr('checked')&&$('#txtAmount').val()=="0"){
            $('#txtAmount').show('Bitte geben Sie Curstomer Amount',$('#txtAmount'));
            return;
         }
         
         if($('#cuCheckbox').attr('checked')&&parseInt($('#txtAmount').val())<mingoldnumber){
             $('#txtAmount').show('Der kleinste Betrag Ihres Einkaufs wird '+mingoldnumber,$('#txtAmount'));
            return;
         }
         
         if($('#txtcredit').checkNotNull()){
             if($('#txtcredit').checkDouble()){
                if(parseFloat($('#txtcredit').val())>parseFloat($('#cu_credit span').text().substring(1)))
                $('#txtcredit').val($('#cu_credit span').text().substring(1));
            }else{
                $('#txtcredit').show('Feedback Info Type Error!',$('#txtcredit'));
                return;
            }
         }
            
        if($('#put input').attr('checked')){
            if($('#txtactname').val()==""){
                $('#txtactname').show('Bitte Account Name',$('#txtactname'));
                return;
            }
            if($('#txtactpwd').val()==""){
                $('#txtactpwd').show('Bitte Kennwort für das Konto',$('#txtactpwd'));
                return;
            }
        }

        if($('#txtcharname').checkNull()){
            $(this).show('Bitte geben Sie Ihre Character Name',$('#txtcharname'));
            return;
        }
        
        if($('#txtfullname').checkNull()){
            $(this).show('Bitte geben Sie Vor-und Zuname',$('#txtfullname'));
            return;
        }
            
        if($('#txtemail').checkNull()||$('#txtemail').checkEmail()){
            $(this).show('Geben Sie bitte Ihre E-Mail',$('#txtemail'));
            return;
        }
            
       //电话号码检测
       var _tempPhone="";
       $('#usphone input').each(function(){
            if($(this).val()!=""){
                _tempPhone+=$(this).val();
            }
            else{
                _tempPhone="";
                return false;   
            }
       })
       if(_tempPhone==""&&$('#txtnonusphone').checkNull()){
            $(this).show('Bitte geben Sie Ihre Telefonnummer',$('#usphone input:eq(0)'));
            return;
       }
       
       $('#input_error').text('');
       
        
        /***************取值提交***************/

        var curAmount='0';
        var curPrice='0';
        var tradeAddress="0";
        var usPhone='';
        var saleBlockID=0;
        var _maxUseCre='false';


        if($('#cuCheckbox').attr('checked')){
           if($('#txtAmount').checkNotNull()){
                curAmount=$('#txtAmount').val();
           }
           if($('#txtPrice').checkNotNull())
                curPrice=$('#txtPrice').val();
        }else{
            saleBlockID=$('#ddlProduct').val();
        }
        
        if($('#face input').attr('checked')){
            tradeAddress=$('#tradeaddress').val();
        }
        
        $('#usphone input').each(function(){
            if($(this).val()!=""){
                usPhone+="-"+$(this).val();
            }else{
                usPhone='';
                return false;
            }
        })
        
        if($('#cu_credit span:eq(1)').text()!=''&&$('#cu_credit span:eq(1)').text().substring(1)==$('#txtcredit').val()){
            _maxUseCre='true';
        }
        
        editalt(1);
        
        var orderInfo={
            gameID:$('#ddlGame').val(),
            serverID:$('#ddlServer').val(),
            saleBlockID:saleBlockID,
            curType:curType,
            curAmount:curAmount,
            curPrice:curPrice,
            couponCode:$('#txtCoupon').val(),
            tradeMode:$('.gold_b4R input:checked').val(),//?
            tradeAddress:tradeAddress,
            charName:$('#txtcharname').val(),
            fullName:$('#txtfullname').val(),
            email:$('#txtemail').val(),
            usPhone:usPhone!=''?usPhone.substring(1):'',
            nonUSPhone:$('#txtnonusphone').val(),
            actName:$('#txtactname').val(),
            actPwd:$('#txtactpwd').val(),
            credit:$('#txtcredit').val()==""?"0":$('#txtcredit').val(),
            payMethod:$('.gai_ln input:checked').val(),
            maxUseCredit:_maxUseCre
        }
        creditSubmitDiv();
        $(this).ajaxOrder(orderInfo);//下单
        
    })
}

function  ShowKey(gamemid)
{
     if(gamemid==8 || gamemid==9)
        return true;
     else
        return false;
}
function fontColorClear(addobj){
    $('.gold_bord:eq(0) a').removeClass('gold_red');
    $('.gold_bord:eq(0) a').css('color','#fff');
    addobj.addClass('gold_red');
    addobj.css('color','#F1FF00');
}

function moneyColorClear(num){
    $('.gold_bord:eq(1) span').removeClass('gold_red');
    $('.gold_bord:eq(1) span').css('color','#fff');
    $('.gold_bord:eq(1) span:eq('+num+')').addClass('gold_red');
    $('.gold_bord:eq(1) span:eq('+num+')').css('color','#F1FF00');
}

function curAmountByCmd(cmd){
    if(cmd==1){
        $('#curAmount').css('display','block');
        $('#curAmount1').css('display','block');
    }else{
        $('#curAmount').css('display','none');
        $('#curAmount1').css('display','none');
    }
}

function clearMoney(){
    $('.gold_bord:eq(1) span').each(function(){
        $(this).text($(this).text().substring(0,1)+"0.00");
    })
}

function curCreditByCmd(cmd){
    if(cmd==1){
        $('#cu_credit').css('display','block');
        $('#cu_credit1').css('display','block');
    }else{
        $('#cu_credit').css('display','none');
        $('#cu_credit1').css('display','none');
    }
}

function actByCmd(cmd){
     if(cmd==1){
        $('#txtActName').css('display','block');
        $('#txtActPwd').css('display','block');
    }else{
        $('#txtActName').css('display','none');
        $('#txtActPwd').css('display','none');
    }
}

//处理交易模式相关
function disposeTradeMode(result){
    tradeModeByCmd(0);//隐掉trademode
    var _result=result.split("~");
    if(_result[0]=='0'){
        tradeModeByCmd(2,$('#face'),'0');
        $('#tradeaddress').html(_result[2]);
        if(_result[1]=="true")
            tradeModeByCmd(2,$('#put'),'0');
    }else if(_result[0]=='1'){
        tradeModeByCmd(2,$('#sendmail'),'1');
        if(_result[1]=="true")
            tradeModeByCmd(2,$('#put'),'1');
    }else{
       tradeModeByCmd(2,$('#face'),'');
       $('#tradeaddress').html(_result[2]);
       tradeModeByCmd(1);
      if(_result[1]=="false")
         $('#put').css('display','none');
        else 
        $('#put').css('display','block'); 
    }
}

function tradeModeByCmd(cmd,obj,val){
     if(cmd==1){
        $('#face').css('display','block');
        $('#put').css('display','block');
        $('#sendmail').css('display','block');
        $(".gold_b4R input[name='rad_trade']").val(['0']);
     }else if(cmd==0){
        $('#face').css('display','none');
        $('#put').css('display','none');
        $('#sendmail').css('display','none');
     }else if(cmd==2){
        obj.css('display','block');
        $(".gold_b4R input[name='rad_trade']").val([val]);
     }  
}


function creditSubmitDiv(){
    var sdiv=document.createElement("div");
    sdiv.setAttribute("id","sdiv");
    sdiv.className="submittrans";
    sdiv.style.zIndex="99";
    
    var waitmain=document.createElement("div");
    waitmain.className="submitimg";
    waitmain.style.zIndex="98";
    
    var waitimg=document.createElement("img");
    waitimg.style.zIndex="97";
    waitimg.src="http://vcsale.21cge.com/images/process.gif";
    
    
    waitmain.appendChild(waitimg);
    document.body.appendChild(sdiv);
    
    sdiv.appendChild(waitmain);
    
    $("#sdiv").css("height",$(document.html).height());
    $(".submitimg").css("margin-top",(parseInt($(document.html).height())/2.8)+"px")
}

function bindBlockList_Event(){
    $('.gold_bL div:eq(1)  li').click(function(){
        $('.gold_bL div:eq(1)  li').removeClass('gold_02');
        $('.gold_bL div:eq(1)  li').addClass('gold_01');
        $(this).addClass('gold_02');
        $('#ddlProduct').attr('value',$(this).attr('id'));
        $('.gold_bord:eq(1) span:eq(0)').text($(this).children('div:eq(2)').attr('id'));
        $('.gold_bord:eq(1) span:eq(1)').text($('#blockdataeur li[id='+$(this).attr('id')+']').children('div:eq(2)').text());
        $('.gold_bord:eq(1) span:eq(2)').text($('#blockdatagbp li[id='+$(this).attr('id')+']').children('div:eq(2)').text());
        editalt(0);
    })
    $('.gold_bL div:eq(1) li').hover(
        function(){
            $(this).removeClass('gold_01');
            $(this).addClass('gold_02');
        },function(){
            if($(this).attr('id')!=$('#ddlProduct').val()){
                $(this).removeClass('gold_02');
                $(this).addClass('gold_01');
            }                
        })
    $('.gold_bL div:eq(1) li[id='+$('#ddlProduct').val()+']').toggleClass('gold_02');
    $('.gold_bL div:eq(1)  li').css('cursor','pointer');
}

//初始货币类型，联动对象，blocklist,当前货币,币种,点数
function loadDefaultCurType(){
    if(curType=='1'){
        //gbp
       $('.gold_bL div:eq(1) ul').html($('#blockdatagbp').html());//加载en
       if(credit!="0")
            $('#cu_credit span:eq(1)').text("£"+(formatFloat(credit/rates.GBP_Rate,2)));
       fontColorClear($('#a_GBP'));
       moneyColorClear(2);//设置当前货币
    }else if(curType=='2'){
        //eur
       $('.gold_bL div:eq(1) ul').html($('#blockdataeur').html());//加载eur
       if(credit!="0")
            $('#cu_credit span:eq(1)').text("€"+(formatFloat(credit/rates.EUR_Rate,2)));
       fontColorClear($('#a_EUR'));
       moneyColorClear(1);//设置当前货币
       $('.gold_bL div:eq(1) ul li[id='+$('#ddlProduct').val()+']').addClass('gold_02');//选中当前block
    }else if(curType=='0'){
        //usd默认
        $('.gold_bL div:eq(1) ul').html($('#blockdataen').html());//加载usd
        if(credit!="0")
            $('#cu_credit span:eq(1)').text("$"+credit);
        fontColorClear($('#a_USD'));
        moneyColorClear(0);//设置当前货币
    }
    $('.gold_bL div:eq(1) ul li[id='+$('#ddlProduct').val()+']').addClass('gold_02');//选中当前block
    $('.gold_bord:eq(1) span:eq(0)').text($('.gold_bL div:eq(1) ul li[id='+$('#ddlProduct').val()+']').children('div:eq(2)').attr('id'));
    $('.gold_bord:eq(1) span:eq(1)').text($('#blockdataeur li[id='+$('#ddlProduct').val()+']').children('div:eq(2)').text());
    $('.gold_bord:eq(1) span:eq(2)').text($('#blockdatagbp li[id='+$('#ddlProduct').val()+']').children('div:eq(2)').text());//设置货币数量
}

function loadBlockListByCurType(){
    switch(curType){
        case "0":
            $('.gold_bL div:eq(1) ul').html($('#blockdataen').html());//加载usd
            break;
        case "1":
            $('.gold_bL div:eq(1) ul').html($('#blockdatagbp').html());//加载gbp
            break;
        case "2":
            $('.gold_bL div:eq(1) ul').html($('#blockdataeur').html());//加载eur
            break;
    }
    
    var goldinitheight=68;//px单位
    var goldheight=190;//初始高度
    var goldborderheight=150;//初始金币档次高度
    var lisize=$('.gold_bL div:eq(1) ul li').size();
    if(lisize/4>Math.floor(lisize/4)){
        goldheight+=68*((lisize/4)+1);
        goldborderheight+=68*((lisize/4)+1);
    }else{
        goldheight+=68*(lisize/4);
        goldborderheight+=68*(lisize/4);
    }
    $('.gold_b03').css({height:goldheight+'px'});
    $('.buygoldleft_nobg').css({height:goldborderheight+'px'});
    $('.buygoldleft_nobg ul').css({height:goldborderheight+'px'});
}

//vcsale操作提示
function editalt(now){
    $('.goldtoptitle ul li').css({color:"yellow"});
    $('.goldtoptitle ul li:eq('+now+')').css({color:"#fff"});
}

//计算自定义数量价格
function calccustomerprice(){
        if($('#ddlGame').val()=='-1'){
            $(this).show('Bitte wählen Game',$('#ddlGame'));
            return;
        }
        if($('#ddlServer').val()=='-1'){
             $(this).show('Bitte wählen Server',$('#ddlServer'));
            return;
        }
        if($('#txtAmount').checkNum()){
            $('#txtPrice').val('');
            return;
        }else if(parseInt($('#txtAmount').val())<mingoldnumber){
            $('#txtPrice').val('');           
        }else{
               var _curType;
               $('.gold_bord:eq(0) a').each(function(){
                    if($(this).attr('class')=='gold_red'){
                        if($(this).text()=="USD")
                            _curType="0";
                        else if($(this).text()=="GBP")
                            _curType="1";
                        else
                            _curType="2";
                    }
               })
                $('#txtAmount').getPrice({
                    gameID:$('#ddlGame').val(),
                    serverID:$('#ddlServer').val(),
                    amount:$('#txtAmount').val(),
                    curType:_curType
                })
        }
}


function productchange(){
        if($("#ddlProduct").val()!='-1'){
            $('.gold_bL div:eq(1)  li').removeClass('gold_02');
            $('.gold_bL div:eq(1)  li').addClass('gold_01');
            $('.gold_bL div:eq(1) ul li[id='+$("#ddlProduct").val()+']').addClass('gold_02');
            $('.gold_bord:eq(1) span:eq(0)').text($('.gold_bL div:eq(1) ul li[id='+$("#ddlProduct").val()+']').children('div:eq(2)').attr('id'));
            $('.gold_bord:eq(1) span:eq(1)').html($('#blockdataeur li[id='+$("#ddlProduct").val()+']').children('div:eq(2)').text());
            $('.gold_bord:eq(1) span:eq(2)').text($('#blockdatagbp li[id='+$("#ddlProduct").val()+']').children('div:eq(2)').text());
        }else{
           loadDefaultCurType();
           bindBlockList_Event();
           clearMoney();
        }
        editalt(0);
}


function clearMoney(){
    $('.gold_bord:eq(1) span').each(function(){
        if(parseInt($(this).text().substring(1))>0||$(this).checkNull())
            $(this).text($(this).text().substring(0,1)+"0.00");
    })
}

function objectloading_select(obj){
    obj.html('<option value="-1">--Laden--</option>');
}
function objectchoose_select(obj){
    obj.html('<option value="-1">--Wählen--</option>');
}
function objecton_select(obj){
    obj.attr("disabled",'');
}
function objectoff_select(obj){
    obj.attr("disabled","false");
}

function loadserver(gameid){
    if(gameid=="-1"){
        objectchoose_select($("#ddlServer"));
        objectchoose_select($("#ddlProduct"));
        objectoff_select($("#ddlServer"));
        objectoff_select($("#ddlProduct"));
        restorestate();
        
    }else{
        objectloading_select($("#ddlServer"));
        objectchoose_select($("#ddlProduct"));
        objecton_select($("#ddlServer"));
        objectoff_select($("#ddlProduct"));
    }
}

function loadproducts(serverid){
    if(serverid=="-1"){
        objectchoose_select($("#ddlProduct"));
        objectoff_select($("#ddlProduct"));
        clearMoney();
        restorestate();
        
    }else{
        objectloading_select($("#ddlProduct"));
        objecton_select($("#ddlProduct"));
    }
}

function restorestate(){
     $('.gold_bL div:eq(1)').removeClass('buygoldleft');
     $('.gold_bL div:eq(1)').addClass('buygoldleft_nobg');
     $('.gold_bL div:eq(1) ul').html("");
     $('#blockdataen').html("");
     $('#blockdatagbp').html("");
     $('#blockdataeur').html("");
}



