function showrecentposts(xmlfilename) {

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    
function loadXML(xmlFile)
    {
        xmlDoc.async="false";
        xmlDoc.onreadystatechange=verify;
        xmlDoc.load(xmlFile);
        xmlObj=xmlDoc.documentElement;
    }

function verify()
    {
        // 0 Object is not initialized
        // 1 Loading object is loading data
        // 2 Loaded object has loaded data
        // 3 Data from object can be worked with
        // 4 Object completely initialized
        if (xmlDoc.readyState != 4)
        {
            return false;
        }
    }

// Load the xml-file
loadXML(xmlfilename);
// check if it is a rss-feed, tagname should be rss
if (xmlObj.tagName != "rss") alert("Error: this XML-file does not contain rss feed");
// check if xml-file has childnodes
if (!xmlObj.hasChildNodes()) alert("Error: rss-feed is empty");
// get rss-feed from tag channel
var channelfound = false;
for (var i=0;i<xmlObj.childNodes.length;i++) {
  if (xmlObj.childNodes[i].tagName == "channel") {
     var rssfeed = xmlObj.childNodes[i];
     channelfound = true; } }
if (!channelfound) alert("Error: unknown format in rss-feed");
// find all item-tags, and process them
// the item-tag contains the post-data that we need
// title is the post-title
// pubDate is the date the post was published
// link is the link to the post
// description is the post content
var itemfound = false;
var itemcount = 0;
for (var i=0;i<rssfeed.childNodes.length;i++) {
// this loops checks all childNodes of the feed to see if it is an item
// if it is an item, it should be processed, but we may not exceed the numposts limit
  if (rssfeed.childNodes[i].tagName == "item") {
    itemfound="true";
    if (itemcount < numposts) {
      var post = rssfeed.childNodes[i];
      for (var j = 0;j<post.childNodes.length;j++) {
        if (post.childNodes[j].tagName == "title")
          var posttitle = post.childNodes[j].firstChild.text;
        if (post.childNodes[j].tagName == "link") {
          var posturl = post.childNodes[j].firstChild.text;
          posttitle = posttitle.link(posturl);
          var readmorelink="(more)";
          readmorelink=readmorelink.link(posturl);
          }
        if (post.childNodes[j].tagName == "pubDate") 
          var pubdate = post.childNodes[j].firstChild.text.split(" ");
        if (post.childNodes[j].tagName == "description") {
          var content = post.childNodes[j].firstChild.text;
          var re = /<\S[^>]*>/g; 
          content = content.replace(re, "");}
        if (post.childNodes[j].tagName == "atom:summary") {
          var content = post.childNodes[j].firstChild.text;
          var re = /<\S[^>]*>/g;
          content = content.replace(re, "");} }
      itemcount = itemcount + 1;
      document.write('<div class="bbrecpost">' + posttitle);
      if (showpostdate) document.write(' - '+pubdate[0]+' ' + pubdate[1] + ' ' +pubdate[2]+' '+pubdate[3]);
      document.write('</div>');
      if (showpostsummary) {
        document.write('<div class="bbrecpostsum">');
        if (content.length < numchars) {document.write(content);}
        else document.write(content.substring(0,numchars) + '...' + readmorelink);
        document.write('</div>');}
}
  }
}
  document.write('<div class="bbwidgetfooter">');
  document.write('<span style="font-size:80%;">Widget by <a href="http://beautifulbeta.blogspot.com">Beautiful Beta</a></span>');
  document.write('</div>');

}
