﻿ var tbl_hand="<table  id='table_gold_list' class='table_gold_list' border='0' cellpadding='0' cellspacing='0'><tbody><tr><th>NAME</th><th>TOTAL</th></tr>";
     var tbl_body="";   
	 var tbl_foot="</tbody></table>";
	 var tag=1;
	 var dataGold;
	 var moneyType="USD";
	        function queryGameProduct(g){
	         $('#div_wait').show();
	         if(g.value=="0"){
	             $('#div_wait').hide();return;
	         }
	         document.getElementById("h_gameserver").value=g.options[g.selectedIndex].text;
	        var gameserver = g.value;
	                	        
	         var selproduct = document.getElementById("ddlProduct");
	         
	             $.ajax({
	                url : '/ajax/GameProducts.ashx',
	                type : 'post',
	                data : 'gameserver='+gameserver+"&product=0",
	                dataType : 'html',
	                success : function(html){	
	                    dataGold=html;            
	                    var productList = html.split('|');	                    
	                    var productitem;	    
	                    var USD="";
	                    selproduct.options.length=0;
	                    for(var i=0;i<productList.length;i++){
	                        productitem = productList[i].split('@');
	                        for(var j=0;j<productitem.length-2;j++){	
	                         
	                          if(USD==""){
	                            var p = productitem[2].split('^');
	                                USD=p[0];
	                                
	                              document.getElementById("b_Price").value=USD;
	                              document.getElementById("h_price").value=USD;     
	                              document.getElementById("h_moneyType").value='USD';
	                              setMoneycolor('USD');
	                              document.getElementById("h_productName").value=productitem[1];  
	                                                 
	                          }
	                            selproduct.options.add(new Option(productitem[1],productitem[0]+"^"+productitem[2]));
	                        }
	                    } 
	                    UintGoldList(moneyType);
	                    $('#div_wait').hide();
	                }
	            });
	        } 
	         
	        function UintGoldList(moneyType){
	            $('#div_wait').show();
	            var objTable=document.getElementById( "div1" ); 	
	            tbl_body="";
	            var productlist = dataGold.split('|');
	            var price;
	            var productitem;
	            var p;
	            
	            for(var i=0;i<productlist.length;i++){
	                productitem = productlist[i].split('@');
	                p = productitem[2].split('^');
	                switch(moneyType){
	                    case 'USD':
	                        price=p[0];break;
	                    case 'EUR':
	                        price=p[1];break;
	                    case 'GBP':
	                        price=p[2];
	                 }
	                 if((tag%2)==0){
	                tbl_body+="<tr onmouseover=\"javascript:this.bgColor='#580004'\" onclick=\"queryPrice1('"+price+"','"+productitem[1]+"','"+productitem[0]+"^"+productitem[2]+"');\" onmouseout=\"javascript:this.bgColor=''\"><td style=\"height: 17px\">"+productitem[1]+"</td><td style=\"height: 17px\">"+price+"</td></tr>";
	            }else{
	                tbl_body+="<tr onmouseover=\"javascript:this.bgColor='#580004'\" onclick=\"queryPrice1('"+price+"','"+productitem[1]+"','"+productitem[0]+"^"+productitem[2]+"');\" onmouseout=\"javascript:this.bgColor='#000'\" bgcolor=\"#000000\"><td style=\"height: 17px\">"+productitem[1]+"</td><td style=\"height: 17px\">"+price+"</td></tr>";
	            } 
	            tag++;
	             }	      	            
	            objTable.innerHTML=tbl_hand+tbl_body+tbl_foot;  
	            $('#div_wait').hide();
	        }
       
	        function queryPrice(p){
	            var price = p.value.split('^');
	            
	            document.getElementById("b_Price").value=price[1];
	            document.getElementById("h_price").value=price[1]; 
	            document.getElementById("h_moneyType").value='USD';
	            setMoneycolor('USD');
	            document.getElementById("h_productName").value=p.options[p.selectedIndex].text;   
	        }
	        
	        function queryPrice1(p,productName,guid){	                
	            var moneyType='$';
	            var moneyType1='USD';
	            var price = p.substr(1);
	            var selproduct = document.getElementById("ddlProduct");
	            moneyType = p.substr(0,1);
	            
	            document.getElementById("b_Price").value=moneyType+price;
	            document.getElementById("h_price").value=moneyType+price; 
	            
	            switch(moneyType){
	                    case '$':
	                        moneyType1='USD';break;
	                    case '€':
	                        moneyType1='EUR';break;
	                    case '£':
	                        moneyType1='GBP';
	                 }
	            setMoneycolor(moneyType1)
	            document.getElementById("h_moneyType").value=moneyType1;
	            document.getElementById("h_productName").value=productName;
	            selproduct.value=guid;
	        }
	        
	        function getMoney(type){
	            var product = document.getElementById("ddlProduct");
	            if(product.options[product.selectedIndex].text=="-Choose-"||product.options[product.selectedIndex].text==""){
	                return;
	            }
	            var p = product.value.split('^');	
	            
	            var price;   
	            switch(type){
	                case 'USD':
	                    price=p[1];break;
	                case 'EUR':
	                    price=p[2];break;
	                case 'GBP':
	                    price=p[3]; 
	            } 
	            UintGoldList(type);           
	              
	            setMoneycolor(type);
                document.getElementById("b_Price").value=price;
                document.getElementById("h_price").value=price;    
                document.getElementById("h_moneyType").value=type;   
                document.getElementById("h_productName").value=product.options[product.selectedIndex].text; 
	        }
	        //设置选中货币类型的颜色
	        function setMoneycolor(type){
	            document.getElementById("USD").style.color='';
	            document.getElementById("EUR").style.color='';
	            document.getElementById("GBP").style.color='';
	            document.getElementById(type).style.color='yellow';
	        }
	        
	       ///验证优惠券
	       function CheckCoupon(){    
            var success = "<img src=\"/images/yes.gif\" alt=\"\" >";
            var failure = "<img src=\"/images/no.gif\" alt=\"\" >";
            var info = "<img src=\"/images/process.gif\" alt=\"Load...\" style=\"width:30px;height:30px;\" >";
            var cou = $("#txtCouponCode").val();
            if(cou.length>0){
               $("#lblcoupon").html(info);
               $.ajax({
                    url : '/ajax/CheckCoupon.ashx',
                    type : 'post',
                    data : 'operate=gold&val='+cou,
                    dataType : 'html',
                    success : function(html){
                        if(html=="false"){
                             $("#lblcoupon").html(failure);
                        }
                        if(html=="true"){
                            $("#lblcoupon").html(success);
                        }
                    }
               });        
            }else{
               $("#lblcoupon").html(failure);
            }
           }