
var OUTAGE_ALERT_COOKIE = "outageAlertDismissed";
var IMPORTANT_NOTICE_COOKIE = "importantNoticesDismissed";
var COOKIE_TIME = 365;

function showOutageNotice(notice)
{	
	if (notice == null)
	{
		return;
	}
	
	$("#notices-outageDialog").dialog({
		title: "Outage Notice",
		modal: false,
		buttons: {
			OK: function() {
				$(this).dialog('close');
				outageNoticeClosed();
			}
		},
		dialogClass: "outageNoticeMessage"
	});
	
	$(".outageNoticeMessage.ui-dialog").css({
		position: 'fixed',
		bottom: '50px',
		right: '10px',
		top: 'auto',
		left: 'auto'
	});

	$("#notices-outageDialogText").html("<b>"+notice.title+"</b><br /><br />"+notice.noticeText);
	$("#notices-outageDialog > a").bind('click', function(e){$("#notices-outageDialog").dialog('close');});	
}

function outageNoticeClosed()
{
	createCookie(OUTAGE_ALERT_COOKIE, new Date().getTime(), COOKIE_TIME);
}

function showImportantNoticesCount(notices)
{
	if (notices == null || notices.length == 0)
	{
		return;
	}
	
	$(".notices-importantNotices").css("display", "block");
	$(".notices-importantNotices").text(notices.length);
}

// For importantNotices.xhtml
function showImportantNotices(notices)
{
	if (notices == null || notices.length == 0)
	{
		$("#notices-content").html("There are no important notices at this time.");
		return;
	}

	for (var i = 0; i < notices.length; i++)
	{
		var n = notices[i];
		
		var target;
		if (n.noticeType == 1)
		{
			target = $("#notices-outages");
		}
		else
		{
			target = $("#notices-content");
		}
		
		target
			.append($("<p>").addClass("notices-title").text(n.title))
			.append($("<p>").addClass("notices-text").html(n.noticeText));
	}
	
	createCookie(IMPORTANT_NOTICE_COOKIE, new Date().getTime(), COOKIE_TIME);
}
