function url(code, target)
{
	var httpRequest,
		xmlRequest,
		returnUrl;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/GetUrl.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest("<root code=\"" + code + "\" />")) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = responseReturnValue(httpRequest);
			if (typeof(target) == "string")
				window.open(returnUrl, "", "", target);
			else
				window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function urlLogEvent(code, eventCode, target)
{
	var httpRequest,
		xmlRequest,
		returnUrl;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/GetUrl.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest("<root code=\"" + code + "\" event=\"" + eventCode + "\" />")) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = responseReturnValue(httpRequest);
			if (typeof(target) == "string")
				window.open(returnUrl, "", "", target);
			else
				window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function selectExpo(expoID, target)
{
	var httpRequest,
		xmlRequest,
		returnUrl;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/SelectExpo.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest("<root code=\"" + expoID + "\" />")) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = responseReturnValue(httpRequest);
			// R1.3.5.1: PDF always opens in new window
			if (returnUrl.indexOf("archive.aspx") > 0)
				target = "_blank";
			if (typeof(target) == "string" && target != "")
				window.open(returnUrl, "", "", target);
			else
				window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function SelectExpo(expoID)
{
//	AddSubmitParameter("expoid", expoID);
//	SetRedirect(true);
//	Submit(100, "select");
	alert("obsolete");
}

function Logout()
{
	SetRedirect(true);
	Submit(100, "logoff");
}

function SwitchLanguage(language)
{
	var httpRequest,
		xmlRequest;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/SwitchLanguage.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest("<language>" + language + "</language>")) != null)
	{
		if (responseErrors(httpRequest) == 0)
			window.location.reload();
		else
			alert(responseMessage(httpRequest));
	}
}

function HasSelections()
{
	var xmlRequest;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/HasSelections.aspx";
	return (xmlRequest.ExecuteScalar("<root/>") == "true");
}

function _SendSelection(xml)
{
	var httpRequest,
		xmlRequest,
		returnUrl;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/SendSelection.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = unescape(document.getElementById("history").value);
			window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function _SendList(xml)
{
	var httpRequest,
		xmlRequest,
		returnUrl;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/LetMarvelSendList.aspx";
	if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = unescape(document.getElementById("history").value);
			window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function VisitorDetails(id)
{
	window.location.href = "visitor-details.aspx?visitorid=" + id + "&returnurl=" + 
		ConstructReturnUrl(null);
}

function SendVisitorDetailsPDF(visitorID)
{
	if (typeof(visitorID) == "undefined" || visitorID == "")
		window.location.href = "send-details.aspx?returnurl=" + window.location.pathname;
	else
		window.location.href = "send-details.aspx?visitorid=" + visitorID + "&returnurl=" + 
			ConstructReturnUrl(document.getElementById("history").value);
}

function CreateVisitorDetailsPDF(visitorID, target)
{
	var httpRequest,
		xmlRequest,
		returnUrl,
		xml;
	
	xmlRequest = new XmlRequest();
	xmlRequest.ServerPage = applicationPath + "XmlHttp/VisitorDetailsPDF.aspx";
	if (typeof(visitorID) == "undefined" || visitorID == "")
		xml = "<root />";
	else
		xml = "<root><visitorid>" + visitorID + "</visitorid></root>";
	if ((httpRequest = xmlRequest.ExecuteRequest(xml)) != null)
	{
		if (responseErrors(httpRequest) == 0)
		{
			returnUrl = responseReturnValue(httpRequest);
			if (typeof(target) == "string")
				window.open(returnUrl, "", "", target);
			else
				window.location.href = returnUrl;
		}
		else
			alert(responseMessage(httpRequest));
	}
}

function ToValidXML(value)
{
	return value;
	//return unescape(value).replace("&", "&amp;");
	//return "<[CDATA[" + value + "]]>";
	//return escape("<[CDATA[" + value + "]]>");
}

function ConstructReturnUrl(returnUrl)
{
	var parameters,
		thisUrl,
		expr,
		url;
	
	thisUrl = window.location.pathname;
	parameters = window.location.search;
	
	expr = /[?&]returnurl=[^&]*/gi;
	if (expr.test(parameters))
		parameters = parameters.replace(expr, "");

	if (returnUrl != null)
	{
		if (parameters.length == 0)
			parameters += "?";
		else
			parameters += "&";
		parameters += "returnurl=";
		parameters += returnUrl;
	}
	url = thisUrl + escape(parameters);
	//alert(url);
	return url;
}

function ToggleExpos(parent) {
	if (parent.className != "open")
		parent.className = "open";
	else
		parent.className = "closed";
}
