$(document).ready(function(){
    //onLoadRefreshCustom ? ReloadCurrency() : "";
})

function CheckOut(name,moneycode,price,webtime,startlevel,endlevel,leveltype,choosetype)
{
	InfoHidden();
	var result = game.powerlevel.honor.SaveForm($("#hidGameName").attr("value"), "", name, moneycode, price, webtime, startlevel, endlevel, leveltype, choosetype);
	Main("CheckOut");
	window.location="confirm_step1.html";
}

function ReloadCurrency()
{
	var gameId = $("#hidGameId").attr("value");
	game.powerlevel.honor.GetPackageslist(gameId, "1", 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 = "<div style=\"margin-bottom:10px;\" align=\"center\"><div style=\"height:14px; width:98%; padding:5px; background-color:#1A1A1A; border:1px solid #2E2E2E; margin-bottom:4px;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"3%\" align=\"center\" valign=\"middle\"><img src=\"img/jt.gif\" width=\"7\" height=\"5\" /></td><td width=\"50%\" align=\"left\" valign=\"middle\"><strong><a href=\"#\">$PackName$</a></strong></td><td width=\"15%\" align=\"center\" valign=\"middle\" style=\"color:#FF0000;\"><strong>$PackPrice$</strong></td><td width=\"15%\" align=\"center\" valign=\"middle\">$RequestDays$</td><td width=\"17%\" valign=\"middle\"><a style=\"cursor:pointer;\" onclick=\"CheckOut('$cartName$','$cartMoneyCode$','$cartPrice$','$cartWebtime$','$cartStartLevel$','$cartEndLevel$','$cartLevelType$','$cartChooseType$')\"><img src=\"img/checkout.gif\" width=\"64\" height=\"16\" /></a></td></tr></table></div><div style=\"background-color:#242424; line-height:18px; border:1px solid #2D2D2D; padding:10px; width:94%;\" align=\"left\"><span class=\"lv\"><p style=\"word-break:break-all;\">$Detail$</p></span></div></div>";
	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;\" >$PackName$</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 = htmlTemplate;
		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("$Detail$", arrayPack[i][8]);
		//tempHtml = tempHtml.replace("$aDetail$", "aDetail_" + packageClass + "_" + i);
		tempHtml = tempHtml.replace("$aID$", arrayPack[i][10]);
		html = html + 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(html);
}

