function GA_NotificationSubscribe()
{
	var oNSC = new vdf.ajax.SoapCall("NotificationSubscribe", {}, "GA_Proxy.asp");
	var sSubs = new Array();
	var oElements = document.getElementsByTagName("input");
	var i = 0;

	for (i = 0; i < oElements.length; i++)
	{
		if (oElements[i].type == "checkbox" && oElements[i].attributes["isSubs"] != null && !oElements[i].disabled && oElements[i].checked)
		{
			sSubs.push(oElements[i].value);
		}
	}

	if (sSubs.length > 0)
	{			
		oNSC.addParam("sSessionToken", GA_GetCookie("vdfSessionKey"));
		oNSC.addParam("sEmail", GA_GetCookie("gaEmail"));
		oNSC.addParam("sIp", GA_IP);
		oNSC.addParam("sSubs", sSubs);
		oNSC.onFinished.addListener(GA_handleNotificationSubscribe);
		oNSC.send(true);
	}
}

function GA_handleNotificationSubscribe(oEvent) 
{
	if (!GA_CallFailed(oEvent))
	{
		if (GA_CallValue(oEvent) == 0)
		{
			alert("You are now subscribed to these topics.");
			window.location = window.location;
		}
	}
}

function GA_GetNotificationSubscriptions()
{
	var oGNSC = new vdf.ajax.SoapCall("GetNotificationSubscriptions", {}, "GA_Proxy.asp");
	oGNSC.addParam("sSessionToken", GA_GetCookie("vdfSessionKey"));
	oGNSC.addParam("sEmail", GA_GetCookie("gaEmail"));
	oGNSC.addParam("sIp", GA_IP);
	oGNSC.onFinished.addListener(GA_handleGetNotificationSubscriptions);
	oGNSC.send(true);
	
}

function GA_handleGetNotificationSubscriptions(oEvent) 
{
	if (!GA_CallFailed(oEvent))
	{
		document.getElementById("NotifyTable").innerHTML = GA_CallValue(oEvent);	
	}
}

function GA_WriteSubscriptions()
{
	var sForms = [
	
	"<div id='divAccountSubscription'>",
		"<form id='frmAccNotifySub' action='none' autocomplete='off' >",
			"<table>",
				"<tr>",
					"<td>Avaible subscriptions</td>",
				"</tr>",
				"<tr>",
					"<td id='NotifyTable'>",
					"</td>",
				"</tr>",
				"<tr>",
					"<td>",
						"<input type='button' value='Subscribe to selected topics' onclick='GA_NotificationSubscribe();' />",
					"</td>",
				"</tr>",
			"</table>",
		"</form>",
	"</div>"
	
	];

	GA_ShowScreen("divSubscriptions", sForms.join(""));
	
	GA_GetNotificationSubscriptions();
}

function GA_WriteNotificationSubscriptions()
{
	if (GA_UserLoggedIn())
	{
		GA_WriteSubscriptions();
	}
	else
	{
		GA_WriteAccountEntry();
	}
}
