// JavaScript Document

function leggi_news()	{

var Mostra = "";
// Feed RSS - BBC Sport
URI="http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/tennis/rss.xml";

if(window.ActiveXObject) {
		var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		while(xmlDoc.readyState!=4) document.write('Loading...');
	}
	else if(document.implementation&&document.implementation.createDocument)
		xmlDoc=document.implementation.createDocument("","doc",null);
	xmlDoc.load(URI);
	items=xmlDoc;

function verify() {if(xmlDoc.readyState!=4) return false;}

function formatRSS() {
		var items_count=items.getElementsByTagName('item').length;
		var pubDate=new Array(), date=new Array, link=new Array(), title=new Array(), description=new Array(), guid=new Array();

		for(var i=0; i<items_count; i++) {
			if(items.getElementsByTagName('item')[i].getElementsByTagName('pubDate').length==1)
				pubDate[i]=items.getElementsByTagName('item')[i].getElementsByTagName('pubDate')[0];
			if(items.getElementsByTagName('item')[i].getElementsByTagName('dc:date').length==1)
				date[i]=items.getElementsByTagName('item')[i].getElementsByTagName('dc:date')[0];
			if(items.getElementsByTagName('item')[i].getElementsByTagName('link').length==1)
				link[i]=items.getElementsByTagName('item')[i].getElementsByTagName('link')[0];
			if(items.getElementsByTagName('item')[i].getElementsByTagName('guid').length==1)
				guid[i]=items.getElementsByTagName('item')[i].getElementsByTagName('guid')[0];
			if(items.getElementsByTagName('item')[i].getElementsByTagName('title').length==1)
				title[i]=items.getElementsByTagName('item')[i].getElementsByTagName('title')[0];
			if(items.getElementsByTagName('item')[i].getElementsByTagName('description').length==1)
				description[i]=items.getElementsByTagName('item')[i].getElementsByTagName('description')[0];
		}//chiude il for
if((description.length==0)&&(title.length==0)) return false;

		Mostra += "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
		Mostra += "<tbody>"

		Mostra += "<tr>"
		Mostra += "<td id='news_title_left'>&nbsp;</td>"
		Mostra += "<td><table id='news_title'  width='100%' border='0'><tr><td id='title_font'><img src='../../../images/news_by.jpg'></td><td height='60px'>&nbsp;</td></tr></table></td>"
		Mostra += "<td id='news_title_img' width='125px'><a href='" + xmlDoc.getElementsByTagName('image/link')[0].firstChild.nodeValue +"' target='_blank'><img id='bbc_logo' src='" +xmlDoc.getElementsByTagName('url')[0].firstChild.nodeValue +"'></a></td>"
		Mostra += "</tr>"
		Mostra += "<tr>"
		Mostra += "<td >&nbsp;</td>"
		Mostra += "<td><a name='top'>&nbsp;</a></td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "</tr>"
		Mostra += "<tr>"
		Mostra += "<td >&nbsp;</td>"
		Mostra += "<td id='news_title_update'>last update:   "+xmlDoc.getElementsByTagName('lastBuildDate')[0].firstChild.nodeValue+"</td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "</tr>"
		
		Mostra += "<tr>"
		Mostra += "<td >&nbsp;</td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "</tr>"
		/*Mostra += "<tr>"
		Mostra += "<td id='ico'>&nbsp;</td>"
		Mostra += "<td>"+xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue+"</td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "</tr>"
		Mostra += "<tr>"
		Mostra += "<td id='ico'>&nbsp;</td>"
		Mostra += "<td>"+xmlDoc.getElementsByTagName('link')[0].firstChild.nodeValue+ " " + xmlDoc.getElementsByTagName('description')[0].firstChild.nodeValue+"</td>"
		Mostra += "<td>&nbsp;</td>"
		Mostra += "</tr>"*/
		
		
		
		//document.write('<html><head><title>'+xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue+'</title></head><body>');
		//document.write('<span style="font-family:verdana,arial,helvetica; font-size:8pt">');
		//document.write('<center><a href="rss-reader.htm"><h3>[Go Back]</h3></a></center>');
		//document.write('<center><a href="'+xmlDoc.getElementsByTagName('link')[0].firstChild.nodeValue+'"><h2>'+xmlDoc.getElementsByTagName('description')[0].firstChild.nodeValue+'</h2></a></center>');
		var ws=/\S/;

		for(var i=0; i<items_count; i++) {
			var pubDate_w, title_w, link_w;
			pubDate_w=(pubDate.length>0)?pubDate[i].firstChild.nodeValue:"<i>Date NA</i>";
			if(document.all)
				title_w=(title.length>0)?title[i].text:"<i>Untitled</i>";
			else
				title_w=(title.length>0)?title[i].firstChild.nodeValue:"<i>Untitled</i>";

			link_w=(link.length>0)?link[i].firstChild.nodeValue:"";
			if(link.length==0) link_w=(guid.length>0)?guid[i].firstChild.nodeValue:"";
			if(title.length>0) title_w=(!ws.test(title_w))?"<i>Untitled</i>":title_w;
			if(pubDate.length==0) pubDate_w=(date.length>0)?date[i].firstChild.nodeValue:"<i>Date NA</i>";
			//document.write('<a href="'+link_w+'"><b>'+title_w+'</b></a> <b>['+pubDate_w+']</b><br>');
				Mostra += "<tr>"
				Mostra += "<td align='center' id='ico'><img id='img_ico' src='../../../images/icone/news.ico'></td>"
				Mostra += "<td id='news_link'><a href='" +link_w+ "' target='_blank'>" +title_w+"</a></td>"
				Mostra += "<td id='news_date'>["+pubDate_w+"]</td>"
				Mostra += "</tr>"
			if(description.length>0)
				Mostra += "<tr>"
				Mostra += "<td id='sub_ico'>&nbsp;</td>"
				Mostra += "<td id='news_desc'><p>"+description[i].firstChild.nodeValue+"</p></td>"
				Mostra += "<td id='news_desc'>&nbsp;</td>"
				Mostra += "</tr>"
				Mostra += "<tr>"
				Mostra += "<td ><hr></td>"
				Mostra += "<td><hr></td>"
				Mostra += "<td><hr></td>"
				Mostra += "</tr>"
				//document.write('<font size="-1">'+description[i].firstChild.nodeValue+'</font><hr noshade><br>');
		}//chiude for
		
		
		Mostra += "<tr>"
		Mostra += "<td id='left_footer'>&nbsp;</td>"
		Mostra += "<td id='news_link_footer'><a href='" +xmlDoc.getElementsByTagName('link')[0].firstChild.nodeValue+ "' target='_blank'>" +xmlDoc.getElementsByTagName('title')[0].firstChild.nodeValue+ " - " +xmlDoc.getElementsByTagName('description')[0].firstChild.nodeValue +"</a></td>"
		Mostra += "<td align='right' id='news_link_footer'><a href='#top'><img border='0' src='../../../images/icone/up.ico'></a></td>"
		Mostra += "</tr>"
		Mostra += "</tbody>"
		Mostra += "</table>"
		//document.write('</span></body></html>');
	}//chiude formatRSS()

	if(typeof(xmlDoc)!="undefined") {
		if(window.ActiveXObject) formatRSS();
		else xmlDoc.onload=formatRSS;
	}//chiude if
	
news_bbc.innerHTML = Mostra;
}
// ************* MAIN **********************************************
leggi_news();

