﻿function ShowServerList(IndexChar)
{
	var SevAryDiv=document.getElementById("ServerListDiv").getElementsByTagName("Div");
	for(i=0;i<SevAryDiv.length;i++)
	{
		if(SevAryDiv[i].id.substring(1,2)=="_")
		{
			if(IndexChar=="ALL" || IndexChar.toUpperCase()==SevAryDiv[i].id.substring(0,1).toUpperCase())
			{
				SevAryDiv[i].style.display="";
			}
			else
			{
				SevAryDiv[i].style.display="none";
			}
		}
	}
}

//ShowItemlist
function UpdateItemList()
{
	var Game=document.getElementById("txtGame").value;
	var Server=document.getElementById("txtServer").value;
	var dt=pureland.Buy.Buy.CreateItemList(Game,Server,"1").value;	
	ShowItemList(dt);
}

function SetfromURL()
{
	var fromURL=top.document.referrer;
	var ret=pureland.Buy.Buy.SetfromURL(fromURL);
}

function random(startnum,endnum)
{
	var upnum=Math.abs(endnum-startnum);
	var ran=parseInt(Math.random()*10000000000000000);
	ran=(ran+1)%upnum;
	return ran+startnum;
}

function ShowItemList(dt)
{
	if(dt.Rows[0].Unit1=="0") return;
	if(dt.Rows.length>0)
	{
		switch(dt.Rows[0].MoneyLogo)
		{
			case "$":
				document.getElementById("drpMoneyCode").selectedIndex=0;
				break;
			case "&euro;":
				document.getElementById("drpMoneyCode").selectedIndex=1;
				break;
			case "&pound;":
				document.getElementById("drpMoneyCode").selectedIndex=2;
				break;
			case "A$":
				document.getElementById("drpMoneyCode").selectedIndex=3;
				break;
		}
	}
	var marketrate=[9,1,1,7,7,6,5,2,5,8,1,5,2,2,2,1,4,3,6,2,5,9,4,2,8,6,5,2,1,9,3,6,5,2,7,2,3,4,4,5,6,3,3,1,2,7,1,7,3,2,5,9,6,2,3,2,3,5,5,5,8,7,1,7,9,6,3,9,2,1,2,3,7,4,6,1,7,7,5,4,2,3,2,2,2,5,2,1,8,9,5,4,7,1,3,3,4,8,9,8];
	var str="";
	for(i=0;i<dt.Rows.length;i++)
	{
		var marketprice=parseFloat(dt.Rows[i].Price1)*(1.4+parseFloat(marketrate[i])/parseFloat(100));
		marketprice=marketprice.toFixed(2);
		str=str+"<div class=\"p12\">\r\n";
		str=str+"	<div class=\"p13\" align=\"center\">\r\n";
		str=str+"		<p class=\"p14\">"+dt.Rows[i].Unit1+"</p>\r\n";
		str=str+"		<p class=\"p15\">"+dt.Rows[i].UnitName+"</p>\r\n";
		str=str+"		</p>\r\n";
		str=str+"	</div>\r\n";
		str=str+"	<div align=\"center\" class=\"p162\"\"><del>Price "+marketprice+"</del></div>\r\n<div align=\"center\" class=\"p16\"\">Only "+dt.Rows[i].MoneyLogo+dt.Rows[i].Price1+"</div>\r\n";
		str=str+"	<div class=\"p17\"><a style=\"cursor:pointer;\" onclick=\"SubmitConfirm("+dt.Rows[i].Unit1+","+dt.Rows[i].Unit2+","+dt.Rows[i].Price1+","+dt.Rows[i].Price2+");return false;\"><img src=\"../images/buy.gif\" border=\"0\"/></a></div>\r\n";
		str=str+"</div>\r\n";
	}
	str=str+"<div style=\"clear:both; height:20px;\"></div>";
	document.getElementById("ServerPriceListDiv").innerHTML=str;
}

//Submit
function SubmitConfirm(unit1,unit2,price1,price2)
{
	var MoneyCode=document.getElementById("drpMoneyCode").value;
	var Game=document.getElementById("txtGame").value;
	var Server=document.getElementById("txtServer").value;
	var result = pureland.Buy.Buy.SubmitConfirm(Game,Server,unit1.toString(),unit2.toString(),price1.toString(),price2.toString(),MoneyCode).value;
	if(result=="0" || result=="-1")
	{
		if(result=="0") alert("Url overtime,Please refresh webpage.");
		if(result=="-1") alert("Server is busy now ,Please try it again.");
	}
	else if(result=="1")
	{
		Main("CheckOut");
		top.location.href="../Buy/Confirm_Step1.Html";
	}
}

//Change MoneyCode and ShowItemList
function ChangeMoneyCode(MoneyCode)
{
	var Game=document.getElementById("txtGame").value;
	var Server=document.getElementById("txtServer").value;
	var dt=pureland.Buy.Buy.ChangeMoneyCode(Game,Server,MoneyCode).value;
	ShowItemList(dt);
}

