/* --- blob.lastcomments.js ---
  wersja: 0.5.5  (15.01.2008)
  autor: s.z.y.m.o.n[SHIFT+2]gazeta.pl
  opis: skrypt umozliwia wyswietlenie na blogu w blox.pl fragmentow ostatnich komentarzy
  licencja: Mozna wykorzystywać i modyfikowac pod warunkiem zachowania informacji o autorze (czyli o mnie) oraz
  nie usuwaniu linka do mojego bloga. Wiecej info szukaj na 
  http://testblog.blox.pl/2007/05/Ostatnie-komentarze-wersja-JavaScript-widgetu.html
*/

// Ponizsze linie mozesz edytowac
var ilosc = 5;   // liczba wyswietlanych komentarzy
var znaki = 100; // liczba wyswietlanych znakow komentarza
var tytul = 'Ostatnie komentarze';
//-----koniec bloku do edycji ------

function loadXMLDoc(div) {
 var req=null;
 var url=document.URL.replace(/\.blox\.pl\/[^ ]*$/,'.blox.pl/komentarze.rss');
 if (window.XMLHttpRequest) {req=new XMLHttpRequest();}
 else if (window.ActiveXObject) {req=new ActiveXObject('Msxml2.XMLHTTP');}
 if (req){
  req.onreadystatechange=function(){
   if (req.readyState==4)
    if (req.status==200) getComments(req.responseXML,div);
  }
  req.open("GET",url,true);
  if (window.XMLHttpRequest){req.send(null);}
  else{req.send();}
 }
}

function getText(e,tag){var t = e.getElementsByTagName(tag)[0]; return (t)? t.firstChild.nodeValue: '';}

function getComments(xml,div){
 var comm=xml.getElementsByTagName('item');
 var dt=new Date();
 var html='<div id="LCtitle">'+tytul+'</div><ul>';
 if ((ilosc<1)||(ilosc>comm.length))ilosc=comm.length;
 for (var i=0; i<ilosc;i++){
  var cm=comm[i];
  var cont=getText(cm,'description');
  cont=cont.replace(/<br\/>/gi,' ');
  cont=cont.replace(/<[^>]+>/gi,'');
  cont=cont.substr(0,znaki-1);
  if (cont.length==znaki) cont.replace(/( [^ ]*)$/,'');
  dt.setTime(Date.parse(getText(cm,'pubDate')));
  html+='<li><span class="LCtop"><span class="LCuser">'+getText(cm,'title').match(/,([^,]*)$/i)[1]+'</span><span class="LCdate">, '+String('0'+dt.getDate()).replace(/(^.)(?=\d{2})/,'')+'.'+String('0'+(dt.getMonth()+1)).replace(/(^.)(?=\d{2})/,'')+'.'+String(dt.getFullYear()).substr(2)+' '+dt.getHours()+':'+String('0'+dt.getMinutes()).replace(/(^.)(?=\d{2})/,'')+'</span></span><br />'+'<a href="'+getText(cm,'link').replace(/(#.+)$/,'')+'">'+getText(cm,'title').match(/\: (.*),/i)[1]+'</a><br />'+cont+'&#8230;</li>';
 }
 html+='</ul><p style="font:normal 10px \'Verdana\'!important;display:block!important;text-align:left">Skrypt: <a href="http://testblog.blox.pl" style="font-weight:bold!important;">s.z.y.m.o.n</a></p>';
 div.innerHTML=html;
}
document.write('<div id="LastComments"></div>');
d=document.getElementById('LastComments');
loadXMLDoc(d);

