
function get_rss_feed(feedUrl, limit, div) {
	//clear the content in the div for the next feed.
        if (!$("#" + div)) return false;
	$("#" + div).empty();
        var loadImg = "<div style='text-align:center;margin:0 auto;' id='loading_" + feedUrl +"'><p align='center'><img src='./img/ajax-loader.gif' style='border:0 !important;' border='0' alt='' /></p></div>";
        $('#' + div).append($(loadImg));
	//use the JQuery get() to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	try {
		$.get('proxy.php?url='+feedUrl, function(d) {
                       
			if ($(d).is('output')) {
				var html = "<div class=\"entry\">";
				html += "<h4 class=\"postTitle\">" + $(d).find('error').text() + "<\/h4>";
                                $('#loading_' + feedUrl).remove();
				$('#' + div).append($(html));
			}
                            var cnt = 0;
                            var limite = limit;
                            var tagName = (div == 'blogspot') ? 'entry' : 'item';

                            var link = "", tmpS = "", curr;

                            //find each 'item' in the file and parse it
                            $(d).find(tagName).each(function(indice) {

                                    
                                    if (cnt == limite) {
                                        $('#loading_' + feedUrl).remove();
                                        return false; // means "break;" in jQuery!
                                    }
                                    //name the current found item this for this particular loop run
                                    var item = $(this);

                                    // grab the post title
                                    var title = item.children('title').text();

                                    // subtitle
                                    //var subtitle = item.children('subtitle').text().trim();

                                    // grab the post's URL
                                    link = item.children('link').text();

                                    if (div == 'wordpress' || div == 'blogspot') {
                                        item.find('link[rel*="alternate"]').each(function() {
                                            curr = $(this);
                                            if (curr.attr("href").indexOf("html") != -1) {
                                                link = curr.attr("href");
                                                return false;// means "break;" in jQuery!
                                            }
                                        });
                                    }

                                    //alert(title + "\n" + item);

                                    // next, the description
                                    //var description = $item.find('description').text();
                                    //don't forget the pubdate
                                    
                                    var pubDate = (div == 'blogspot') ? item.find('published').text() : item.find('pubDate').text();
                                    var dObj = new Date(pubDate);
                                    
                                    var gg = dObj.getDate();
                                    var mm = dObj.getMonth() + 1;
                                    var yy = dObj.getFullYear();
                                    pubDateFinal = gg + "/" + mm + "/" + yy;
                                    
                                    // now create a var 'html' to store the markup we're using to output the feed to the browser window
                                    var html = "<div class=\"entry\">";
                                    html += "<h4 class=\"postTitle\"><span class=\"date\">" + pubDateFinal + "</span>&nbsp;&nbsp;";
                                    html += "<a class=\"link_body\" href=\"" + link + "\" target=\"_blank\">" + title + "<\/a><\/h4>";
                                    html += "</div>";
                                    //html += "<span class=\"date\">" + pubDate + "</span>";
                                    //html += "<p class=\"description\">" + description + "</p>";
                                    //html += "&nbsp;<a href=\"" + link + "\" target=\"_blank\">Leggi<\/a><\/div>";

                                    //put that feed content on the screen!
                                    
                                    $('#' + div).append($(html)); 
                                    cnt++; 
			}); // end each       
		}); // end $.get
                
	} catch(e) {
		alert("sono nel catch");
		var html = "<div class=\"entry\">";
		html += "<h4 class=\"postTitle\">Catched error: " + e.message +"<\/h4>";
                $('#loading_' + feedUrl).remove();
		$('#' + div).append($(html));
	}
};

