//------------------
// Title: feeds-contentpage.js
// Description: This script is used for loading the external 'opdrachten' and 'vacatures' feeds on the vakgebied landingpages 
// Author: C. van marwijk
// Date: 23-12-2009
//------------------

// Script for Feed import
google.load("feeds", "1");
  
function feeds_initialize() {
   
// test if the global variables set in the vakgebied templates are set correctly
//feed cross-content block opdrachten

//alert("feedurl value = " + feedurl);

//var feed1 = new google.feeds.Feed("http://accsite6.roxen.ibridge.nl/content/search-selection/over-randstad/job-feed-mwp.xml");
var feed1 = new google.feeds.Feed(feedurl);

feed1.setNumEntries(15);
feed1.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed1.load(function(result) {
      if (!result.error) {
        var container = document.getElementById("vacaturesfeedcp");
        var html = "";
        for (var i = 0; i < result.feed.entries.length; i++) {
          var entry = result.feed.entries[i];
          // get title
           var entrydescription = entry.content;
            if (entrydescription.length > 50) {
            entrydescription = entrydescription.substr(0,50) + "...";
          }
          var entrytitle = entry.title;
          if (entrytitle.length > 23) {
            entrytitle = entrytitle.substr(0,23) + "...";
          }
          // calculate/format date
          var entrydate = new Date(entry.publishedDate);
          var current_day = entrydate.getDate();
          var current_month = entrydate.getMonth() + 1;
          var current_year = entrydate.getFullYear();
          if (current_day < 10) {current_day = "0" + current_day; }
          if (current_month < 10) {current_month = "0" + current_month; }
          var formatteddate = current_day + "-" + current_month + "-" + entrydate.getFullYear();
          // build link
          var ahref = "<a href='"
            + entry.link
            + "' target='_self' class='linkFeedcp' title='"
            + entrytitle
            + "' alt='"
            + entrytitle
            + "'>"
            + entrytitle
            + "</a>";
             var description = "<div class='contentFeedcp'>" 
            + entrydescription 
            + "</div>";
          //html = html + "" + ahref + "" + description + "";
          html = html + "" + ahref + "";
        }
        var rsshtml = "<a href='/mwp2/faces/baanZoeken?afstand=10&pagina=1&sc=0&filters=geen' class='linkFeedMorecp' title='Meer vacatures' alt='Meer vacatures' target='_self'>> Meer...</a>";
       // var rsshtml = "";
        //html = html + rsshtml + "</ul>";
        html = html + rsshtml + "</div>"; 
        container.innerHTML = html;
      }
    });
    
  }
  google.setOnLoadCallback(feeds_initialize);

