var req;
var isIE = false;
var en = window.location.href.indexOf("/en/") != -1;

function loadXMLDoc(url) {

    if (window.XMLHttpRequest) {

        req = new XMLHttpRequest();

        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);

    } else if (window.ActiveXObject) {

		isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() {

    if (req.readyState == 4) {
        if (req.status == 200) {
            formatNews();
		} else {
			document.getElementById("news").innerText = req.statusText;
		}
    }
    
}

function loadNews() {
	loadXMLDoc("news.xml");
}

function formatNews() {

	var n = document.getElementById("news");
	var xml = req.responseXML;
	var items = xml.getElementsByTagName("item");
	var html = "<div style=\"margin: 15px\">";
	
	for(i = 0; i < items.length; i++) {
		
		var title = items[i].getElementsByTagName("title");
		var pubDate = items[i].getElementsByTagName("pubDate");
		var desc = items[i].getElementsByTagName("description");
		var link = items[i].getElementsByTagName("link");

		if (isIE) {

			html += "<div class=\"head\">";

			if (pubDate.length > 0) 
				html += "<i>" + pubDate[0].text.substring(5,16) + "</i> - ";
			
			html += title[0].text + "</div>";
			html += "<div class=\"codesection\">";
			
			if (desc.length > 0 && desc[0].text.length > 0)
				html += desc[0].text + "<br />";
				
			html += "<a href=\"" + link[0].text + "\" target=\"_parent\"><img src=\"../../resources/bullet.gif\" class=\"absmiddle\" align=\"middle\" width=\"15\" height=\"15\" alt=\"Go\" border=0/> ";
			
			if (en)
				html += "Go";
			else
				html += "ÏÂÔØ";
				
			html += "</a></div><hr/>";

		} else {

			html += "<div class=\"head\">";
			
			if (pubDate.length > 0) 
				html += "<i>" + pubDate[0].childNodes[0].nodeValue.substring(5,16) + "</i> - ";
			
			html += title[0].childNodes[0].nodeValue + "</div>";
			html += "<div class=\"codesection\">";
			
			if (desc.length > 0 && desc[0].childNodes.length > 0)
				html += desc[0].childNodes[0].nodeValue + "<br />";
				
			html += "<a href=\"" + link[0].childNodes[0].nodeValue + "\" target=\"_parent\"><img src=\"../../resources/bullet.gif\" class=\"absmiddle\" align=\"middle\" width=\"15\" height=\"15\" alt=\"Go\" border=0/> ";
			
			if (en)
				html += "Go";
			else
				html += "ÏÂÔØ";
				
			html += "</a></div><hr/>";
			
		}
		
	}
	
	html += "</div>";
	
	n.innerHTML = html; 
	
}

window.onload = loadNews;
