// mozdelphi_whatsnew.js
// JavaScript functions used for displaying Mozilla-Delphi Project What's New
// Reads them directly from rss feed mozilla_delphi_project.xml
// Written by Dave Murray. Copyright (c) 2004 Conspiracy Software


// function loadXML(xmlFile) - Loads XML document (RSS)
// function processRSS(noItems) - Processes RSS document


var xmlDoc;


function loadXML(xmlFile) {
// loads XML document - RSS
  if ((typeof document.implementation == "object") && (typeof document.implementation.createDocument == "function"))
    // Mozilla based browser
    xmlDoc = document.implementation.createDocument("", "", null);
  else 
    // assume IE
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async = false;
  xmlDoc.load(xmlFile);
  }


function processRSS(noItems) {
// processes RSS document
  if (window.opera) {
    // Opera browser doesn't support a way to load XML
    document.writeln("<p style='text-align: left'>");
    document.writeln("This feature requires a function not supported by Opera. ");
    document.writeln("Please request they implement <code>document.load()</code> in their ");
    document.writeln("<a href='http://my.opera.com/forums/forumdisplay.php?forumid=24'>Wishlist Forum</a>.");
    document.writeln("<br />(It works in IE and Mozilla based browsers!)");
    document.writeln("</p>");
    }
  else {
    loadXML("mozilla_delphi_project.xml");
    var i = 0;
    // get rss node first
    var RSS = xmlDoc.getElementsByTagName("rss");
    // get channel nodes
    var rssChannels = RSS[0].getElementsByTagName("channel");
    while (i < rssChannels.length) {
      // iterate through channels
      var itm = 0;
      document.writeln("<ul class='infoItems'>");
      // item nodes
      var rssItems = rssChannels[i].getElementsByTagName("item");
      if (noItems > rssItems.length) {
        noItems = rssItems.length;
        }
      while (itm < noItems) {
        // iterate through noItems items
        // title + link nodes
        var iTitle = rssItems[itm].getElementsByTagName("title")[0].firstChild.nodeValue;
        var iLink = rssItems[itm].getElementsByTagName("link")[0].firstChild.nodeValue;
        document.writeln("<li class='infoItems'>");
        // description node
        var iDesc = rssItems[itm].getElementsByTagName("description")[0].firstChild.nodeValue;
        document.writeln(iDesc);
        // optional pubDate node
        if (rssItems[itm].getElementsByTagName("pubDate")[0] != null) {
          var iPubDate = rssItems[itm].getElementsByTagName("pubDate")[0].firstChild.nodeValue;
          document.writeln("<br />" + iPubDate.slice(0,11));
          }
        document.writeln("</li>");
        itm++;
        }
      i++;
      }
    }
  }


