// File: readXML.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 

	// Open the xml file
	$.get("/de/memo/counter.xml",{},function(xml){
	
		// Build an HTML string
		myHTMLOutputEN = '';
		myHTMLOutputDE = '';

	$('list',xml).each(function(i) {
		listName = $(this).find("name").text();
		listNumber = $(this).find("number").text();
			
		// Build row HTML data and store in string
		//mydata = BuildListHTML(listName,listNumber);
		mydata = getNumber(listName,listNumber);
		if (listName == 'EN') myHTMLOutputEN = myHTMLOutputEN + mydata;
		if (listName == 'DE') myHTMLOutputDE = myHTMLOutputDE + mydata;
	});
		
		// Update the DIV called Content Area with the HTML string
		$("#counter_en").append(myHTMLOutputEN);
		$("#counter_de").append(myHTMLOutputDE);
	});
});
 

function getNumber(listName,listNumber){
	output = addSeperator(listNumber, listName);
	return output;
}

function addSeperator(nStr, diff) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		if (diff == 'EN') x1 = x1.replace(rgx, '$1' + ',' + '$2');
		if (diff == 'DE') x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}

