$(document).ready(function(){
	$.ajax({
		type: "GET",
		url: "file/news.php",
		cache: false,
		success: xmlParser
	});
});

function xmlParser(xml) {

	var lastDate = 0;
	var date;

	$(xml).find("item").each(function () {

		$(this).children().each(function() {
			if ($(this)[0].tagName == "dc:date") {
				date = '' + $(this).text().match(/^[0-9]{2,4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}/i);
				date = date.replace(/-/g,'/');
				date = date.replace(/T/g,' ');
				date = new Date( date.replace(/-/g,'/') );
			}
		});

		if( lastDate < date.getTime() )  lastDate = date.getTime();
		
	});

	$("#lastupdate").html( '(' + chgDate( new Date(lastDate) ) + ')' );
}


function chgDate( d ){
	yy = d.getYear();
	mm = d.getMonth() + 1;
	dd = d.getDate();
	ho = d.getHours();
	mi = d.getMinutes();
	
	if (yy < 2000) { yy += 1900; }
	if (mm < 10) { mm = "0" + mm; }
	if (dd < 10) { dd = "0" + dd; }
	if (ho < 10) { ho = "0" + ho; }
	if (mi < 10) { mi = "0" + mi; }

	return yy + "/" + mm + "/" + dd + ' ' + ho + ':' + mi;
}


