window.onload = init;

var objXHR;

function init()
{
	var objAnchor;

	if (!document.getElementById ||
		!document.createTextNode ||
		(typeof XMLHttpRequest == 'undefined' && !ActiveXObject))
	{
		return;
	}

	objAnchor = document.getElementById('feature');

	if (objAnchor)
	{
		// Assign an event handler to intercept the standard behaviour
		objAnchor.onclick = function(){return updateContent();};
	}
}

function processResult()
{
	var strResult, objCurrent, objReplacement, objContent;

	if (objXHR.readyState == 4) // Loaded
	{
		if (objXHR.status == 200) // OK
		{
			// Get the response
			strResult = objXHR.responseText;

			objCurrent = document.getElementById('update');

			// Setup a paragraph containing the response
			objReplacement = document.createElement('p');
			objReplacement.setAttribute('id', 'update');
			objReplacement.appendChild(document.createTextNode(strResult));

			// If another reponse already exists in the DOM, replace it;
			// otherwise, append the response.
			if (objCurrent)					
			{
				objCurrent.parentNode.replaceChild(objReplacement, objCurrent);
			}
			else
			{
				objContent = document.getElementById('content');
				objContent.appendChild(objReplacement);
			}
		}
	}
}

function updateContent()
{
	// Create an instance of the XMLHttpRequest object
	objXHR = window.XMLHttpRequest ?
	  new XMLHttpRequest() : 
	  new ActiveXObject("MSXML2.XMLHTTP.3.0");

	if (objXHR)
	{
		// Setup the request object
		objXHR.onreadystatechange = processResult;
		objXHR.open('GET', 'feature.php', true);
		objXHR.send(null);
	}

	// Cancel the default behaviour of the link
	return false;
}

