function OnInitForm() {
	var flashHeader,
		appKey;

	appKey = document.getElementById("appkey").value;
	if ((flashHeader = document.getElementById("flashheader")) != null)
		SetFlashHeader(flashHeader.value.toLowerCase(), appKey);
	switch (document.getElementById("showmenu").value) {
		case "yes":
		case "left":
			ShowLeftFlashMenu(appKey);
			break;
	}
	if (typeof (LocalInit) == "function")
		LocalInit();
}

function ValidateSubscriber(email, optin) {
	var xmlRequest;

	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/ValidateEmail.aspx";
	return xmlRequest.ExecuteScalar(
		"<root>" +
			"<email>" + email + "</email>" +
			"<tour>" + optin + "</tour>" +
		"</root>");
}

function SetFlashHeader(name, appKey) {
	switch (name) {
		case "header":
			var so = new SWFObject("API/loader.swf", "sotester", "927", "305", "9.0.28", "#FFFFFF");
			so.addParam("allowNetworking", "all");
			so.addParam("wmode", "transparent");
			so.addVariable("fForm", "API/header.swf");
			so.addVariable("config", "API/header.xml");
			so.addVariable("_gl.CARROUSEL", "homeofcomedy");
			so.addVariable("_gl.SCALE_IMAGES", "true");
			so.addVariable("_gl.SHOW_LOGO", "true");
			so.addVariable("ShowLoader", "false");
			so.addVariable("Scale", "70");
			so.addVariable("_gl.SiteURL", document.location.href);
			so.addParam("allowScriptAccess", "all");
			so.write("header");
			break;

		case "header_small":
			var so = new SWFObject("API/loader.swf", "sotester", "927", "152", "9.0.28", "#FFFFFF");
			so.addParam("allowNetworking", "all");
			so.addParam("wmode", "transparent");
			so.addVariable("fForm", "API/header_small.swf");
			so.addVariable("config", "API/header.xml");
			so.addVariable("ShowLoader", "false");
			so.addVariable("Scale", "70");
			so.addVariable("_gl.SiteURL", document.location.href);
			so.addParam("allowScriptAccess", "all");
			so.write("header");
			break;

		case "header_portal":
			var so = new SWFObject("API/loader.swf", "sotester", "927", "305", "9.0.28", "#FFFFFF");
			so.addParam("allowNetworking", "all");
			so.addParam("wmode", "transparent");
			so.addVariable("fForm", "API/header.swf");
			so.addVariable("config", "API/header.xml");
			so.addVariable("_gl.CARROUSEL", "portalpage");
			so.addVariable("_gl.SCALE_IMAGES", "true");
			so.addVariable("_gl.SHOW_LOGO", "false");
			so.addVariable("ShowLoader", "false");
			so.addVariable("Scale", "70");
			so.addVariable("_gl.SiteURL", document.location.href);
			so.addParam("allowScriptAccess", "all");
			so.write("header");
			break;

		case "headerlarge":
			var so = new SWFObject("API/loader.swf", "sotester", "927", "305", "9.0.28", "#FFFFFF");
			so.addParam("allowNetworking", "all");
			so.addParam("wmode", "transparent");
			so.addVariable("fForm", "API/newheader.swf");
			so.addVariable("config", "API/newheader.xml");
			so.addVariable("_gl.APP_KEY", appKey);
			so.addVariable("_gl.SiteURL", document.location.href);
			so.addParam("allowScriptAccess", "all");
			so.write("header");
			break;

		case "headersmall":
			var so = new SWFObject("API/loader.swf", "sotester", "927", "152", "9.0.28", "#FFFFFF");
			so.addParam("allowNetworking", "all");
			so.addParam("wmode", "transparent");
			so.addVariable("fForm", "API/newheader_small.swf");
			so.addVariable("config", "API/newheader.xml");
			so.addVariable("_gl.SHOW_LOGO", "true");
			so.addVariable("ShowLoader", "false");			
			so.addVariable("_gl.APP_KEY", appKey);
			so.addVariable("_gl.SiteURL", document.location.href);
			so.addParam("allowScriptAccess", "all");
			so.write("header");
			break;

		case "talenttour":
			var so = new SWFObject("API/talenttour_header_2010.swf", "sotester", "927", "307", "9.0.28", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("talent", appKey);
			so.addVariable("lang", document.getElementById("language").value);
			so.write("header");
			break;
	}
}

//function ShowFlashMenu(appKey)
//{	
//	var selectedID;
//	var so;
//	
//	so = new SWFObject("API/loader.swf", "sotester", "170", "240", "9.0.28", "#FFFFFF");
//	so.addParam("allowNetworking", "all"); 
//	so.addParam("wmode","transparent");
//	so.addVariable("fForm","API/leftmenu.swf");
//	so.addVariable("config","API/sitemenu.xml");
//  so.addVariable("ShowLoader","false");
//	so.addVariable("Header","false");
//	so.addVariable("Scale","70");
//	if ((selectedID = document.getElementById("activemenuid")) != null)
//		so.addVariable("_gl.selectedId", selectedID.value);
//	so.addVariable("_gl.SiteURL",document.location.href);
//	so.addParam("allowScriptAccess", "all");
//	so.write("menu");	 
//}

function ShowLeftFlashMenu(appKey) {
	var so;

	so = new SWFObject("API/loader.swf", "sotester", "170", "320", "9.0.28", "#FFFFFF");
	so.addParam("allowNetworking", "all");
	so.addParam("wmode", "transparent");
	so.addVariable("config", "API/newsitemenu.xml");
	//so.addVariable("fForm", "API/newleftmenu.swf");
	so.addVariable("fForm", "API/leftmenu.swf");
	so.addVariable("ShowLoader", "false");
	so.addVariable("_gl.APP_KEY", appKey);
	so.addVariable("_gl.SiteURL", document.location.href);
	so.addParam("allowScriptAccess", "all");
	so.write("menu");
}

function AddToShoppingCart(itemID) {
	alert(itemID);
	var cartItemID,
		xmlHttp;

	xmlHttp = XmlHttpObject();
	xmlHttp.open("POST", applicationPath + "XmlHttp/AddToShoppingCart.aspx", false);
	xmlHttp.send("<root><itemid>" + itemID + "</itemid><quantity>1</quantity></root>");
	if (XmlHttpResponse(xmlHttp, document.body, false) == 0) {
		responseRecordID(xmlHttp);
		GotoShoppingCart();
	}
}

function GotoShoppingCart() {
	window.location.href = applicationPath + "afrekenen.aspx";
}

function SetCoupon(coupon) {
	var httpRequest,
		xmlRequest,
		xml;

	xml = "<root coupon=\"" + coupon + "\" />";
	xmlRequest = new XmlRequest(applicationPath + "XmlHttp/SetCoupon.aspx");
	xmlRequest.Debug = false;
	try {
		if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null) {
			if (responseErrors(httpRequest) == 0) {
				return null;
			}
			else
				return evaluateXPath(httpRequest.responseXML, "response/error");
		}
	}
	catch (exception) {
		alert(exception.message);
	}
}

