﻿// JavaScript Document
$i=function(id){return document.getElementById(id)}
//var default_Type="USD";
var subMitMehtod=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){
		
		$i(id).value=val;
	}
	this.SetPrice=function(Realm,Server,Amount,Currency){ 
		
		if($i(Server).value==""){
			this.UnitPrice=0;
			this.TotalPrice=0;
			return;
		}
		if(!$i(Currency)){
			TypeName=default_Type;
		}else{
			TypeName=$i(Currency).value	
		}
		
		if(!$i(Realm)){
			ParentServer=1;	
		}else{
			ParentServer=$i(Realm).value;
		}
			this.UnitPrice=(GoldPrice[ParentServer][$i(Server).value]*PriceFitsArray[TypeName][1]).toFixed(5);
			
			this.TotalPrice=(GoldPrice[ParentServer][$i(Server).value]*PriceFitsArray[TypeName][1]*$i(Amount).value).toFixed(2);
			
			this.PriceType=PriceFitsArray[TypeName][0];
			
			if(beat==true){
				var 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($i(Amount).value);
				this.TotalPrice=((1-(Amount/Min)*((1-beat_num)/(Max/Min)))*this.TotalPrice).toFixed(2);
				
			}
	}
}

function SubMitCheck(Method){
	this.SubmitMethod=Method;
	this.GameName="focus";
	this.SiteName="www.dofusbuy.fr";
	if(!$i("LarCode")){
		servername =this.GameName;	
	}else{
		servername = RealmArray[$i("LarCode").value][1];
	}
		if(this.SubmitMethod==false || this.SubmitMethod==null){
			this.check=function(){
			
				if($i("TotalPrice").value=="" || $i("TotalPrice").value==0){
					alert('Enter Price!');
					//alert("fhw dw");fhqdw
					return false;
				}
				if($i("CharactorName").value==''){
					alert('Enter Character!');
					$i("CharactorName").focus();
					return false;
				}
				$i("item_name").value = this.SiteName+"|"+servername+"|"+ServerArray[$i("LarCode").value][$i("Server").value]+"|gold|"+$i("Num").value;
		   
		   
				$i("amount").value=$i("TotalPrice").value;
		   
				$i("item_number").value=$i("CharactorName").value+"|0|0";
				
				if($i('PriceType')){
					$i("currency_code").value=$i('PriceType').value.toUpperCase();	
				}else{
					$i("currency_code").value=default_Type;
				}
		   
				$i("checkout_confirmation").submit();
		   		return false;
			//////////
			}
		}else{
			
			this.check=function(){
				if($i("TotalPrice").value=="" || $i("TotalPrice").value==0){
					alert('Enter Price!');
					return false;
				}
				if($i("CharactorName").value==''){
					alert('Enter Character!');
					$i("CharactorName").focus();
					return false;
				}
				var p=document.forms["ppform"];
				p.item_name1.value=this.SiteName+'|'+servername+"|"+$i("Server").options[$i("Server").selectedIndex].text+"|gold|"+$i("Num").value;
				
				p.amount1.value=parseFloat($i("TotalPrice").value);
				
				p.item_number1.value=$i("CharactorName").value+"|0|0";
				
				p.quantity1.value=1;
				
				p.price_unit.value=$i("UnitPrice").value;
				
				p.price_total.value=$i("TotalPrice").value;
				
				p.item_quantity.value=$i("Num").value;
				
				p.server_name.value=$i("Server").options[$i("Server").selectedIndex].text;
				
				p.character2.value=$i("CharactorName").value;
				
				if($i('PriceType')){
					p.currency_code1.value=$i('PriceType').value.toUpperCase();	
				}else{
					p.currency_code1.value=default_Type;
				}
				p.submit();
			}	
		}
}


function leveling_class(gameserver,slevel,elevel){  
	if(!$i(gameserver)){
		gameserver=1;	
	}else{
		gameserver=parseInt($i(gameserver).value);	
	}
 	startlevel =  parseInt($i(slevel).value) ;
    endlevel =  parseInt($i(elevel).value);
    if(endlevel > startlevel){
      var money = 0; var time = 0; 
      var  it = RealmLeveArray[gameserver]['it'];
      var pri = RealmLeveArray[gameserver]['pri'];
	  if(endlevel <= 10 ){
          money = pri[0]; time = it[0];  	
      }else{
         if(startlevel < 10 ){
	        for(i = 11 ;i <= endlevel ;i ++){
		       a = i - 10;	
			   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 - 10 ;
		       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{
 	  $i(elevel).focus();
	  this.pri_gbp = "0.00" ;
	  this.pri_usd = "0.00";
	  this.time = "";
	}
}

function leveling_submit(method){
	this.SubmitMethod=method;
	this.GameName="focus";
	this.SiteName="www.dofusbuy.fr";
	if(!$i("LarCode_e")){
		servername1 =this.GameName;	
	}else{
		servername1 = RealmArray[$i("LarCode_e").value][1];
	}
	this.PaySubMit=function(){
		
    	this.server_name = $i("Server_e").options[$i("Server_e").selectedIndex].text;	
		$i("os0").value =servername1+"--"+this.server_name+"--"+$i("slevel").value+"--"+$i("elevel").value+"--"+$i("Time").value;
    	
 		document.getElementById("item_name").value = this.SiteName+"|"+servername1+"|"+this.server_name+"|pl|1";
 		 $i("item_number").value=$i("CharactorName_e").value+"|"+$i("UserName").value+"|"+$i("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;
			}
		}
		 $i("currency_code").value=Price_e;
		 $i("amount").value = $i(Price_e).value;
		 $i("os1").value=$i("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){
		$i("pri_usd").value=PriceFitsArray["USD"][1];
		$i("pri_gbp").value=PriceFitsArray["GBP"][1];
		$i("pri_eur").value=PriceFitsArray["EUR"][1];
	}
		switch(method){
			case "1":
				this.PaySubMit();
				break;
			case "3":
				$i("pl_LarCode").value=servername1;
				$i("pl_Server").value=$i("Server_e").options[$i("Server_e").selectedIndex].text;
				$i("pl_form").action="confirm_sell/payment_eu.php?action=pl";
				$i("pl_form").submit();
			case "4":
				$i("pl_LarCode").value=servername1;
				$i("pl_Server").value=$i("Server_e").options[$i("Server_e").selectedIndex].text;
				$i("pl_form").action="confirm_sell/payment_eu.php?action=pl";
				$i("pl_form").submit();
		}
	}
}

}
