﻿// JavaScript Document
$=function(id){return document.getElementById(id)}
var default_Type="USD";///定义一个默认的货币类型
var subMitMehtod=true; //true多方式 提交  false单一提交 (非金币购买时的设置)
var beat=true;//是否打折
//////////////////////////*************
function Gold_Class(){
	this.TotalPrice=0.00;//总价
	this.UnitPrice=0.00;//单价
	this.PriceType=PriceFitsArray[default_Type][0];//符号
	this.SetVal=function(id,val){
		////id号  与val值
		$(id).value=val;
	}
	this.SetPrice=function(Realm,Server,Amount,Currency){
		////Realm服务区,Server服务器,Amount数量,Currency货币类型
		if($(Server).value==""){
			this.UnitPrice=0;
			this.TotalPrice=0;
			return;
		}
		if(!$(Currency)){
			TypeName=default_Type;
		}else{
			TypeName=$(Currency).value	
		}
		
		if(!$(Realm)){
			ParentServer=1;	
		}else{
			ParentServer=$(Realm).value;
		}
			this.UnitPrice=(GoldPrice[ParentServer][$(Server).value]*PriceFitsArray[TypeName][1]).toFixed(2);
			
			this.TotalPrice=(GoldPrice[ParentServer][$(Server).value]*PriceFitsArray[TypeName][1]*$(Amount).value).toFixed(2);
			
			this.PriceType=PriceFitsArray[TypeName][0];
			
			if(beat==true){
				i=0
				for(var kk in NumberArray[ParentServer]){
					if(i==0){
						bb=kk;	
					}
					var aa=kk;
					i++;
				}
				var Max=parseInt(aa);
				var Min=parseInt(bb);
				var Amount=parseFloat($(Amount).value);
				this.TotalPrice=((1-(Amount/Min)*((1-beat_num)/(Max/Min)))*this.TotalPrice).toFixed(2);
				
			}
	}
}
///////************************************************

////提交类//////////////////////
function SubMitCheck(Method){
	this.SubmitMethod=Method;//false单一的Paypal提交,如果为true则增加德国银行
	this.GameName="focus";//定义一个游戏名
	this.SiteName="www.dofusbuy.fr";//定义一个网站名
	if(!$("LarCode")){
		servername =this.GameName;	
	}else{
		servername = RealmArray[$("LarCode").value][1];
	}
		if(this.SubmitMethod==false || this.SubmitMethod==null){
			this.check=function(){
			/////////////paypal提交
				if($("TotalPrice").value=="" || $("TotalPrice").value==0){
					alert('Enter Price!');
					return false;
				}
				if($("CharactorName").value==''){
					alert('Enter Character!');
					$("CharactorName").focus();
					return false;
				}
				$("item_name").value = this.SiteName+"|"+servername+"|"+ServerArray[$("LarCode").value][$("Server").value]+"|gold|"+$("Num").value;
		   
		   
				$("amount").value=$("TotalPrice").value;
		   
				$("item_number").value=$("CharactorName").value+"|0|0";
				
				if($('PriceType')){
					$("currency_code").value=$('PriceType').value.toUpperCase();	
				}else{
					$("currency_code").value=default_Type;
				}
		   
				$("checkout_confirmation").submit();
		   		return false;
			//////////
			}
		}else{
			//////////多方式提交
			this.check=function(){
				if($("TotalPrice").value=="" || $("TotalPrice").value==0){
					alert('Enter Price!');
					return false;
				}
				if($("CharactorName").value==''){
					alert('Enter Character!');
					$("CharactorName").focus();
					return false;
				}
				var p=document.forms["ppform"];
				p.item_name1.value=this.SiteName+'|'+servername+"|"+$("Server").options[$("Server").selectedIndex].text+"|gold|"+$("Num").value;
				
				p.amount1.value=parseFloat($("TotalPrice").value);
				
				p.item_number1.value=$("CharactorName").value+"|0|0";
				
				p.quantity1.value=1;
				
				p.price_unit.value=$("UnitPrice").value;
				
				p.price_total.value=$("TotalPrice").value;
				
				p.item_quantity.value=$("Num").value;
				
				p.server_name.value=$("Server").options[$("Server").selectedIndex].text;
				
				p.character2.value=$("CharactorName").value;
				
				if($('PriceType')){
					p.currency_code1.value=$('PriceType').value.toUpperCase();	
				}else{
					p.currency_code1.value=default_Type;
				}
				p.submit();
			}	
		}
}

/////////////////////////////////////////////////////////////////////////////////

//代练类
function leveling_class(gameserver,slevel,elevel){   ////加一个参数server判断它的服务器
	if(!$(gameserver)){
		gameserver=1;	
	}else{
		gameserver=parseInt($(gameserver).value);	
	}
 	startlevel =  parseInt($(slevel).value) ;
    endlevel =  parseInt($(elevel).value);
    if(endlevel > startlevel){
      var money = 0; var time = 0; 
      var  it = RealmLeveArray[gameserver]['it'];
      var pri = RealmLeveArray[gameserver]['pri'];
      if(endlevel <= 20 ){
          money = pri[0]; time = it[0];  	
      }else{
         if(startlevel < 20 ){
	        for(i = 21 ;i <= endlevel ;i ++){
		       a = i - 20;	
			   money = money + pri[a];	
			   time = time + it[a];
		    }    
	     money = money + pri[0];
		 time = time + it[0];
        }else{
	        for(i = startlevel ;i < endlevel ;i ++){
		       a = i - 20 ;
		       time = time + it[a+1];
			   money = money + pri[a+1];
		    }
	    }
      }
      this.time = (Math.round(time * 100 ) / 100).toFixed(2);
      this.pri_usd = (Math.round(money * 100 )/ 100).toFixed(2);
      this.pri_gbp = (Math.round(money * 100 ) / 100 * PriceFitsArray['GBP'][1]).toFixed(2);
    }else{
 	  $(elevel).focus();
	  this.pri_gbp = "0.00" ;
	  this.pri_usd = "0.00";
	  this.time = "";
	}
}
////////////另一种算法   计算出总时间time   mony=time×0.65 些时只需要一个it数组
/*
var  it = new Array("6","2","2","2","2","2","2","3","3","3","3","3","3","3","3","3","3","3","3","3","3","2","2","2","3","3","3","3","4","4","4","3","3","4","4","4","4","4","4","5","5","5","5","5","5","5","5","6","6","6","6","14","14","16","16","16","18","18","22","22","24")
	if(endlevel <= 10 ){ 
		money = parseFloat(it[0]); 
		time = money;
	}else{
		if(startlevel < 10 ){
		for(i = 11 ;i <= endlevel ;i ++){
			a = i - 10;	money = money + parseFloat(it[a]);
		}    
			money = money + parseFloat(it[0]);
		}else{
			for(i = startlevel ;i < endlevel ;i ++)	{
				a = i - 10 ;	money = money + parseFloat(it[a+1]);
			}
		}		
} 
		this.time = (Math.round(money * 100 ) / 100).toFixed(2);  							        this.pri_usd = (Math.round(money * 100 * 0.65)/ 100).toFixed(2);        
		this.pri_gbp = (Math.round(money * 100 * 0.65) / 100/1.98).toFixed(2);
		
*/



/////////////////////////////////////
////代练提交类
function leveling_submit(method){
	this.SubmitMethod=method;//false单一的Paypal提交,如果为true则增加德国银行
	this.GameName="focus";//定义一个游戏名
	this.SiteName="www.dofusbuy.fr";//定义一个网站名
	if(!$("LarCode_e")){
		servername1 =this.GameName;	
	}else{
		servername1 = RealmArray[$("LarCode_e").value][1];
	}
	this.PaySubMit=function(){
		//////默认paypal提交
    	this.server_name = $("Server_e").options[$("Server_e").selectedIndex].text;	
		$("os0").value =servername1+"--"+this.server_name+"--"+$("slevel").value+"--"+$("elevel").value+"--"+$("Time").value;
    	
 		document.getElementById("item_name").value = this.SiteName+"|"+servername1+"|"+this.server_name+"|pl|1";
 		 $("item_number").value=$("CharactorName_e").value+"|"+$("UserName").value+"|"+$("PassWord").value;
		 var Price_e = document.getElementsByName('Price_e');
			for(var i=0;i<Price_e.length;i++){
				if(Price_e[i].checked){
					Price_e=Price_e[i].value;
				break;
			}
		}
		 $("currency_code").value=Price_e;
		 $("amount").value = $(Price_e).value;
		 $("os1").value=$("Notice").value;
    	 document.getElementById("checkout_confirmation").submit();
 		 return false;
	}
if(this.SubmitMethod==false || this.SubmitMethod==null){
	this.CheckSubMit=function(){
		this.PaySubMit();
	}
}else{
	///////////////多方式提交
	this.CheckSubMit=function(){
	var method = document.getElementsByName('payment');
	for(var i=0;i<method.length;i++){
		if(method[i].checked){
			method=method[i].value;
			break;
		}
	}
	if(method==3 || method==4){
		$("pri_usd").value=PriceFitsArray["USD"][1];
		$("pri_gbp").value=PriceFitsArray["GBP"][1];
		$("pri_eur").value=PriceFitsArray["EUR"][1];
	}
		switch(method){
			case "1":
				this.PaySubMit();
				break;
			case "3":
				$("pl_LarCode").value=servername1;
				$("pl_Server").value=$("Server_e").options[$("Server_e").selectedIndex].text;
				$("pl_form").action="confirm_sell/payment_eu.php?action=pl";
				$("pl_form").submit();
			case "4":
				$("pl_LarCode").value=servername1;
				$("pl_Server").value=$("Server_e").options[$("Server_e").selectedIndex].text;
				$("pl_form").action="confirm_sell/payment_eu.php?action=pl";
				$("pl_form").submit();
		}
	}
}

}
