﻿function loadInterstitialWindow(data, viewId, width, widthType, closeButtonLabel) {

	var showInterstitial = true;
	
	if (showInterstitial) {
		var webServiceUrl = "/EasySiteWeb/WebService/DataStoreRecordRender.asmx/RenderRecord?data=" + encodeURIComponent(data);

		// Dynamically retrieve the data
		$.ajax({
			type: "GET",
			url: webServiceUrl,
			dataType: "xml",
			success: function(responseXml) {
					onResponseSuccess({
					responseXml: responseXml,
					viewId: viewId,
					width: width,
					widthType: widthType,
					closeButtonLabel: closeButtonLabel
				});
			}
		});
	}
}

function onResponseSuccess(config) {
	var html = $(config.responseXml).find("string").text();

	if (html.length == 0)
		html = config.responseXml;

	if (html.length > 0) {
		var openingHtml
			= "<div class=\"page-interstitial-outer view-" + config.viewId + "-interstitial\">"
			+ "  <div class=\"page-interstitial-inner\">"
			+ "     <div class=\"body-outer\">"
			+ "        <div class=\"body-inner clear\">";
		var closingButtonHtml = "<div class=\"oInterstitialButtonContainer\">"
			+ "              <button onclick=\"closeInterstitial();\" class=\"oDataFormButton\">"
			+ config.closeButtonLabel
			+ "              </button>"
			+ "           </div>";
		var closingHtml
			= "        </div>"
			+ "     </div>"
			+ "   </div>"
			+ "</div>";

		html = openingHtml + html

		if (config.closeButtonLabel != "") {
			html = html + closingButtonHtml;
		}

		html = html + closingHtml;

		var marginString;
		var leftString;

		if (config.widthType == "px") {
			leftString = "50%";
			var leftOffset = config.width / 2;
			marginString = "0px 0px 0px -" + leftOffset + "px";
		}

		if (config.widthType == "%") {
			leftString = (50) - (config.width / 2) + "%";
			marginString = "0px 0px 0px 0px";
		}

		$.blockUI(
		{
			message: html,
			css:
			{
				width: config.width + config.widthType,
				left: leftString,
				margin: marginString,
				textAlign: "left",
				cursor: "default",
				border: "0"
			},
			overlayCSS:
			{
				cursor: "default"
			}
		});

	}
}

function closeInterstitial() {
	$.unblockUI();
}
