﻿WaitWindow.Visible = false;
WaitWindow.Background = null;

WaitWindow.Show = function Show(strText, strImage)
{
	try
	{
		if (window.top != window && window.top.WaitWindow)
			return window.top.WaitWindow.Show(strText, strImage);

		if (WaitWindow.Background == null)
			WaitWindow.Background = document.getElementById("popupBackground");

		if (document.getElementById("WaitWindow") != null)
		{
			WaitWindow(strText.replace(/\n/g, "<br />"));
			
			var waitWindow = document.getElementById("WaitWindowMessage");

			if (WaitWindow.Background != null)
			{
				WaitWindow.Background.style.opacity = "0.5";
				WaitWindow.Background.style.filter = "alpha(opacity=50)";

				/*try
				{
					var xamlWorkshopLoading = document.getElementById("xamlWorkshopLoading");
					if (xamlWorkshopLoading != null && xamlWorkshopLoading.content != null && xamlWorkshopLoading.content.LoadingCanvas != null)
						xamlWorkshopLoading.content.LoadingCanvas.SetColor(128, 0, 0, 0);
				}
				catch (exc) { }*/

				WaitWindow.Background.style.display = "block";
				WaitWindow.Visible = true;
			}

			if (strImage != undefined)
				waitWindow.style.backgroundImage = "url('" + strImage + "')";
			else
				waitWindow.style.backgroundImage = "";
		}
	}
	catch (exc)
	{
		alert("Error showing wait window:\n\n" + exc.message);
	}
}

WaitWindow.HideOnly = function HideOnly()
{
	try
	{
		if (window.top != window && window.top.WaitWindow)
			return window.top.WaitWindow.HideOnly();

		if (document.getElementById("WaitWindow") != null)
			WaitWindow("");
		
		WaitWindow.Visible = false;
	}
	catch (exc)
	{
		alert("Error hiding wait window:\n\n" + exc.message);
	}
}

WaitWindow.Hide = function Hide()
{
	try
	{
		if (window.top != window && window.top.WaitWindow)
			return window.top.WaitWindow.Hide();

		/*var waitWindowWrapper = document.getElementById("waitWindowWrapper");
		var popupBackground = document.getElementById("popupBackground");
		waitWindowWrapper.style.display = "none";
		popupBackground.style.display = "none";*/

		if (WaitWindow.Background != null)
		{
			if (NewPopup.OpenPopups == 0)
			{
				WaitWindow.Background.style.display = "";

				/*try
				{
					var xamlWorkshopLoading = document.getElementById("xamlWorkshopLoading");
					if (xamlWorkshopLoading != null && xamlWorkshopLoading.content != null && xamlWorkshopLoading.content.LoadingCanvas != null)
						xamlWorkshopLoading.content.LoadingCanvas.SetColor(255, 255, 255, 255);
				}
				catch (exc) { }*/
			}
		}

		if (document.getElementById("WaitWindow") != null)
			WaitWindow("");

		WaitWindow.Visible = false;
	}
	catch (exc)
	{
		alert("Error hiding wait window:\n\n" + exc.message);
	}
}

