var g_feed = 'http://www.mpad.co.uk/blog/?feed=rss2';
//var g_feed = 'http://webwork/glenpike/html/blog/?feed=rss2';


var req = null;
function processReqChange( handler ) {
  if (req.readyState == 4 && req.status == 200 && req.responseXML ) {
    handler( req.responseXML ); 
  }
}

function loadXMLDoc( url, handler ) {
	var doc = document.location.href;
	if(-1 == doc.indexOf("www.") && -1 != url.indexOf("www.")) {
		url = "http://" + url.substring(url.indexOf("www.") + 4);
	}
	//alert(url);
	
  if(window.XMLHttpRequest) {
    try { req = new XMLHttpRequest(); } catch(e) { req = false; }
  }
  else if(window.ActiveXObject)
  {
    try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {
    try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } }
  }

  if(req) {
    req.onreadystatechange = function() { processReqChange( handler ); };
    req.open("GET", url, true);
    req.send("");
  }
}

function parseFeed( dom ) {
	//alert("parseFeed");
  var nl = req.responseXML.getElementsByTagName( 'item' );
	if(0 == nl.length) {
		//alert("parseFeed - no items");
		return;
	}
	var nli = nl.item( 0 ).childNodes;
	var nd = nl.item(0).firstChild;
	for(var j = 0;j < nli.length;j++) {
		if('title' == nd.nodeName && nd.firstChild) { var title = nd.firstChild.nodeValue; }
		if('link' == nd.nodeName && nd.firstChild) { var link = nd.firstChild.nodeValue; }
		if('description' == nd.nodeName && nd.firstChild) { var description = nd.firstChild.nodeValue; }
		if('content:encoded' == nd.nodeName && nd.firstChild) { var content = nd.firstChild.nodeValue; }
		nd = nd.nextSibling;
	}
	
	if(title) {
		var titleBox = document.getElementById('blog-title-container');
		
		var elTitleLink = document.createElement( 'a' );
		elTitleLink.href = link;
		elTitleLink.innerHTML = title;
		elTitleLink.title = title;
		elTitleLink.target = '_self';
		titleBox.innerHTML = '';
		titleBox.appendChild(elTitleLink);
	}
	var contentBox = document.getElementById('blog-item-container');
	
	if(content)	{
		contentBox.innerHTML = content;
	} else {
		contentBox.innerHTML = '';
	}
}