function getXmlHttp()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Your browser does not support XMLHTTP!");
	}
	
	return xmlhttp;
}

function getAppInfo(stub, format)
{
	var xmlhttp = getXmlHttp();
	
	document.write("<div id=\"appinfo-" + stub + "\"></div>");
	
	xmlhttp.onreadystatechange =	function()
									{
										if (xmlhttp.readyState == 4)
										{
											var elem = document.getElementById("appinfo-" + stub);
											elem.innerHTML = xmlhttp.responseText;
										}
									};
	
	xmlhttp.open("GET","http://forums.toucharcade.com/includes/appinfo/appinfo.php?stub=" + stub + "&format=" + format,true);
	xmlhttp.send(null);
}

function getAppInfoById(id, format)
{
	var xmlhttp = getXmlHttp();
	
	document.write("<div id=\"appinfo-" + id + "\"></div>");

	xmlhttp.onreadystatechange =	function()
									{
										if (xmlhttp.readyState == 4)
										{
											var elem = document.getElementById("appinfo-" + id);
											elem.innerHTML = xmlhttp.responseText;
										}
									};
	xmlhttp.open("GET","http://forums.toucharcade.com/includes/appinfo/appinfo.php?id=" + id + "&format=" + format,true);
	xmlhttp.send(null);
}

function getAppInfoByUrl(url, format)
{
	var match = url.match(/id(\d{9})/);

	if (!match)
	{
		var match = url.match(/id=(\d{9})/);
		id = match[1];
	}

	id = match[1];

	getAppInfoById(id, format);
}

function appshotshow(appleid, index)
{
	for (var i = 0; i < 100; i++)
	{
		var elem = document.getElementById("appshot_" + appleid + "_" + i);
		if (elem == null) break;
		
		if (i == index) elem.style.display = "inline";
		else elem.style.display = "none";
	}
	
	var caption = "Screenshot " + (index + 1) + " of " + i;
	elemcap = document.getElementById("appshotcaption_" + appleid);
	elemcap.innerHTML = caption;
}

function appshotnext(appleid)
{
	var index = 0;
	
	for (var i = 0; i < 100; i++)
	{
		var elem = document.getElementById("appshot_" + appleid + "_" + i);
		if (elem == null) break;
		
		if (elem.style.display == "inline") index = i;
	}
	
	if (++index == i) index = 0;

	appshotshow(appleid,index);
}

function appshotprev(appleid)
{
	var index = 0;
	
	for (var i = 0; i < 100; i++)
	{
		var elem = document.getElementById("appshot_" + appleid + "_" + i);
		if (elem == null) break;
		
		if (elem.style.display == "inline") index = i;
	}
	
	if (--index == -1) index = i - 1;
	
	appshotshow(appleid,index);
}