// Initilise variable
i = 0;  
var xmlDoc;
var xmlFile = "XML/MessageBox.xml";
var move;

function xmldata(move1)
{
	move = move1;	
	if (window.ActiveXObject)
	{			
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.onreadystatechange = verify;
		xmlDoc.load(xmlFile);	
		ReadData();							
	}
	else if (document.implementation && document.implementation.createDocument)
	{				
		xmlDoc = document.implementation.createDocument("", "", null);		
		xmlDoc.onload = ReadData;								
		xmlDoc.load(xmlFile);															
	}
	else				
		alert('Your browser cannot handle this script');		
}	

function ReadData()
{	
	xmlobj = xmlDoc.documentElement;	
	var len = xmlobj.childNodes.length;	
	var x = xmlDoc.getElementsByTagName("project");	
	
	/*alert("List");
	alert(x.documnetElement);
	for (i=0;i<x.length;i++)
	{
		alert(i);
		for (j=0;j<x[i].childNodes.length;j++)
		{
			alert(j);
			if (x[i].childNodes[j].nodeType != 1) continue;		
			alert( x[i].childNodes[0].firstChild.nodeValue );
		}				
	}	*/
	
	if (move == 0)
	{				
		// At Page Load
		document.getElementById("next").style.cursor = "Pointer";
		document.getElementById("pre").style.cursor = "Auto";		
		document.getElementById("txtComment").value = xmlobj.childNodes(0).childNodes(1).text;	
		//document.getElementById("txtComment").value = x[0].childNodes[1].nodeValue;		
	}
	else if (move == 1)
	{		
		// To Move Next
		document.getElementById("next").style.cursor = "Pointer";
		i++;
		if (i < len)
		{				
			document.getElementById("txtComment").value = xmlobj.childNodes(i).childNodes(1).text;					
			document.getElementById("next").style.cursor = "Pointer";
			document.getElementById("pre").style.cursor = "Pointer";
			if (i == (len-1))
			{
				document.getElementById("next").style.cursor = "Auto"; 
				document.getElementById("pre").style.cursor = "Pointer";
			}
		}
		
		if (i == len)
		{
			document.getElementById("next").style.cursor = "Auto";
			document.getElementById("pre").style.cursor = "Pointer";
			document.getElementById("txtComment").value = xmlobj.childNodes(len-1).childNodes(1).text;					
		}
		
		if (i > len)
		{	
			document.getElementById("next").style.cursor = "Auto";
			document.getElementById("pre").style.cursor = "Pointer";
			//alert("No Further Record");										
		}							
	}	
	else if (move == 2)
	{
		// To Move Previous
		document.getElementById("pre").style.cursor = "Pointer";
		i--;
		if (i < 0)
		{
			i++;
			document.getElementById("pre").style.cursor = "Auto";
			document.getElementById("next").style.cursor = "Pointer";
			//alert("No Further Record");					
		}
		else if (i == 0)
		{
			document.getElementById("pre").style.cursor = "Auto";
			document.getElementById("next").style.cursor = "Pointer";
			document.getElementById("txtComment").value = xmlobj.childNodes(0).childNodes(1).text;
		}
		else if (i == len)
		{
			i--;i--;
			document.getElementById("next").style.cursor = "Auto";
			document.getElementById("txtComment").value = xmlobj.childNodes(i).childNodes(1).text;
		}
		else if (i > len)
		{
			i = (len-2);
			document.getElementById("next").style.cursor = "Auto";
			document.getElementById("txtComment").value = xmlobj.childNodes(i).childNodes(1).text;							
		}
		else
		{
			document.getElementById("pre").style.cursor = "Pointer";
			document.getElementById("next").style.cursor = "Pointer";
			document.getElementById("txtComment").value = xmlobj.childNodes(i).childNodes(1).text;					
		}				
	}
}

function verify()
{
	if (xmlDoc.readyState != 4)
		return false;
}