﻿/// Loading message box
(function($) {
	$.utilisMsgBox = function(text, override) {
		var id = 'utilis_msgBox';
		var loadingBox = $('#' + id);
		if (loadingBox.length == 0) {
			loadingBox = $('<div class="utilis_message_box ui-corner-bottom" id="' + id + '"><b></b></div>');
			loadingBox.appendTo(document.body);
		}

		var isVisible = text != null && $.trim(text) != '';
		if (isVisible) {
			var msgTextElement = $('b', loadingBox);
			if (!$.utilisMsgBox.isVisible) {
				msgTextElement.html(text);
				var leftPos = $(window).width() / 2 - loadingBox.outerWidth() / 2;
				loadingBox.css({ left: leftPos });
				loadingBox.fadeIn(400);
			}
			else if (override) {
				msgTextElement.html(text);
			}
		}
		else {
			loadingBox.stop(true, true);
			loadingBox.hide();
		}

		// Store current visibility
		$.utilisMsgBox.isVisible = isVisible;
	}

	$.utilisMsgBox.isVisible = false;
})(jQuery);
