function getXmlHttpRequestObject()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
	}
}

var xml_request = getXmlHttpRequestObject();

function go_to_page(page)
{
	var page_url = document.location.search.split("&pn=");
	document.location.search = page_url[0] + "&pn=" + page;
}

function get_page_size()
{
	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;
	}
	
	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;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	}
	else
	{
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

	return arrayPageSize;
}

function activate_theme(theme)
{
	var i, a, main;

	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			a.disabled = true;

			if(a.getAttribute("title") == theme)
			{
				a.disabled = false;
			}
		}
	}
}

function select_theme(theme)
{
	// turn on the mask
	document.getElementById('mask').className = "mask_on";

	// write to the popup message div
	document.getElementById('popup_message').innerHTML = "<h3>Changing Theme</h3><p>You are about to change the theme to the "+theme+" one.</p><p>Would you also like to remember this theme and use it every time you visit this site?</p><p><br /><br /><input type=\"button\" name=\"btn_no\" onclick=\"set_theme('"+theme+"', false);\" value=\"No\" /> <input type=\"button\" name=\"btn_yes\" onclick=\"set_theme('"+theme+"', true);\" value=\"Yes\" /></p>";

	// show the popup message
	document.getElementById('popup_message').className = "visible";
}

function set_theme(theme, remember)
{
	activate_theme(theme);

	if(remember === true)
	{
		var url = "save_theme.php?theme="+theme+"&remember=yes";
	}
	else
	{
		var url = "save_theme.php?theme="+theme;
	}

	if (xml_request.readyState == 4 || xml_request.readyState == 0)
	{
		xml_request.open("GET", url, true);
		xml_request.send(null);
	}

	// hide the popup message
	document.getElementById('popup_message').className = "hidden"

	// turn off the mask
	document.getElementById('mask').className = "mask_off";
}