Event.observe(window, 'load', AdjustPage);

function AdjustPage(evt)
{
	var body = document.getElementsByTagName('body')[0];
	if (body.offsetHeight > 768)
	{
		$('FirstPage').className = '';
	}
	else
	{
		if (window.location.href.indexOf('popup') >= 0)
		{
			return false;
		}

		var Links = document.getElementsByTagName('a');
		for (var i = 0, Link; Link = Links[i]; i++)
		{
			if (Link.parentNode.parentNode.id == 'Languages')
			{
				continue;
			}

			Link.onclick = function(evt)
			{
				if (this.href)
				{
					OpenWindow(this.href);
					return false;
				}

				var src = Event.element(evt);
				if (src.href)
				{
					OpenWindow(src.href);
				}
				return false;
			}
		}
	}
}

function OpenWindow(url)
{
	var w = 1000;
	var h = 780;
	if (screen.availHeight < 780)
	{
		h = screen.availHeight;
	}

	if (screen.availWidth > 1000 &&
		(
			(screen.availHeight <= 800 && screen.availWidth <= 1280) ||
			(screen.availWidth <= 1200)
		)
	)
	{
		w = screen.availWidth;
	}

	url = url.replace('index.php/', 'index.php/popup/');
	win = window.open(url, '', 'width=' + w + ',height=' + h + ',scrollbars=yes');// + (w <= 1280 ? ',fullscreen=yes' : ''));

	var x = Math.round((screen.availWidth - w) / 2);
	var y = Math.round((screen.availHeight - h) / 2);

	win.moveTo(x >= 0 ? x : 0, y >= 0 ? y : 0);

	win.focus();
}