﻿var xmlHttp;
function createXMLHttpRequest() 
{
    if (window.ActiveXObject)
    {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
	else if (window.XMLHttpRequest) 
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(url) 
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("post", url, true);
	xmlHttp.send(null);
}
function LoadPackage()
{
    createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("post", "/ajax/loadrightpackage.aspx", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("action=load&game=wow&packageid=24");
	function handleStateChange()
	{
		if(xmlHttp.readyState == 4) 
		{
			if(xmlHttp.status == 200) 
			{
				var gameId = xmlHttp.responseText;
				gold.powerlevel.PowerLevel_Common.GetPackageslist(gameId, "-1", MakeHotPackageHtml);
			}
		}
	}	
}
function MakeHotPackageHtml(response)
{
	var htmlPackage = "";
	var itemTemplate = "<div style=\"padding:5px 5px 0 5px;\"><div style=\"$Style$\"><a style=\"cursor:pointer;color:#fff;font-weight:bold;\" onclick=\"DisplayHidden(this.id,'$aID$',true)\" onmouseover=\"DisplayHidden(this.id,'$aID$',false)\" onmouseout=\"InfoHidden(false)\" id=\"$aDetail$\">$PackName$</a><br/><div style=\"float:left;width:80px;height:20px;line-height:20px;\">Time:$RequestDays$</div><div style=\"float:left;height:20px;line-height:20px;\">Price$PackPrice$</div><div style=\"clear:both;\"></div><div style=\"padding-top:5px;\">$star$</div><div style=\"float:right;padding-top:5px;\"><img style=\"cursor:pointer;\" onclick=\"GoCart('$game$','$cartName$','$cartMoneyCode$','$cartPrice$','$cartWebtime$','$cartStartLevel$','$cartEndLevel$','$cartLevelType$','$cartChooseType$','$itemID$','$hash$')\" onmouseout=\"this.src='../powerlevel/images/addtocart.gif'\" onmouseover=\"this.src='../powerlevel/images/addtocart1.gif'\" src=\"../powerlevel/images/addtocart.gif\" style=\"cursor: pointer;\"/></div></div></div>";
	var arrayPack = response.value;
	for(var i = 0; i < arrayPack.length; i++)
	{
		var tempHtml = itemTemplate;
		tempHtml = tempHtml.replace("$game$", arrayPack[i][15]);
		tempHtml = tempHtml.replace(/\$PackName\$/g, 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_1" + "_right_" + i);
		tempHtml = tempHtml.replace(/\$aID\$/g, arrayPack[i][10]);
		tempHtml = tempHtml.replace("$itemID$", arrayPack[i][10]);
		tempHtml = tempHtml.replace("$hash$", arrayPack[i][13]);	
		tempHtml = tempHtml.replace(/\$Style\$/g, (i % 2 == 1 ? "padding:5px;color:#f30;background-color:#242423;margin-left:auto;margin-right:auto;word-wrap:break-word;word-break:break-all;width:190px !important;width:200px;overflow:hidden;" : " padding:5px;color:#f30;background-color:#242423;margin-left:auto;margin-right:auto;word-wrap:break-word;word-break:break-all;width:190px !important;width:200px;overflow:hidden;"));
		tempHtml = tempHtml.replace("$star$", GetStar(arrayPack[i][14]));
		htmlPackage = htmlPackage + tempHtml;
	}
	document.getElementById("rightPackage").innerHTML = htmlPackage;
}
function GetStar(level)
{
	var starHtml = "";
	for(var i = 1; i<= 5; i++)
	{
		starHtml = starHtml + (i <= level ? "<img src=\"/AdsImages/star.gif\" />&nbsp;" : "<img src=\"/AdsImages/star_.gif\" />&nbsp;");
	}
	return starHtml;
}
function NewPackageCheckOut(name,moneycode,price,webtime,startlevel,endlevel,leveltype,choosetype)
{
	var result = gold.powerlevel.PowerLevel_Common.SaveForm('WOW', "", name, moneycode, price, webtime, startlevel, endlevel, leveltype, choosetype);
	Main("PL_CheckOut");
	window.location="confirmstep1.aspx";
}
function createXml(str)
{
	if(document.all)
    {
		var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
		xmlDom.loadXML(str);
		return xmlDom;
　　}
　　else
    {
        return new DOMParser().parseFromString(str, "text/xml");
    }
}
LoadPackage();

