// Name and Path to XML-data
var strXMLName = "./data/upload.xml";
// create Global xmlDoc
var xmlDoc = null;
// current type
var nCurrentType = -1;

function InitData()
{
	// only load xml-Document through initializaion - Nodelist will be loaded in FillList()
	xmlDoc = LoadXMLDoc( strXMLName );
	if( xmlDoc == null )
	{
		alert( 'Error creating/loading XML-Doc: ' + strXMLName );
	}
}

function FillList( nType, strFilter )
{
	// no xml-Data loaded
	if( xmlDoc == null )
	{
		return false;
	}
	
	nCurrentType = nType;

	// build XPath dependend on Type and Filter
	// -> currently no filter supported
	// -> type fix on 'public changes'
	var strXPath = "/dataroot/upload[ nType = '0' ]";

	var xmlNodelist = SelectNodes( xmlDoc, strXPath );
	if( xmlNodelist == null )
	{
		return true;
	}

	// get needed HTML-Elements
	var htmlTable = document.getElementById( 'tablebody' );
	

	// first delete dynamic created rows (don't delete header!)
	var htmlRows = htmlTable.getElementsByTagName("tr");
	var nRows = htmlRows.length;
	for( i = nRows - 1; i > 0; i-- )
	{
		// delete reverse
		htmlTable.removeChild( htmlRows[i] );
	}
	
	var htmlHeader = document.getElementById( 'headerrow' );
	if( htmlTable == null || htmlHeader == null )
	{
		return true;
	}

	// now fill list
	nRows = xmlNodelist.length;
	for( i = 0; i < nRows; i++ )
	{
		// get Event-Data from Node
		var xmlUpload = xmlNodelist[i];
		
		// create new HTML-Row (clone from header)
		var htmlRow = htmlHeader.cloneNode(true);

		// append to Table before first access - otherwise IE won't work fine
		htmlTable.appendChild( htmlRow );

		if( i % 2 )
		{
			htmlRow.className = 'hatched1';
		}
		else
		{
			htmlRow.className = 'hatched2';
		}
		
		var nCol = 0;
		var htmlCols = htmlRow.getElementsByTagName("td");
		
		// Date of change
		htmlCols[nCol++].innerHTML = FormatDate( NodeText( SelectSingleNode( xmlUpload, 'date') ) );
		// Description of change
		htmlCols[nCol++].innerHTML = NodeText( SelectSingleNode( xmlUpload, 'strDescription') );

		// set unique id
		htmlRow.id = 'row' + i;
	}
}

