
var isIE = false;
var req;
var newsCount = 10;

function displayRssNews()
{
	//Feed Name
	document.getElementById("whichFeed").innerHTML = '<small><a href="' + req.responseXML.getElementsByTagName("link")[0].firstChild.nodeValue + '">' + req.responseXML.getElementsByTagName("title")[0].firstChild.nodeValue + '<\/a><\/small>';
	//Feed Date
	document.getElementById("feedDate").innerHTML = '<small>' + req.responseXML.getElementsByTagName("lastBuildDate")[0].firstChild.nodeValue + '<\/small>';
	
	//Get the Items array
	items = req.responseXML.getElementsByTagName("item");
	
    //alert(document.getElementById("feedDate").innerHTML);
 	if (document.getElementById) {
			
	    var strHtml = "";
	    
	    for(var i = 0; i < items.length && i < newsCount; i++) {
	       strHtml = strHtml + "<li>"
	                              + "<a id=\"rssAnchor\" href=\""
	                              + getElementTextNS("", "link", items[i], 0)
	                              + "\">"
	                              +  getElementTextNS("", "title", items[i], 0)
	                              + "<\/a>"
	                         + "</li>";	                         
	    }
	    document.getElementById("rrsNews").innerHTML = strHtml;
		}
}



function loadXMLDoc(url, count) {
    newsCount = count;
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

// handle onreadystatechange event of req object
function processReqChange() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			displayRssNews();
		} else {
			// Stop displaying loading flag
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}



// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
	var result = "";
	if (prefix && isIE) {
		// IE/Windows way of handling namespaces
		result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
	} else {
		// the namespace versions of this method
		// (getElementsByTagNameNS()) operate
		// differently in Safari and Mozilla, but both
		// return value with just local name, provided
		// there aren't conflicts with non-namespace element names
		result = parentElem.getElementsByTagName(local)[index];
	}
	if (result) {
		// get text, accounting for possible
		// whitespace (carriage return) text nodes
		if (result.childNodes.length > 1) {
			return result.childNodes[1].nodeValue;
		} else {
			return result.firstChild.nodeValue;
		}
	} else {
		return "n/a";
	}
}
