﻿// ---------------------------------------------------
// BLOGTOC
// ---------------------------------------------------

   var postTitle = new Array();     // array of posttitles
   var postUrl = new Array();       // array of posturls
   var postDate = new Array();      // array of post publish dates
   var postSum = new Array();       // array of post summaries

   var tocLoaded = false;           // true if feed is read and ToC can be displayed
   //var numChars = 250;              // number of characters in post summary


function loadtoc(json) {

   function getPostData() {
	  // this functions reads all postdata from the json-feed and stores it in arrays
      if ("entry" in json.feed) {
         var numEntries = json.feed.entry.length;
         // main loop gets all the entries from the feed
         for (var i = 0; i < numEntries; i++) {
            // get the entry from the feed
            var entry = json.feed.entry[i];

            // get the posttitle from the entry
            var posttitle = entry.title.$t;

            // get the post date from the entry
            var postdate = entry.published.$t.substring(0,10);

            // get the post url from the entry
            var posturl;
            for (var k = 0; k < entry.link.length; k++) {
               if (entry.link[k].rel == 'alternate') {
               posturl = entry.link[k].href;
               break;
               }
            }

         // add the post data to the arrays
            postTitle.push(posttitle);
            postDate.push(postdate);
            postUrl.push(posturl);
            //postSum.push(postcontent);
            //postLabels.push(pll);
         }
      }
   } // end of getPostData

   getPostData();
   tocLoaded = true;
}



function displayToc(TocName) {
   //var numDisplayed = 0;
   var tocTable = '';
   //tocTable += '<ul>';
   for (var i = 0; i < postTitle.length; i++) {
	  //tocTable += '<tr>';
      //tocTable += '<td nowrap="nowrap" valign="top"><p class="rub-date">' + postDate[i].substr(8,2) +'/'+ postDate[i].substr(5,2) +'/'+ postDate[i].substr(0,4) + '</p></td>';
      //tocTable += '<td><a href="' + postUrl[i] + '" title="' + postTitle[i] + '">' + postTitle[i] + '</a></td>';
	  //tocTable += '</tr>';
      //numDisplayed++;
      tocTable += '<p>- <a href="' + postUrl[i] + '" title="' + postTitle[i] + '"  target="_blank">' + postTitle[i] + '</a></p>';
   }
   //tocTable += '</ul>';

   //var tocNote = '</br>' + postTitle.length + ' articles';

   var tocdiv = document.getElementById(TocName);
   tocdiv.innerHTML = tocTable;// + tocNote;
}



function showToc(TocName) {
  if (tocLoaded) { 
     displayToc(TocName);
  }
  //else { alert("Chargement..."); }
}

