﻿var popupStatus = 0;

function loadPopup() {
	if (popupStatus == 0) {
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("normal");
		$("#popupContainer").fadeIn("normal");
		popupStatus = 1;
	}
}

function disablePopup() {
	if (popupStatus == 1) {
		$("#backgroundPopup").fadeOut("normal");
		$("#popupContainer").fadeOut("normal");
		popupStatus = 0;
	}
}

function centerPopup() {
	var windowHeight = $(document).height(); // document.documentElement.clientHeight;
	var windowWidth = $(document).width(); // document.documentElement.clientWidth;
	var popupHeight = $("#popupContainer").height();
	var popupWidth = $("#popupContainer").width();
	$("#popupContainer").css({
		"position": "absolute",
		"top": ($(document).scrollTop() + ((windowHeight / 2) - (popupHeight / 2) - 200)),
		"left": ((windowWidth / 2) - (popupWidth / 2))
	});
	$("#backgroundPopup").css({
		"height": $(document).height()
	});
}

function openAlert(heading, contents, closeTxt) {
	centerPopup();
	loadPopup();
	$("#popupContent").html('<h3>' + heading + '</h3><p>' + contents + '</p>');
}

function openAlertWithClose(heading, contents, closeTxt) {
	centerPopup();
	loadPopup();
	$("#popupContent").html('<h2 class="header">' + heading + '</h3><p>' + contents + '</p><p><a href="javascript:void(0);" onclick="javascript:disablePopup();">' + closeTxt + '</a></p>');
}

function openAlertNoHeadingWithClose(contents, closeTxt) {
	centerPopup();
	loadPopup();
	$("#popupContent").html('<p>' + contents + '</p><p><a href="javascript:void(0);" onclick="javascript:disablePopup();">' + closeTxt + '</a></p>');
}
