var warningShowing = false;

var oldScrollY = 0

function showWarning() {
	warningShowing = true;
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		scrollY = document.body.scrollTop;
	} else {
		scrollY = window.pageYOffset;
	}
	var mask = document.getElementById("mask");
	mask.style.top = scrollY + 'px'
	mask.style.width = screen.width + "px";
	mask.style.height = screen.height + "px";
	mask.style.display = "block";
	var warning = document.getElementById("warning")
	var windowHeight = getWindowHeight();
	warning.style.display = "block";
	if (windowHeight > 0) {
		var warningHeight = warning.offsetHeight;
		var warningWidth = warning.offsetWidth;
		if (windowHeight - warningHeight > 0) {
			warning.style.position = "absolute";
			warning.style.top = ((screen.height / 2) - (warningHeight)) + scrollY + 'px';
			warning.style.left = (screen.width - warningWidth) / 2;
		} else {
			warning.style.position = "static";
		}
	}
	oldi = i;
}

function scrollEvent() {
	if (warningShowing == true) {
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			scrollY = document.body.scrollTop;
		} else {
			scrollY = window.pageYOffset;
		}
		var windowHeight = getWindowHeight();
		if (scrollY < windowHeight || scrollY < oldScrollY) {
			var mask = document.getElementById("mask");
			mask.style.top = scrollY + 'px'
			mask.style.width = screen.width + "px";
			mask.style.height = screen.height + "px";
			var warning = document.getElementById("warning")
			if (windowHeight > 0) {
				var warningHeight = warning.offsetHeight;
				var warningWidth = warning.offsetWidth;
				if (windowHeight - warningHeight > 0) {
					warning.style.top = ((screen.height / 2) - (warningHeight)) + scrollY + 'px';
					warning.style.left = (screen.width - warningWidth) / 2;
				} else {
					warning.style.position = "static";
				}
			}
			oldScrollY = scrollY;
		}
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function hideWarning() {
	warningShowing = false;
	document.getElementById("warning").style.display = "none";
	document.getElementById("mask").style.display = "none";
	oldi = 0;
}


