function GA_DownloadProduct(sDownloadId)
{
	var oSDNC = new vdf.ajax.SoapCall("SendDownloadNote", {}, "GA_Proxy.asp");
	
	window.open("GA_Download.asp?DownloadId=" + sDownloadId);
	
	oSDNC.addParam("sSessionToken", GA_GetCookie("vdfSessionKey"));
	oSDNC.addParam("sEmail", GA_GetCookie("gaEmail"));
	oSDNC.addParam("sIp", GA_IP);
	oSDNC.addParam("sDownloadId", sDownloadId);
	oSDNC.addParam("sUrl", location.href);
	oSDNC.send(true);
}

function GA_GetDownloadInfo(sDownloadId)
{
	var oGDIC = new vdf.ajax.SoapCall("GetDownloadInfo", {}, "GA_Proxy.asp");
	var bExtern = sDownloadId.indexOf("|EXTERN|") != -1;
	sDownloadId = sDownloadId.replace("|EXTERN|", "");
	var sForm = "";
	var sLink = "window.open('http://localhost/globalaccount/externcommand.asp?downloadid=" + sDownloadId + "&email=" + GA_GetCookie('gaEmail') + "&serv=" + location.href + "');";
	
	if (sDownloadId == "") return;
	
	if (!bExtern)
	{
		if (GA_UserLoggedIn())
		{
			oGDIC.addParam("sSessionToken", GA_GetCookie("vdfSessionKey"));
			oGDIC.addParam("sEmail", GA_GetCookie("gaEmail"));
			oGDIC.addParam("sIp", GA_IP);
			oGDIC.addParam("sDownloadId", sDownloadId);
			oGDIC.onFinished.addListener(GA_handleGetDownloadInfo);
			oGDIC.send(true);
		}
		else
		{
			GA_WriteAccountEntry();
		}
	}
	else
	{
		sForm = ("<a id='GA_buttonDownload' Class='button' onclick=\"" + sLink + "\"><span>Go to download page!</span></a><br><br>");
		
		GA_ShowScreen("GA_Container", sForm);
	}
}

function GA_handleGetDownloadInfo(oEvent) 
{
	var sForm = "";
	var stDownloads = "";
	var i = 0;
	
	if (!GA_CallFailed(oEvent))
	{
		stDownloads = GA_CallValue(oEvent, true);
		
		if (stDownloads == "")
		{
			GA_ShowScreen("GA_Container", "Product you've selected is (no longer) valid.");
		}
		else
		{
			for (i = 0; i < stDownloads.length; i++)
			{
				sForm += ("<label>" + stDownloads[i].sDescription + "</label><a id='GA_buttonDownload' Class='button' onclick='GA_DownloadProduct(\"" + stDownloads[i].sDownloadId + "\");'><span>Download now!</span></a><br><br>");
			}

			GA_ShowScreen("GA_Container", sForm);		
		}
	}
}
