// checkComments tests if a comment has been added
// for the demo, the scripts checks if the page is reloaded

function checkComments()
{
	var parameters = location.search.substring(1).split("&");

	var temp = parameters[0].split("=");
	var reloaded = unescape(temp[0]);
	return true;
	//return (reloaded == "submit");	// page loaded by the submit button of a form
}


// processData writes the retrieved values into the page

function processData(doc)
{
	var element = doc.getElementsByTagName('login').item(0);

	document.getElementById("login").innerHTML= element.firstChild.data;
	document.getElementById("comment").innerHTML= doc.getElementsByTagName('comment').item(0).firstChild.data;
	
}

// submitForm is an Ajax script to load the XML file 

function submitForm(doc)
{ 

	var xhr=createXHR();

	xhr.open("GET", doc + "?nocache=" + Math.random(),true);

	xhr.onreadystatechange = function()
	{ 

		if(xhr.readyState == 4)
		{

			if(xhr.status == 200)
			{
				processData(xhr.responseXML);
			}	
			else	
			{
				alert("Error: returned status code " + xhr.status + " " + xhr.statusText);
			}	

		} 
	}; 

	xhr.send(null); 
} 

// assigning a processing to the onload event

window.onload = function()
{
	if(checkComments() == false) return;

	submitForm("demo-comment.xml");
}