document.write("<script type='text/javascript' src='http://smart.1parkplace.com/scripts/js/jquery-1.2.3.min.js'></script>");

function GetFeed(feed, itemCount, divID, showSnippet)
{
	//format the request
	var googleApi = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=";
	googleApi = googleApi + UrlEncode(feed);
	
	if(itemCount != null)
		googleApi = googleApi + "&num=" + itemCount;	
	
	//load the data
	$.getJSON(googleApi,
		function(data)
		{
		  var rssDiv = document.getElementById(divID);	//this is the container from the page where the feed will be written out
		  rssDiv.className = "wwRssContainer";
		  if(data.responseData == null)
			rssDiv.innerHTML = "RSS Feed is unavailable";
		  else
		  {	  
			  rssFeed = data.responseData.feed; //json			  
			  
			  if(!rssFeed)
				rssDiv.innerHTML = "RSS Feed is unavailable";
			  else			  
				ProcessFeed(rssFeed, rssDiv, showSnippet); //format the output  
			}
		});		
}

function ProcessFeed(feed, container, showSnippet)
{	
	if(feed.entries.length == 0)
		container.innerHTML = "RSS Feed is empty";
	else
		container.innerHTML = ""; //clears out the loading image if the container has one.
			
	for(var i=0; i<feed.entries.length; i++)
	{
		var entry = feed.entries[i];
		AttachFeedLinkDiv(container, entry.title, entry.link, "wwRssTitle");
		AttachDiv(container, entry.publishedDate, "wwRssPubDate");
		
		if(showSnippet)
			AttachDiv(container, entry.contentSnippet, "wwRssContent");	
		else
			AttachDiv(container, entry.content, "wwRssContent");
	}
}

function AttachFeedLinkDiv(attachTo, linkTitle, link, cssClass)
{
	//create the title container
	var div = document.createElement("div");	
	
	//create the link
	var anchor = document.createElement("a");
	anchor.href = link;
	anchor.target = "_blank";
	anchor.className = cssClass;
	anchor.appendChild(document.createTextNode(linkTitle));
	
	//attach the link to the title container and the title container to the rssFeed container 
	div.appendChild(anchor);
	attachTo.appendChild(div);
}

//adds the individual feed sections
function AttachDiv(attachTo, content, cssClass)
{
	var div = document.createElement("div");
	div.className = cssClass;	
	div.innerHTML = content;
	attachTo.appendChild(div);
}


function UrlEncode(c)
{
	var o='';
	var x=0;
	c=c.toString();
	var r=/(^[a-zA-Z0-9_.]*)/;
	
	while(x<c.length)
	{
		var m=r.exec(c.substr(x));
		
		if(m!=null && m.length>1 && m[1]!='')
		{
			o+=m[1];
			x+=m[1].length;
		}
		else
		{
			if(c[x]==' ')
				o+='+';			
			else
			{
				var d=c.charCodeAt(x);
				var h=d.toString(16);
				o+='%'+(h.length<2?'0':'')+h.toUpperCase();
			}
			x++;
		}
	}
	return o;
}
