$i=function(id){return document.getElementById(id)}
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.silkroadonlinemall.com";
	if(!$i("LarCode")){
		gamename =this.GameName;	
	}else{
		gamename = RealmArray[$i("LarCode").value][1];
		gamename1 = RealmArray[$i("LarCode").value][0];
	}
			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.gamename.value=gamename;
				p.gamename1.value=gamename1;
				p.amount3.value=$i("Num").value;
				p.amount2.value = $i("Num").options[$i("Num").selectedIndex].text;
				p.UnitPrice.value=$i("UnitPrice").value;
				p.TotalPrice.value=parseFloat($i("TotalPrice").value);
				p.servername.value=$i("Server").options[$i("Server").selectedIndex].text;
				p.CharactorName.value=$i("CharactorName").value;
				p.g_id.value=$i("LarCode").value;
				p.s_id.value=$i("Server").value;
				if($i('PriceType')){
					p.PriceType.value=$i('PriceType').value.toUpperCase();	
				}else{
					p.PriceType.value=default_Type;
				}
				p.submit();
		}
}
function check_pl(submit_type,method){
		if($i("time").value==0){
		alert("Enter Price");
		return false;
		}
		if($i("charactor").value==""){
		alert("Enter charactor name");
		$i("charactor").select();
		return false;
		}
		if($i("username").value==""){
		$i("username").select();
		alert("Enter username");
		return false;
		}
		if($i("password").value==""){
		$i("password").select();
		alert("Enter password");
		return false;
		}
		if($i("pl_firstname").value==""){
                    alert('Enter First Name!');
					$i("pl_firstname").select();
					return false;}
  if($i("pl_lastname").value==""){
  					alert('Enter Last Name!');
					$i("pl_lastname").select();
					return false;}
 if($i("pl_email_address").value==""){
  alert('Enter Email Address!');
					$i("pl_email_address").select();
					return false;}
if ($i("pl_email_address").value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
					alert('Email Address Wrong!');
					$i("pl_email_address").select();
					return false;
}
					if(($i("usa_tel1").value=="" || $i("usa_tel2").value=="" || $i("usa_tel3").value=="") && ($i("countryCode").value=="" || $i("not_use_tel").value==""))
{
alert("Enter Telephone");return false;}
if($i("usa_tel1").value!="" && $i("usa_tel2").value!="" && $i("usa_tel3").value!=""){
 var phone=$i("usa_tel1").value+"-"+$i("usa_tel2").value+"-"+$i("usa_tel3").value;}
else{
 var phone=$i("countryCode").value+"-"+$i("not_use_tel").value;}	
		var gameid=$i("game_name").value;
		 pl_level_submit(method,gameid,phone,submit_type);
		
}
$pl_price=function(game_id,type,level_end){return RealmLeveArray[game_id][type][level_end];}

function getprice(game_id,level_begin,level_end){
	for(j=level_begin;j>=0;j--){
		price1=$pl_price(game_id,"price",level_end)-$pl_price(game_id,"price",j);
		time1=$pl_price(game_id,"time",level_end)-$pl_price(game_id,"time",j);
		var price_info={"price":price1,"time":time1};
		if(price1>0){
		 return price_info;
		}
	}
}
function level(){
	
	var game_id=$i("game_name").value;
	var level_end=$i("level_end").value-1;
	var level_begin=$i("level_begin").value-1;
	if(level_end<minlevel && level_begin<minlevel){
		var price=RealmLeveArray[game_id]["price"][1];	
		var time=RealmLeveArray[game_id]["time"][1];
		}
		else{
	var price_end=$pl_price(game_id,"price",level_end);
	var price_begin=$pl_price(game_id,"price",level_begin);
	var price=price_end-price_begin+RealmLeveArray[game_id]["price"][1];
	var time=$pl_price(game_id,"time",level_end)-$pl_price(game_id,"time",level_begin)+RealmLeveArray[game_id]["time"][1];;
		}
	if(level_end<=level_begin){
		$i("USD").value=0.00;
		$i("GBP").value=0.00;
		$i("EUR").value=0.00;
		$i("time").value=0.00;
		}
	else{
	
		   	if(price>0){
					$i("USD").value=(price*PriceFitsArray["USD"][1]).toFixed(2);
					$i("GBP").value=(price*PriceFitsArray["GBP"][1]).toFixed(2);
					$i("EUR").value=(price*PriceFitsArray["EUR"][1]).toFixed(2);
					$i("time").value=time;
				}
		    else{   
				   price=getprice(game_id,level_begin,level_end);
				   $i("USD").value=(price["price"]*PriceFitsArray["USD"][1]).toFixed(2);
				   $i("GBP").value=(price["price"]*PriceFitsArray["GBP"][1]).toFixed(2);
				   $i("EUR").value=(price["price"]*PriceFitsArray["EUR"][1]).toFixed(2);
				   $i("time").value=price["time"];
				 }
		 }
	}
function pl_honor()
{
	var game_id=$i("game_name").value;
	var price=PriceHonorArray[game_id][$i("time").value];
	$i("USD").value=(price*PriceFitsArray["USD"][1]).toFixed(2);
	$i("GBP").value=(price*PriceFitsArray["GBP"][1]).toFixed(2);
	$i("EUR").value=(price*PriceFitsArray["EUR"][1]).toFixed(2);
	
}
function pl_reputation()
{
	var game_id=$i("game_name").value;
	var price=PriceReputationArray[game_id][$i("city_name").value][$i("time").value];
	$i("USD").value=(price*PriceFitsArray["USD"][1]).toFixed(2);
	$i("GBP").value=(price*PriceFitsArray["GBP"][1]).toFixed(2);
	$i("EUR").value=(price*PriceFitsArray["EUR"][1]).toFixed(2);
	
}
function pl_level_submit(method,gameid,phone,submit_type){
	    this.gamename_all=RealmArray[gameid][1];
		this.gamename_part=RealmArray[gameid][0];
		this.server_name = $i("server_name_pl").options[$i("server_name_pl").selectedIndex].text;	
        this.server_id=$i("server_name_pl").value;
	var one_submit=function(gamename_all,gamename_part,server_name){
		var price_type = document.getElementsByName('price_type');
			for(var i=0;i<price_type.length;i++){
				if(price_type[i].checked){
					price_type=price_type[i].value;
				break;
			}
		}
		  if(typeof(price_type)=="object"){
			  price_type="USD";}
		 $i("currency_code").value=price_type;
		 $i("amount").value = $i(price_type).value;
		 $i("custom").value = "1:PayPal Game Order";
		 $i("item_name").value = "www.silkroadonlinemall.com|1 x "+this.gamename_part+" - "+this.server_name+" - pl";
 		 $i("item_number").value="123|2|"+gameid+"|"+this.server_id+"|1";
		 $i("os0").value=$i("charactor").value+"|"+$i("username").value+"|"+$i("password").value;
		 $i("os1").value=$i("pl_email_address").value+"|"+$i("pl_firstname").value+" "+$i("pl_lastname").value+"|"+phone+"|0";
		 if(submit_type=="pl_level"){
		 $i("os2").value=$i("level_begin").value+"-"+$i("level_end").value+" "+$i("time").value+"h|"+"Pl-Level";
		 }
		 else if(submit_type=="pl_honor"){
		         $i("os2").value="0 "+$i("time").value*24+"h|Pl-Honor";
		  }
		 else if(submit_type=="pl_reputation"){
		         $i("os2").value="0 "+$i("time").value*24+"h|Pl-reputation-"+CityArray[$i("city_name").value];
			 }
		 else if(submit_type=="pl_package"){
		         $i("os2").value="0 "+$i("time").value+"h|Pl-Concessions-"+"-"+$i("name").value;
				 
			 }
		 $i("os3").value=$i("notice").value;
		 //$i("checkout_confirmation").charset="iso-8859-1";
		 document.charset='iso-8859-1';
    	 $i("checkout_confirmation").submit();
		 //$i("aa").onclick();
 		 return false;
		}
	  if(method=="false"){
		  one_submit();
		  }  
	  else{
	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":
				one_submit();
				break;
			case "3":
				$i("pl_LarCode").value=gamename_all;
				$i("pl_Server").value=server_name;
				$i("pl_form").action="payment_eu.php?action=pl";
				$i("form1").submit();
			case "4":
				$i("pl_LarCode").value=gamename_all;
				$i("pl_Server").value=server_name;
				$i("pl_form").action="payment_wu.php?action=pl";
				$i("form1").submit();
				
		}
		  }
	}
function SetServerList(){
	var str_option="<select name='server_name_pl' id='server_name_pl'>";
	if(!$i("game_name")){
		for(key in ServerArray[1]){
				str_option+="<option value=";
				str_option+=key;
				str_option+=">";
				str_option+=ServerArray[1][key];
				str_option+="</option>";
			}
	}else{
			for(key in ServerArray[document.getElementById("game_name").value]){
				str_option+="<option value=";
				str_option+=key;
				str_option+=">";
				str_option+=ServerArray[document.getElementById("game_name").value][key];
				str_option+="</option>";
			}
		}
	
	str_option+="</select>";
	document.getElementById("Faction_e").innerHTML=str_option;
}
function checkphone(phonenum,id)
{      
    var re = /^[0-9]*$/;     
     if (re.test(phonenum) == false)
    {   
	    document.getElementById(id).value="";
    }

  }
