//Function to take an rss feed and parse it
/*
	strFeedURL = The URL of the feed
	intItemCount = Max number of items to display
	strContainer = ID of container that item will be added to
	blnReplace = If set to true then the content of the container will be replaced, if false the the rss will be appended to the bottom of the container
*/
function get_rss_feed(strFeedURL,intItemCount,strDiv,blnReplace) {
	$.get('/xml_proxy.asp?url='+escape(strFeedURL), function(d) {
		var html = '';
		var intXMLItemCount = 10;
		
		d = parseXml(d);

		$(d).find('item').each(function() {
			intXMLItemCount +=1;
			if (intXMLItemCount <= intItemCount) {
			
				var item = $(this);
				
				var title = item.find('title').text();
				if (title != null) {
					title = title.replace(/\<\!\[CDATA\[/g,"");
					title = title.replace(/]]>/g,"");
				} else {
					title = '';
				}
				
				if (jQuery.browser.msie) {				
					var link = item.find('link').text();
				} else {	
					var link = '';
					if (item != null) {
						var linkPos = item.html().indexOf("<link>");
						link = item.html().slice(linkPos+6);
						var linkPos2 = link.indexOf("<");
						link = link.slice(0,linkPos2);
					}
				}
				
				if (jQuery.browser.msie) {
					var description = item.find('description').text();
				} else {
					var description = item.find('description').html();
				}
				if (description != null) {
					description = description.replace(/\<!--\[CDATA\[/g,"");
					description = description.replace(/]]-->/g,"");
					description = description.replace(/&amp;/g,'&');
					description = description.replace(/&lt;/g,'<');
					description = description.replace(/&gt;/g,'>');
				} else {
					description = '';
				}
				
				var pubDate = item.find('pubDate').text();
				
				//if (title != '' && link != '' && description != '' && pubDate != '') {
				html += "<div class=\"rssEntry\"><h3 class=\"postTitle\">" + title + "<\/h3>";
				html += "<em class=\"rssDate\">" + pubDate + "</em>";
				html += "<p class=\"rssDescription\">" + description + "</p>";
				if (link != '') html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a>"
				html += "<\/div>";
				//console.log(html);
				//}
			}
		});
		if (html == '') html='<p>There were no items in the rss feed to display.</p>';
		if (blnReplace) {
			$('#'+strDiv).html($(html));
		} else {
			$('#'+strDiv).append($(html)); 
		}
	}); 
};

function parseXml(xml)
{
	originalXML = xml;
	if (jQuery.browser.msie)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.loadXML(xml);
		xml = xmlDoc;
	}
	if (xml.xml == '') xml = originalXML;
	return xml;
}
