$(document).ready(function(){
    onLoadRefreshArenapoints ? ReloadCurrency() : "";
})
function CheckOut(name,moneycode,price,webtime,startlevel,endlevel,leveltype,choosetype)
{
	InfoHidden();
	var result = game.powerlevel.arenapoints.SaveForm($("#hidGameName").attr("value"), "", name, moneycode, price, webtime,startlevel, endlevel, leveltype, choosetype);
	Main("PL_CheckOut");
	window.location="confirm_step1.html";
}

function ReloadCurrency()
{
	var gameId = $("#hidGameId").attr("value");
	game.powerlevel.arenapoints.GetPackageslist(gameId, "2", MakeHtml);
}

function MakeHtml(response)
{
	if(response == null || response.value == null)
	{
		return;
	}
	var html = "";
	var htmlPieces = "";
/*	
	var htmlTemplate = "<div style=\"width:634px; border-bottom:#519ED2 solid 1px; height:39px; position:relative; color: #1862A3; font-weight:bold;\" ><div style=\"position:absolute; top:7px; left:15px; width:228px; line-height:12px; word-break:break-all;\" align=\"left\"><a style=\"cursor:pointer;\" id=\"$aDetail$\" onclick=\"DisplayHidden(this.id,'$aID$')\">$PackName$</a></div><div style=\"position:absolute; top:13px; left:300px; width:90px; line-height:12px;\" align=\"left\">$RequestDays$</div><div style=\"position:absolute; top:13px; left:407px; width:50px; line-height:12px;\" align=\"left\">$PackPrice$</div><div style=\"position:absolute; top:8px; left:502px; width:115px; line-height:12px;\" align=\"left\"><a style=\"cursor:pointer;\" onclick=\"CheckOut('$cartName$','$cartMoneyCode$','$cartPrice$','$cartWebtime$','$cartStartLevel$','$cartEndLevel$','$cartLevelType$','$cartChooseType$')\"><img src=\"/images/BUY.gif\" /></a></div></div>";
	*/
	var htmlTemplate = "<tr  onMouseOver=\"this.className='bj2';\" onMouseOut=\"this.className='bj';\"><td align=\"left\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\" ><a style=\"cursor:pointer;\" id=\"$aDetail$\" onclick=\"DisplayHidden(this.id,'$aID$')\">$PackName$</a></td><td align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D; color:#FFFF00\"  >$RequestDays$</td><td align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D; color:#FFFF00\"  >$PackPrice$</td><td align=\"center\" valign=\"middle\" style=\" border-bottom:1px solid #2D2D2D;\"  ><a style=\"cursor:pointer;\" onclick=\"CheckOut('$cartName$','$cartMoneyCode$','$cartPrice$','$cartWebtime$','$cartStartLevel$','$cartEndLevel$','$cartLevelType$','$cartChooseType$')\"><img src=\"/img/checkout.gif\" width=\"64\" height=\"16\" / border=\"0\"></a></td></tr>";
	var htmlTemplatePieces = "<tr  onMouseOver=\"this.className='bj2';\" onMouseOut=\"this.className='bj';\"><td align=\"left\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\" ><a style=\"cursor:pointer;\" id=\"$aDetail$\" onclick=\"DisplayHidden(this.id,'$aID$')\">$PackName$</a></td><td align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D; color:#FFFF00\"  >$Pieces$</td><td align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D; color:#FFFF00\"  >$RequestDays$</td><td align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D; color:#FFFF00\"  >$PackPrice$</td><td align=\"center\" valign=\"middle\" style=\" border-bottom:1px solid #2D2D2D;\"  ><a style=\"cursor:pointer;\" onclick=\"CheckOut('$cartName$','$cartMoneyCode$','$cartPrice$','$cartWebtime$','$cartStartLevel$','$cartEndLevel$','$cartLevelType$','$cartChooseType$')\"><img src=\"/img/checkout.gif\" width=\"64\" height=\"16\" / border=\"0\"></a></td></tr>";
	
	var arrayPack = response.value;
	for(var i = 0; i < arrayPack.length; i++)
	{
		var tempHtml;
		if(arrayPack[i][12] == "")
		{
			tempHtml = htmlTemplate;
		}
		else
		{
			tempHtml = htmlTemplatePieces;
			tempHtml = tempHtml.replace("$Pieces$", arrayPack[i][12]);
		}
		tempHtml = tempHtml.replace("$PackName$", arrayPack[i][1].replace("\\","").replace("new.gif","../adsimages/new.gif"));
		tempHtml = tempHtml.replace("$RequestDays$", arrayPack[i][7]);
		tempHtml = tempHtml.replace("$PackPrice$", arrayPack[i][3] + arrayPack[i][4]);
		tempHtml = tempHtml.replace("$cartName$", arrayPack[i][1].replace("\"","\\\"").replace("new.gif","../adsimages/new.gif"));
		tempHtml = tempHtml.replace("$cartMoneyCode$", arrayPack[i][2]);
		tempHtml = tempHtml.replace("$cartPrice$", arrayPack[i][4]);
		tempHtml = tempHtml.replace("$cartWebtime$", arrayPack[i][11]);
	    tempHtml = tempHtml.replace("$cartStartLevel$", arrayPack[i][5]);
		tempHtml = tempHtml.replace("$cartEndLevel$", arrayPack[i][6]);
		tempHtml = tempHtml.replace("$cartLevelType$", arrayPack[i][0]);
		tempHtml = tempHtml.replace("$cartChooseType$", arrayPack[i][9]);
		tempHtml = tempHtml.replace("$aDetail$", "aDetail_2" + "_" + i);
		tempHtml = tempHtml.replace("$aID$", arrayPack[i][10]);
		if(arrayPack[i][12] == "")
		{
			html = html + tempHtml;
		}
		else
		{
			htmlPieces = htmlPieces + tempHtml;
		}
	}
	var packRef = $("#Package");
	var headHtml = "<tr  class=\"lv\"><td width=\"55%\" align=\"left\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\" >Items</td><td width=\"16%\" align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\"  >Days</td><td width=\"13%\" align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\"  >Price</td><td width=\"16%\" align=\"center\" valign=\"middle\" style=\" border-bottom:1px solid #2D2D2D;\"  >Checkout</td></tr>";
	var headHtmlPieces = "<tr  class=\"lv\"><td width=\"33%\" align=\"left\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\" >Items</td><td width=\"22%\" align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\"  >Pieces</td><td width=\"16%\" align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\"  >Days</td><td width=\"13%\" align=\"center\" valign=\"middle\" style=\" border-right:1px solid #2D2D2D; border-bottom:1px solid #2D2D2D;\"  >Price</td><td width=\"16%\" align=\"center\" valign=\"middle\" style=\" border-bottom:1px solid #2D2D2D;\"  >Checkout</td></tr>";
	$("#Package").html(headHtml + html);
	if(htmlPieces != "")
	{
	    $("#PackagePieces").html(headHtmlPieces + htmlPieces);
	}
}

