var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
function parseDate(date_str){
    d = new Date(date_str); h = d.getHours(); m = d.getMinutes(); m = (m < 10 ) ? "0" + m : m;
    time = (h > 12) ? (h - 12) + ":" + m + " p.m." : h + ":" + m + " a.m.";
    ret = months[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " at " + time;
    return ret;
}

var rss_data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:apnm=\"http://ap.org/schemas/03/2005/apnm\" version=\"2.0\" xmlns:apcm=\"http://ap.org/schemas/03/2005/apcm\"><channel><title>blounttoday.com Stories: News</title><link>http://www.blounttoday.com/news/news/?partner=RSS</link><atom:link href=\"http://www.blounttoday.com/news/news/?partner=RSS\" type=\"application/rss+xml\" rel=\"self\"></atom:link><description>blounttoday.com Stories: News</description><language>en-us</language><category>news</category></channel></rss>";
var items_parsed = [];

if(typeof(FEED_LIMIT) == 'undefined')
    FEED_LIMIT = 5;

var link_re = new RegExp("\<link\>(.*?)\</link\>", "g");
var title_re = new RegExp("\<title\>(.*?)\</title\>", "g");
var pubdate_re = new RegExp("\<pubDate\>(.*?)\</pubDate\>", "g");

var lpct = 0;
do {
    title = title_re.exec(rss_data);
    link = link_re.exec(rss_data);
    pubdate = pubdate_re.exec(rss_data);

    matched = (title != null && link != null && pubdate != null);

    if(matched && lpct > 0){
        parsed = "<li>" +
            "<a href=\"" + link[1] + "\">"+ title[1] +"</a>" +
            "<span class=\"date\">Published "+ parseDate(pubdate[1]) +"</span>" +
            "</li>";
        items_parsed.push(parsed);
    }

    lpct++;
}
while (matched != null && lpct < (FEED_LIMIT + 1))

document.getElementById(FEED_CONTAINER).innerHTML = "<ul class=\"story_list\">" + items_parsed.join("") + "</ul>";

