var Page = new function()
{
	var autoScrollInterval;
	var autoScrollAmount = 0;
	var autoScrollTarget = null;
	this.onAutoScroll = '';

	this.insertAfter = function(parent, node, referenceNode)
	{
		parent.insertBefore(node, referenceNode.nextSibling);
	}

	this.getElementsByClass = function(searchClass, node, tag)
	{
		var classElements = new Array();
		if (node == null)
			node = document;
		if (tag == null)
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++)
		{
			if (pattern.test(els[i].className))
			{
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

	this.setAutoScroll = function(amt, target)
	{
		if (amt == autoScrollAmount && target == autoScrollTarget)
			return;

		if (autoScrollInterval != null)
		{
			clearInterval(autoScrollInterval);
			autoScrollInterval = null;
		}

		autoScrollAmount = amt;
		autoScrollTarget = target;

		if (amt == 0)
			return;

		autoScrollInterval = setInterval('Page.doAutoScroll()', 20);
	}

	this.doAutoScroll = function()
	{
		if (autoScrollAmount == 0)
		{
			clearInterval(autoScrollInterval);
			autoScrollInterval = null;
			return;
		}

		if (autoScrollTarget != null && ((autoScrollAmount > 0 && Page.getScrollXY()[1] + autoScrollAmount >= autoScrollTarget) || (autoScrollAmount < 0 && Page.getScrollXY()[1] + autoScrollAmount <= autoScrollTarget)))
		{
			window.scrollBy(0, autoScrollTarget - Page.getScrollXY()[1]);
			Page.setAutoScroll(0);
		}
		else
			window.scrollBy(0, autoScrollAmount);

		if (Page.onAutoScroll != "")
			eval(Page.onAutoScroll);
	}

	this.getWindowSize = function()
	{
		var w = 0;
		var h = 0;
	
		if (typeof(window.innerWidth) == 'number')
		{
			w = window.innerWidth;
			h = window.innerHeight;
		}
		else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		else if (document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		else
			return false;
	
		return [w, h];
	}

	this.getScrollXY = function()
	{
		var x = 0;
		var y = 0;
	
		if(typeof(window.pageYOffset) == 'number')
		{
			x = window.pageXOffset;
			y = window.pageYOffset;
		}
		else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
		{
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
		{
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
	
		return [x, y];
	}

	this.showError = function(str, xmlhttp)
	{
		if (xmlhttp)
		{
			if (xmlhttp.status != 200)
			{
				str += "\n\nStatus: " + xmlhttp.status;
			}
			else if (xmlhttp.responseXML.getElementsByTagName('error').length > 0)
			{
				str += "\n\nDetails: " + xmlhttp.responseXML.getElementsByTagName('error')[0].firstChild.data;
			}
		}
		alert("Error! " + str);
	}
}
