/*
	Check whether or not e-commerce is currently disabled.  If so, put up a modal dialog.
	Requires jQuery and jQuery UI dialog widget.
*/

$(document).ready(function() {
	$("#misc-notify").dialog({
		modal: true,
		autoOpen: false,
		zIndex: 10000001,
		buttons: {
			"OK": function() { 
				if (eccurl != "") location.href = eccurl; 
				else $(this).dialog("close");
			}
		}
	});
});

var eccurl;
var ecavail = true;

function ECommerceCheck(returnURL,defer) {
	if (arguments.length == 1) { defer = false; }
	$.get("/Common/ECommerceCheck.cfm", function(data) {
			result = $.trim(data);
			if (result != "OK") {
				$("#misc-notify").html("We're sorry, this section of our website is currently closed for maintenance.<br /><br />Please come back at " + data + " when this section will be available again");
				$("#misc-notify").dialog("option","title","Closed for Maintenance");
				eccurl = returnURL;
				ecavail = false;
				if (!defer) $("#misc-notify").dialog("open");
			} else {
				ecavail = true;
			}
	});
}

function ECommerceAvailable() {
	return ecavail;
}

function ECommerceDialog() {
	if (!ecavail) $("#misc-notify").dialog("open");
}
