function getRSS()
{
   	 
	alert(2);

	new Ajax.Request('http://twitter.com/statuses/user_timeline/115062245.rss',   
	{     method:'get', 
		//contentType: 'application/xml',  
		onSuccess: function(transport){  
		var response = transport.responseText || "no response text";
		
		if (window.DOMParser)
  		{
  			parser=new DOMParser();
  			xmlDoc=parser.parseFromString(transport.responseText,"text/xml");
  		}
		else // Internet Explorer
  		{
  			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  			xmlDoc.async="false";
  			xmlDoc.loadXML(transport.responseText); 
  		} 
		 
		try{
		rssElement  = xmlDoc.getElementsByTagName("rss")[0];
		channelElement =  rssElement.getElementsByTagName("channel")[0];
		itemElements = channelElement.getElementsByTagName("item");
		var imageTag = "<img id='chan_image'";
			var startItemTag = "<div id='item'>";
    			var startTitle = "<div id='item_title'>";
    			var startDate = "<div id='item_date'>";
    			var startDescription = "<div id='item_description'>";
    			var endTag = "</div>";
		item_html = ""		
		var noElements = 10;

		if (noElements > itemElements.length){
			nOelements = itemElements.length;
		}
		for (var i=0; i< itemElements.length; i++)
    		{	
		
				
			title =  itemElements[i].getElementsByTagName("title")[0].text;
			description = itemElements[i].getElementsByTagName("description")[0].text;
			pubDate = itemElements[i].getElementsByTagName("pubDate")[0].text;
			dateTokens = pubDate.split(" ");
			
			  item_html += startItemTag;
      			  //item_html += (title == null) ? "" : title + endTag;
      			  item_html += (pubDate == null) ? "" : startDate + dateTokens[0] + " " + dateTokens[1]  + " " + dateTokens[2] + " " + dateTokens[3] + endTag;
       			  item_html += (description == null) ? "" : startDescription  + "<p>" +  description + "</p>"  + endTag;
        		  item_html += endTag;
        
		}	
		// <h4>What's New</h4>
		document.getElementById("chan_items").innerHTML += "" + item_html + "";
		
		}
		catch(ex){
			alert(ex.message);
		}		

			  },   
		  onFailure: function(){ alert('An error has occurred reading latest news and specials...') }   }); 


 
}

function showRSS(RSS)
{
    /*A*/
    var imageTag = "<img id='chan_image'";
    var startItemTag = "<div id='item'>";
    var startTitle = "<div id='item_title'>";
    var startLink = "<div id='item_link'>";
    var startDescription = "<div id='item_description'>";
    var endTag = "</div>";

    /*B*/
    var properties = new Array("title","link","description","pubDate","copyright");
    for (var i=0; i<properties.length; i++)
    {
        eval("document.getElementById('chan_"+properties[i]+"').innerHTML = ''"); /*B1*/
        curProp = eval("RSS."+properties[i]);
        if (curProp != null)
            eval("document.getElementById('chan_"+properties[i]+"').innerHTML = curProp"); /*B2*/
    }

    /*C*/
    /*show the image*/
   
   /* document.getElementById("chan_image_link").innerHTML = "";
    if (RSS.image.src != null)
    {
        document.getElementById("chan_image_link").href = RSS.image.link; 
        document.getElementById("chan_image_link").innerHTML = imageTag
            +" alt='"+RSS.image.description
            +"' width='"+RSS.image.width
            +"' height='"+RSS.image.height
            +"' src='"+RSS.image.url
            +"' "+"/>"; 
    }
    */

    /*D*/
    document.getElementById("chan_items").innerHTML = "";
	
    for (var i=0; i<RSS.items.length; i++)
    {
        item_html = startItemTag;
        item_html += (RSS.items[i].title == null) ? "" : startTitle + RSS.items[i].title + endTag;
        item_html += (RSS.items[i].link == null) ? "" : startLink + RSS.items[i].link + endTag;
        item_html += (RSS.items[i].description == null) ? "" : startDescription + "<p>" + RSS.items[i].description +  "</p>" +  endTag;
        item_html += endTag;
        document.getElementById("chan_items").innerHTML += item_html; /*D1*/
    }

    return true;
}

function processRSS(rssxml)
{ 
    var channel = rssxml.getElementsByTagName("channel");
    alert(channel[0].innerHTML);  
    //var channel = rssxml.getElementsByTagName("channel")[0];
    var items = channel.getElementsByTagName("item");
     
	alert(items.length);
    RSS = new RSS2Channel(rssxml);

	alert('showRSS');

     
}

function RSS2Category(catElement)
{
    if (catElement == null) {
        this.domain = null;
        this.value = null;
    } else {
        this.domain = catElement.getAttribute("domain");
        this.value = catElement.childNodes[0].nodeValue;
    }
}

function RSS2Image(imgElement)
{
    if (imgElement == null) {
    this.url = null;
    this.link = null;
    this.width = null;
    this.height = null;
    this.description = null;
    } else {
        imgAttribs = new Array("url","title","link","width","height","description");
        for (var i=0; i<imgAttribs.length; i++)
            if (imgElement.getAttribute(imgAttribs[i]) != null)
                eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
    }
}


function RSS2Item(itemxml)
{
    /*A*/
    /*required properties (strings)*/
    this.title;
    this.link;
    this.description;

    /*optional properties (strings)*/
    this.author;
    this.comments;
    this.pubDate;

    /*optional properties (objects)*/
    this.category;
    this.enclosure;
    this.guid;
    this.source;

    /*B*/
    var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
    var tmpElement = null;
    for (var i=0; i<properties.length; i++)
    {
        tmpElement = itemxml.getElementsByTagName(properties[i])[0];
        if (tmpElement != null)
            eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
    }

    /*C*/
    this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
    this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
    this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
    this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}
function RSS2Item(itemxml)
{
    /*A*/
    /*required properties (strings)*/
    this.title;
    this.link;
    this.description;

    /*optional properties (strings)*/
    this.author;
    this.comments;
    this.pubDate;

    /*optional properties (objects)*/
    this.category;
    this.enclosure;
    this.guid;
    this.source;

    /*B*/
    var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
    var tmpElement = null;
    for (var i=0; i<properties.length; i++)
    {
        tmpElement = itemxml.getElementsByTagName(properties[i])[0];
        if (tmpElement != null)
            eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
    }

    /*C*/
    this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
    this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
    this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
    this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
} 
function RSS2Channel(rssxml)
{
    /*A*/
    /*required string properties*/
    this.title;
    this.link;
    this.description;

    /*optional string properties*/
    this.language;
    this.copyright;
    this.managingEditor;
    this.webMaster;
    this.pubDate;
    this.lastBuildDate;
    this.generator;
    this.docs;
    this.ttl;
    this.rating;

    /*optional object properties*/
    this.category;
    this.image;

    /*array of RSS2Item objects*/
    this.items = new Array();
	 
    /*B*/
	 
    var chanElement = rssxml.getElementsByTagName("channel")[0];
       
    var itemElements = rssxml.getElementsByTagName("item");
	alert("C");
    /*C*/
    for (var i=0; i<itemElements.length; i++)
    {
        Item = new RSS2Item(itemElements[i]);
        this.items.push(Item);
    }

alert("D");
    /*D*/
    var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
    var tmpElement = null;
    for (var i=0; i<properties.length; i++)
    {

	try{
        tmpElement = chanElement.getElementsByTagName(properties[i])[0];
        if (tmpElement!= null)
            eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
	}
	catch(ex){}
    }

    /*E*/
    try{
    this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
    }
    catch(ex){}
 try{
   	
	this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
    }
    catch(ex){}

	
}

function RSS2Enclosure(encElement)
{
    if (encElement == null) {
        this.url = null;
        this.length = null;
        this.type = null;
    } else {
        this.url = encElement.getAttribute("url");
        this.length = encElement.getAttribute("length");
        this.type = encElement.getAttribute("type");
    }
}

function RSS2Guid(guidElement)
{
    if (guidElement == null) {
        this.isPermaLink = null;
        this.value = null;
    } else {
        this.isPermaLink = guidElement.getAttribute("isPermaLink");
        this.value = guidElement.childNodes[0].nodeValue;
    }
}

function RSS2Source(souElement)
{
    if (souElement == null) {
        this.url = null;
        this.value = null;
    } else {
        this.url = souElement.getAttribute("url");
        this.value = souElement.childNodes[0].nodeValue;
    }
}
