var showDebug = 0;					// Use 1 to show debug information (requires a DIV with id="debug")
var latestNewsXMLHTTP;
var latestNewsPath = "latestnews";

function showLatestNews(numItems)
{
	latestXMLHTTP = getXmlHttpObject();
	if (latestXMLHTTP == null)
	{
		alert("Unable to retrieve latest news items.");
		return;
	}

	var url = latestNewsPath + "/showlatestnews.php?numItems=" + numItems;
	latestXMLHTTP.onreadystatechange = latestNewsStateChanged;
	latestXMLHTTP.open("GET", url, true);
	latestXMLHTTP.send(null)

	debugTrace(url);
}

function latestNewsStateChanged()
{
	if (latestXMLHTTP.readyState == 4)
	{
		document.getElementById("latestNews").innerHTML = latestXMLHTTP.responseText;
	}
}

function getXmlHttpObject()
{
	// code for IE7+, Firefox, Chrome, Opera, Safari
	if (window.XMLHttpRequest)
	  	return new XMLHttpRequest();
	// code for IE6, IE5
	else if (window.ActiveXObject)
  		return new ActiveXObject("Microsoft.XMLHTTP");
	else
		return null;
}


function showLatestNewsPopup(type, id)
{
	var title = "latestnews";
	var url = latestNewsPath + "/showlatestnewspopup.php?itemtype=" + type + "&itemid=" + id;
	debugTrace(url);

	var width = 800;
	var height = 600;
	var left = (screen.width/2)-(width/2);
	var top = (screen.height/2)-(height/2);
	var params = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width='+width+', height='+height+', top='+top+', left='+left;
	var targetWin = window.open(url, title, params);
	targetWin.focus();
}

function debugTrace(msg)
{
	if (showDebug == 0)
		return;

	document.getElementById("debug").innerHTML = msg
}

