var inPopup = false;

function popup() {
	var viewportHeight;
	var blanketHeight;
	if (typeof(window.innerHeight) != 'undefined') {
		viewportHeight = window.innerHeight;
	} else {
		viewportHeight = document.documentElement.clientHeight;

		// IE being weird
		if (viewportHeight == 0) {
			viewportHeight = document.body.clientHeight;
		}
	}

	if ((viewportHeight > document.body.scrollHeight) && (viewportHeight > document.body.clientHeight)) {
		blanketHeight = viewportHeight;
	} else {
		if (document.body.clientHeight > document.body.scrollHeight) {
			blanketHeight = document.body.clientHeight;
		} else {
			blanketHeight = document.body.scrollHeight;
		}
	}
	var minHeight = 800;
	if (blanketHeight < minHeight) {
		blanketHeight = minHeight;
	}

	var blanket = document.getElementById('blanket');
	blanket.style.height = blanketHeight + 'px';

	var viewportWidth;
	var blanketWidth;
	if (typeof(window.innerWidth) != 'undefined') {
		viewportWidth = window.innerWidth;
	} else {
		viewportWidth = document.documentElement.clientWidth;

		// IE being weird
		if (viewportWidth == 0) {
			viewportWidth = document.body.clientWidth;
		}
	}

	if ((viewportWidth > document.body.scrollWidth) && (viewportWidth > document.body.clientWidth)) {
		blanketWidth = viewportWidth;
	} else {
		if (document.body.clientWidth > document.body.scrollWidth) {
			blanketWidth = document.body.clientWidth;
		} else {
			blanketWidth = document.body.scrollWidth;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.width = blanketWidth + 'px';

	var scrollArr = getScrollXY();
	var popupDiv = document.getElementById('popup');

	// Can't use offsetWidth/Height as they're only set when div is displayed

	var popupDivWidth;
	var popupDivHeight;

	if (popupDiv.currentStyle) {
		popupDivWidth = popupDiv.currentStyle['width'];
		popupDivHeight = popupDiv.currentStyle['height'];
	} else if (document.defaultView) {
		popupDivWidth = document.defaultView.getComputedStyle(popupDiv, "").getPropertyValue('width');
		popupDivHeight = document.defaultView.getComputedStyle(popupDiv, "").getPropertyValue('height');
	}

	if (typeof(popupDivWidth) == 'string') {
		popupDivWidth = popupDivWidth.replace(/[^0-9]/g, "");
	}

	if (typeof(popupDivHeight) == 'string') {
		popupDivHeight = popupDivHeight.replace(/[^0-9]/g, "");
	}

	var popupLeft = (viewportWidth / 2) - (popupDivWidth / 2) + scrollArr[0];
	var popupTop = (viewportHeight / 2) - (popupDivHeight / 2) + scrollArr[1];

	popupDiv.style.top = popupTop + "px";
	popupDiv.style.left = popupLeft + "px";

	var el = document.getElementById('blanket');
	el.style.display = 'block';

	var el = document.getElementById('popup');
	el.style.display = 'block';

	return;
}

function popdown() {
	var el = document.getElementById('blanket');
	el.style.display = 'none';

	var el = document.getElementById('popup');
	el.style.display = 'none';
	return;
}

function PayForIt_start() {
	popup();
	inPopup = true;
	document.getElementById("pfi_form").submit();
	return;
}

function PayForIt_stop() {
	popdown();
	inPopup = false;
	location.reload();
	return;
}

function resizePopup() {
	if (inPopup) {
		popup();
	}
	return;
}


function blank() {
	var frame = document.getElementById("pfi_frame");

	if (frame) {
		frame.src = "empty.jsp";
	}
	return true;
}

function getScrollXY() {
	var scrOfX = 0;
	var scrOfY = 0;

	if (typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY];
}
