﻿function MakePopupFrame(width, height) {
	var frame = $(
'<div class="PopupBoxContainer">' +
'	<div id="popupBox" style="width:' + (width + 32) + 'px;height:' + (height + 32) + 'px;">' +
'		<a href="#" class="CloseButton">Close Window</a>' +
'		<div class="TopLeft"><!-- --></div><div class="TopMiddle"><!-- --></div><div class="TopRight"><!-- --></div>' +
'		<div class="ClearFix"><!-- --></div>' +
'		<div class="LeftSide"><!-- --></div>' +
'		<div class="ContentFrame"><div class="ContentInner"><div>' +

'		</div><div class="ClearFix"><!-- --></div>' +
'		</div></div>' +
'		<div class="RightSide"><!-- --></div>' +
'		<div class="BotLeft"><!-- --></div><div class="BotMiddle"><!-- --></div><div class="BotRight"><!-- --></div>' +
'	</div>' +
'</div>');
	$(document.body).append(frame);
	var resizer = function () {
		var doc = $(document);
		frame.height(doc.height());
	};
	$(window).resize(resizer);
	window.ClosePopup = function () {
		frame.remove();
		$(window).unbind('resize', resizer);
		return false;
	};
	$(".CloseButton", frame).click(window.ClosePopup);
	$("#popupBox").css({ top: $(document).scrollTop() + 100 });
	resizer();
	return $(".ContentInner>div:first", frame);
}

//todo
$(function () {
	$("#ContentFrame .LatestBookletPopup").click(LatestBookletPopup);
	$("#ContentFrame .WebsiteReviewPopup").click(WebsiteReviewPopup);
	$("#ContentFrame .QuestionPopup").click(QuestionPopup);
	$("#ContentFrame .NewsletterPopup").click(NewsletterPopup);
	$("#ContentFrame .ContactPopup").click(ContactPopup);
});

function LatestBookletPopup() {
	var frame = MakePopupFrame(512, 450);
	frame.append("<iframe runat=\"server\" src=\"/Popups/RequestBooklet.aspx\" width=\"520\" height=\"445\" frameborder=\"0\"></iframe>");
	return false;
}

function WebsiteReviewPopup() {
	var frame = MakePopupFrame(512, 480);
	frame.append("<iframe runat=\"server\" src=\"/Popups/WebsiteReview.aspx\" width=\"520\" height=\"475\" frameborder=\"0\"></iframe>");
	return false;
}

function QuestionPopup() {
	var frame = MakePopupFrame(512, 440);
	frame.append("<iframe runat=\"server\" src=\"/Popups/Question.aspx\" width=\"520\" height=\"435\" frameborder=\"0\"></iframe>");
	return false;
}

function NewsletterPopup() {
	var frame = MakePopupFrame(512, 430);
	frame.append("<iframe runat=\"server\" src=\"/Popups/Newsletter.aspx\" width=\"520\" height=\"425\" frameborder=\"0\"></iframe>");
	return false;
}

function ContactPopup() {
	var frame = MakePopupFrame(622, 550);
	frame.append("<iframe runat=\"server\" src=\"/Popups/Contact.aspx\" width=\"620\" height=\"545\" frameborder=\"0\"></iframe>");
	return false;
}
