/*
Based On http://www.legalrss.co.uk/feed/newssynd1.js
Modified By Yammayap
*/

Date.prototype.setISO8601 = function(dString){

	var regexp = /(\d\d\d\d)(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/;

	if (dString.toString().match(new RegExp(regexp))) {
		var d = dString.match(new RegExp(regexp));
		var offset = 0;

		this.setUTCDate(1);
		this.setUTCFullYear(parseInt(d[1],10));
		this.setUTCMonth(parseInt(d[3],10) - 1);
		this.setUTCDate(parseInt(d[5],10));
		this.setUTCHours(parseInt(d[7],10));
		this.setUTCMinutes(parseInt(d[9],10));
		this.setUTCSeconds(parseInt(d[11],10));
		if (d[12])
			this.setUTCMilliseconds(parseFloat(d[12]) * 1000);
		else
			this.setUTCMilliseconds(0);
		if (d[13] != 'Z') {
			offset = (d[15] * 60) + parseInt(d[17],10);
			offset *= ((d[14] == '-') ? -1 : 1);
			this.setTime(this.getTime() - offset * 60 * 1000);
		}
	}
	else {
		this.setTime(Date.parse(dString));
	}
	return this;
};


function generateLi(article, user)
	{
	var articleDate = new Date().setISO8601(article.published_at)
	return "<li><span>Latest legal news:</span> " + articleDate.getDate() + "/" + (articleDate.getMonth() + 1) + "/" + articleDate.getFullYear() + " - <a href=\"/legal-services/news/" + article.slug + "\" title=\"" + article.title + "\">" + article.title + "</a></li>";
	}

/*
 * JavaScript newsSyndFeed
 * Copyright (c) 2008 GoTripod Ltd
 */
 
function newsSyndFeed(data)
{
	var json_data = eval(data);
	if (json_data.status == 0) return;
	var categories = json_data.categories;
	var articles = json_data.articles;
	var user = json_data.user;
	var content = "";
	if (categories) {
		for (i = 0; i < categories.length; i++) {
			if(categories[i].name=="General")
				{
				content += '<ul id="ticker' + nList + '">';
				for (ii = 0; ii < categories[i].articles.length; ii++) {
					content += generateLi(categories[i].articles[ii], user);
				}
				content+='</ul>';
				}
		}
	}
	document.getElementById("newssynd-feed" + nList).innerHTML = content;
}
