﻿// JavaScript Document

$=function(id){return document.getElementById(id)}
//var default_Type="EUR";
var subMitMehtod=true; 
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).value=val;
	}
	this.SetPrice=function(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(5);
			this.TotalPrice=(GoldPrice[ParentServer][$(Server).value]*PriceFitsArray[TypeName][1]*$(Amount).value);
			
			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);
				this.UnitPrice=(((1-(Amount/Min)*((1-beat_num)/(Max/Min)))*this.TotalPrice)/Amount).toFixed(5);
			}
	}
}

function pro_Gold_Class(){
	//alert('111');
	this.TotalPrice=0.00;
	this.UnitPrice=0.00;
	this.PriceType=PriceFitsArray[default_Type][0];
	this.SetVal=function(id,val){
		$(id).value=val;
	}
	this.SetPrice=function(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=(pro_GoldPrice[ParentServer][$(Server).value]*PriceFitsArray[TypeName][1]).toFixed(5);
			this.TotalPrice=(pro_GoldPrice[ParentServer][$(Server).value]*PriceFitsArray[TypeName][1]*$(Amount).value);
			
			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);
				this.UnitPrice=(((1-(Amount/Min)*((1-beat_num)/(Max/Min)))*this.TotalPrice)/Amount).toFixed(5);
			}
	}
}

///////************************************************
function SubMitCheck(Method){
	this.SubmitMethod=Method;
	this.GameName="focus";
	this.SiteName="www.wowgold.ws";
	if(!$("LarCode")){
		servername =this.GameName;	
	}else{
		gamename = RealmArray[$("LarCode").value][1];
		gamename1 = RealmArray[$("LarCode").value][0];
	}
		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;
				}
				if($("email_address").value==''){
					alert('Enter Email Address!');
					$("email_address").focus();
					return false;
				}
				if ($("email_address").value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
					alert('Email Address Wrong!');
					$("email_address").select();
					return false;
				}

				if($("tel").value==''){
					alert('Enter Phone Number!');
					$("tel").focus();
					return false;
				}
				if ($("tel").value.search(/^[0-9]+$/) == -1){
					alert('Phone Number Wrong!');
					$("tel").select();
					return false;
				}
				
				var p=document.forms["checkout_confirmation"];
				p.amount.value=parseFloat($("TotalPrice").value);
				p.item_name.value='www.wowgold.ws|1 x '+gamename1+'-'+$("Server").options[$("Server").selectedIndex].text+'- '+$("TotalPrice").value+'G ';
				p.item_number.value="81|1|"+$("LarCode").value+"|"+$("Server").value+"|"+$("Num").value;
				p.os0.value=$("CharactorName").value+"|0|0";
				p.os1.value=$("email_address").value+"| |"+$("tel").value+"| ";
				if($('PriceType')){
					p.currency_code.value=$('PriceType').value.toUpperCase();	
				}else{
					p.currency_code.value=default_Type;
				}
				
				/*eu
				p.server.value=$("Server").options[$("Server").selectedIndex].text;
				p.game.value=gamename1;
				p.price.value=parseFloat($("TotalPrice").value);
				p.gold.value=$("Num").value;
				p.char.value=$("CharactorName").value;
				p.mail.value=$("email_address").value;
				p.phone.value=$("tel").value;
				if($('PriceType')){
					p.tm_currency_code.value=$('PriceType').value.toUpperCase();	
				}else{
					p.tm_currency_code.value=default_Type;
				}*/

/*				p.item_number1.value=$("CharactorName").value+"|0|0";
				p.gamename.value=gamename;
				p.gamename1.value=gamename1;
				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;
				p.customers_email_address.value=$("email_address").value;
				p.enquiry.value=$("enquiry1").value;
				p.g_id.value=$("LarCode").value;
				p.s_id.value=$("Server").value;
				p.phone.value=$("tel").value;*/
				
				p.submit();
			}	
		}
}



/////////////////////////////////////////////////////////////////////////////////


function leveling_class(gameserver,slevel,elevel){   

	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 <= 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{

 	  $(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(!$("LarCode_e")){

		servername1 =this.GameName;	

	}else{

		servername1 = RealmArray[$("LarCode_e").value][1];

	}

	this.PaySubMit=function(){

		

    	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){

			var 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="payment_eu.php?action=pl";

				$("pl_form").submit();

				break;

			case "4":

				$("pl_LarCode").value=servername1;

				$("pl_Server").value=$("Server_e").options[$("Server_e").selectedIndex].text;

				$("pl_form").action="payment_wu.php?action=pl";

				$("pl_form").submit();

				break;

		}

	}

}



}

