var g_photoalbums_xmlhttp;
var g_photoalbums_delaytimer = null;

try
{
	g_photoalbums_xmlhttp = new XMLHttpRequest();
}
catch (e)
{
	try
	{
		g_photoalbums_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			g_photoalbums_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			alert("Your browser does not support AJAX!");
		}
	}
}

function photoalbums_get(url, page)
{
	var section = 0;
	var sectionSet = false;
	for (var i = 0; i < 8; i++)
	{
		if (getElementValue(document.forms["photoalbumform"]["s" + i]))
		{
			section |= getElementValue(document.forms["photoalbumform"]["sv" + i])
			sectionSet = true;
		}
	}
	if (!sectionSet)
	{
		section = -1;
	}
	var title = getElementValue(document.forms["photoalbumform"].title);
	var year  = getElementValue(document.forms["photoalbumform"].year);
	g_photoalbums_xmlhttp.open("GET", url + "photoalbums.php?section=" + encodeURIComponent(section) + "&title=" + encodeURIComponent(title) + "&year=" + encodeURIComponent(year) + "&page=" + parseInt(page), true);
	g_photoalbums_xmlhttp.onreadystatechange = function()
	{
		if (g_photoalbums_xmlhttp.readyState == 4)
		{
			var album_container = document.getElementById("albumcontainer");
			album_container.innerHTML = g_photoalbums_xmlhttp.responseText;
		}
	}

	g_photoalbums_xmlhttp.send(null);
}

function photoalbums_get_delayed(url)
{
	clearTimeout(g_photoalbums_delaytimer);
	g_photoalbums_delaytimer = setTimeout("photoalbums_get('" + url + "')", 500);
}

function photoalbums_setsection(section)
{
	if (section)
	{
		var allSet = true;
		for (var i = 1; i < 8; i++)
		{
			if (!getElementValue(document.forms["photoalbumform"]["s" + i]))
			{
				allSet = false;
			}
		}
		setElementValue(document.forms["photoalbumform"].s0, allSet);
	}
	else
	{
		var set = getElementValue(document.forms["photoalbumform"].s0);
		for (var i = 1; i < 8; i++)
		{
			setElementValue(document.forms["photoalbumform"]["s" + i], set);
		}
	}
}
