﻿function GetScrollPosition() {
	var x = window.pageXOffset ? window.pageXOffset : 0;
	if (document.documentElement && document.documentElement.scrollLeft > x) x = document.documentElement.scrollLeft;
	if (document.body && document.body.scrollLeft > x) x = document.body.scrollLeft;
	var y = window.pageYOffset ? window.pageYOffset : 0;
	if (document.documentElement && document.documentElement.scrollTop > y) y = document.documentElement.scrollTop;
	if (document.body && document.body.scrollTop > y) y = document.body.scrollTop;
	return {x: x, y: y};
}

function GetScrollSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	return {x: xScroll, y: yScroll};
}

function GetWindowSize() {
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	return {width:windowWidth, height:windowHeight};
}

function CenterObject(obj) { 
	if (obj.style.visibility == "visible") {
		var scrollPosition = GetScrollPosition();
		var windowSize = GetWindowSize();
		var left = scrollPosition.x + (windowSize.width * 0.5) - (obj.offsetWidth * 0.5);
		var top = scrollPosition.y + (windowSize.height * 0.5) - (obj.offsetHeight * 0.5);
		obj.style.left = left + "px";
		obj.style.top = top + "px";
	}
}