///////////////////////////////////
// RSS feed processor for DM2003 //
///////////////////////////////////

// Builds div id="rssblock" from RSS XML file (assigns ul filled with news)

var xmlhttp;

var xmllinks=""; // set to "?print" to hide navigation in minibrowser

function loadXMLDoc() // called from body onload=...
{

var PHREF=window.location.href; 
var nav=navigator.userAgent;

if ((PHREF.indexOf('ile://')>0) || (nav.indexOf('MSIE 4')>0)) // local or msie4
  {
//alert(PHREF.substring(0, PHREF.lastIndexOf("/")+1)); return;
  myxml=new ActiveXObject("MSXML"); // as in updatejs.vbs
//  myxml.URL="rss.xml"; <- wrong - error in MSIE4!!!
  myxml.URL=PHREF.substring(0, PHREF.lastIndexOf("/")+1)+"rss.xml";
//alert(myxml.root.children.length);
  cc=myxml.root.children.item("channel")
  ic=cc.children.item("item")
//alert(ic.length);

  txt="<ul>";

  for (i=0; i<ic.length && i<8; i++)
  {
  ii=ic.item(i);

  dd=ii.children.item("title");
  titl=dd.text;
  dd=ii.children.item("link");
  lin=dd.text;

// remove path for local news browsing...
  if (lin!="http://www.datamaster2003.com/news.html")
     { lin=lin.substring(lin.lastIndexOf("/")+1, lin.length); }

  dd=ii.children.item("pubDate");
  dat=dd.text;
  dd=ii.children.item("description");
  desc=dd.text;
  
// make LI
  if (lin=="http://www.datamaster2003.com/news.html")
    {
    txt=txt + "<li><b>" + titl + "</b> (" + dat + ")<br>" + desc + "<br><br></li>";
    } else
    {
    txt=txt+"<li><b><a href='"+lin+xmllinks+"'>"+titl+"</a></b> ("+dat+")<br>"+desc+"<br><br></li>";
    };

  }; // for

  txt=txt + "</ul>";
  if (nav.indexOf('MSIE 4')>0) // fix bug in MSIE4!!!
  { rssblock.innerHTML=txt; } else 
  { document.getElementById('rssblock').innerHTML=txt; };
  return;
  }; // if local...


///////////////// the rest is based on the script found on the internet /////////////////////////

xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for IE7, Firefox, Mozilla, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE5, IE6
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=onResponse;
  xmlhttp.open("GET","http://www.datamaster2003.com/rss.xml",true); // only URL!!!
  xmlhttp.send(null);
  }
else
  {
  document.getElementById('rssblock').innerHTML="<b>Error</b>: your browser does not support XMLHTTP!";
  }
} // function loadXMLDoc()

function onResponse()
{
if(xmlhttp.readyState!=4) return;
if(xmlhttp.status!=200)
  {
  document.getElementById('rssblock').innerHTML="<b>Error</b>: unable to retrieve XML data!";
  return;
  }

txt="<ul>";

x=xmlhttp.responseXML.documentElement.getElementsByTagName("item");
for (i=0; i<x.length && i<8; i++)
  {

//title
  xx=x[i].getElementsByTagName("title");

//// warning!!! try - catch incompatible with MSIE4 
//// and other old browsers while giving really little protection!!!

//    {
//    try
//      {
      titl=xx[0].firstChild.nodeValue;
//      }
//    catch (er)
//      {
//      titl="XML formatting error!!!";
//      }
//    };
//link 
  xx=x[i].getElementsByTagName("link");
//    {
//    try
//      {
      lin=xx[0].firstChild.nodeValue;
//      }
//    catch (er)
//      {
//      lin="http://www.datamaster2003.com/news.html";
//      }
//    };
//date
  xx=x[i].getElementsByTagName("pubDate");
//    {
//    try
//      {
      dat=xx[0].firstChild.nodeValue;
//      }
//    catch (er)
//      {
//      dat="XML formatting error!!!";
//      }
//    };
//desc
  xx=x[i].getElementsByTagName("description");
//    {
//    try
//      {
      desc=xx[0].firstChild.nodeValue;
//      }
//    catch (er)
//      {
//      desc="XML formatting error!!!";
//      }
//    };

// make LI
  if (lin=="http://www.datamaster2003.com/news.html")
    {
    txt=txt + "<li><b>" + titl + "</b> (" + dat + ")<br>" + desc + "<br><br></li>";
    } else
    {
    txt=txt+"<li><b><a href='"+lin+xmllinks+"'>"+titl+"</a></b> ("+dat+")<br>"+desc+"<br><br></li>";
    };
  }; // end for

txt=txt + "</ul>";
document.getElementById('rssblock').innerHTML=txt;
} // function onResponse()
