﻿var targetControl;

function displayFullFeed(feedResponse) {
    for (i = 0; i < feedResponse.entries.length; i++) {
        var publishedDate = feedResponse.entries[i].publishedDate;

        publishedDate = Date.parse(publishedDate.substring(4, 17));
        var d = new Date(publishedDate);

        var printableUrl = feedResponse.entries[i].link.replace("RssLanding", "RssLanding_pf");
        var date = (d.getMonth() + 1) + '/' + d.getDate() + '/' + (d.getYear() - 100);
        var linkTitle = '<a href="' + feedResponse.entries[i].link + '" target="_blank">' + feedResponse.entries[i].title + '</a>';
        var linkPrintable = '<a href="' + printableUrl + '" target="_blank"><img src="/_layouts/EnergizerSolution/Energizer/images/newsItemPrint.png" width="30" height="25" style="border:none" /></a>';
        var sep = '<hr />'
        var rowClass = (i % 2 == 0) ? 'odd' : 'even';

        html = '<div class="newsItem ' + rowClass + '">';
        html += '<table width="100%"><tr><td width="18%" valign="middle" class="newsItemDate">' + date + '</td>';
        html += '<td width="71%"  valign="middle"class="newsItemText">' + linkTitle + '</td>';
        html += '<td width="11%" valign="middle">' + linkPrintable + '</td>';
        html += '</tr></table></div>';

        $('.newsfeed').append(html);
    }
}

function displayLatestNews(feedResponse, target) {
    if (feedResponse.entries.length > 0) {
        var publishedDate = feedResponse.entries[0].publishedDate;

        publishedDate = Date.parse(publishedDate.substring(4, 17));
        var d = new Date(publishedDate);

        var html = '<div class="panel_content" style="background:url(' + bgImageUrl + ' ) no-repeat;">';
        html += '<h2 style="text-align:left">NEWS</h2>';
        html += '<span style="font-size: 0.95em;">' + feedResponse.entries[0].title + '</span>'
        html += '<div class="rounded_button panelBL_button rounded_button_dark"><a href="' + feedResponse.entries[0].link + '">FULL ARTICLE</a></div>'
        html += '</div>'

        $(target).append(html);
    }
}


function parseRSS(url, callback, target) {
    $.ajax({
        url: 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        success: function (data) {
            callback(data.responseData.feed, target);
        }
    });
}
