
window.onload = function() { load(); };
window.onresize = function() { resize_container(); };

function validate_popup_form () {
	if (validate_download_form() == true) {
		document.getElementById("download_container").style.display = "none";

		if (document.getElementById("popupURL").value != "") {
			window.open(document.getElementById("popupURL").value, "_blank", "status=0, toolbar=0, menubar=0, directories=0, width=1000, resizable=1, height=700");
		}

		return true;
	}
	
	return false;
}

function downloadWithPopup(nextPage, popupURL) {
	document.getElementById("nextPage").value = nextPage;
	document.getElementById("popupURL").value = popupURL;
	
	download();
}

function download() {
	document.getElementById("download_container").style.display = "block";
	resize_container();
}

function load() {
	if (document.all) {
		document.getElementById("firefox_shadow").style.display = "none";
	}
}

function resize_container() {
	var doc = document.getElementById("popup_window");
	var docSite = document.getElementById("container");
	var bg = document.getElementById("download_container_background");
	var firefox = document.getElementById("firefox_shadow");
	var iframe = document.getElementById("download_iframe");
	var width;
	var height;
	
	if (docSite.offsetWidth < document.body.offsetWidth) {
		width = document.body.offsetWidth;

	} else {
		width = docSite.offsetWidth;
	}
	
	if (docSite.offsetHeight < document.documentElement.clientHeight) {
		height = document.documentElement.clientHeight;

	} else {
		height = docSite.offsetHeight + document.getElementById("footer").offsetHeight + document.getElementById("copyright").offsetHeight;
	}
	
	bg.style.width = width + "px";
	bg.style.height = height + "px";
	
	bg.style.left = "0px";
	bg.style.top = "0px";
	
	doc.style.left = ((document.body.offsetWidth / 2) - (doc.offsetWidth / 2)) + "px";
	doc.style.top = ((document.documentElement.clientHeight / 2) - (doc.offsetHeight / 2)) + "px";
	
	iframe.style.left = doc.offsetLeft + 20;
	iframe.style.top = doc.offsetTop + 20;
	iframe.style.width = doc.offsetWidth - 40;
	iframe.style.height = doc.offsetHeight - 40;
	iframe.style.visibility = "visible";

	firefox.style.width = (doc.offsetWidth  - 40) + "px";
	firefox.style.height = (doc.offsetHeight - 20) + "px";
	firefox.style.left = (doc.offsetLeft + 30) + "px";
	firefox.style.top = (doc.offsetTop + 30) + "px";	
}
