// pn_current_issue.js v2.0
// JavaScript for displaying Pascal Newsletter current issue contents
// Written by Dave Murray. Copyright (c) 2004 Conspiracy Software

// function loadXML(xmlFile) - Loads XML document (RSS)
// function PNTitle() - displays title of RSS channel
// function PNContents() - displays contents of current issue from RSS


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 PNTitle(){
  // displays title of RSS channel
  if (window.opera) {
    // Opera browser doesn't support a way to load XML
    document.writeln(" ");
    }
  else {
    //first RSS function so load XML
    loadXML("pascal_newsletter.xml");
    // get rss node
    var RSS = xmlDoc.getElementsByTagName("rss");
    // get title + link nodes
    var pnTitle = RSS[0].getElementsByTagName("title")[0].firstChild.nodeValue;
    var pnLink = RSS[0].getElementsByTagName("link")[0].firstChild.nodeValue;
    document.writeln("<a href='" + pnLink + "'>" + pnTitle + "</a>");
    }
  }

function PNContents(){
  // displays contents of current issue from RSS
  if (window.opera) {
    // Opera browser doesn't support a way to load XML
    document.writeln("<p>");
    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("</p>");
    }
  else {
    var itm = 0;
    // get rss node first
    var RSS = xmlDoc.getElementsByTagName("rss");
    // get channel node
    var rssChannels = RSS[0].getElementsByTagName("channel");
    // iterate through items, except last one (source)
    var rssItems = rssChannels[0].getElementsByTagName("item");
    document.writeln("<div class='rssChannel'>");
    document.writeln("<dl class='rssItem'>");
    while (itm < rssItems.length) {
      // title, link + description nodes
      var iTitle = rssItems[itm].getElementsByTagName("title")[0].firstChild.nodeValue;
      var iLink = rssItems[itm].getElementsByTagName("link")[0].firstChild.nodeValue;
      var iDesc = rssItems[itm].getElementsByTagName("description")[0].firstChild.nodeValue;
      document.writeln("<dt class='rssItem'>");
      document.writeln("<a href='" + iLink + "'>" + iTitle + "</a>");
      document.writeln("</dt>");
      document.writeln("<dd class='rssItem'>");
      document.writeln(iDesc);
      document.writeln("</dd>");
      itm++;
      }
      document.writeln("</dl>");
      document.writeln("</div>");
    }
  }
