function isMainPg(){ return /<?php echo $_SERVER["HTTP_HOST"]; ?>\/?$|<?php echo $_SERVER["HTTP_HOST"]; ?>\/?/.test(document.URL); }

/* By posortowac chronologicznie zmien parametry funkcji listArchive
   na false 1 parametr dla lat, a 2 dla miesiecy*/
if (isMainPg()) {
 listArchive(true, true); // <--Parametry tej funkcji mozna zmienic
}

function css(wpis)
{
 if (1 || screen.width>1680)
 {
  document.getElementById('img_top').src="../resource/top1x1500.jpg";
  document.getElementById('img_top_area').coords="0,0,265,320";
  document.getElementById("BlogTytulBox").style.height="320px";
  document.getElementById("BlogGlownyBox").style.width="1500px";
  if(wpis == 'w')
  {     
   document.getElementById("SkomentujWazkaSzpalta").style.width="250px";
  } else { 	
   document.getElementById("BlogWazkaSzpalta").style.width="250px";
  }
  document.getElementById("BlogWazkaSzpaltaLewa").style.width="250px";
  document.getElementById("BlogSzerokaSzpalta").style.width="910px";
  document.getElementById("logowanie").style.width="244px";
  document.getElementById("newsletter").style.width="244px";
 }
 if (0  || screen.width<=1680 && screen.width>1360)
 {
  document.getElementById('img_top').src="../resource/top1x1200.jpg";
  document.getElementById('img_top_area').coords="0,0,247,290";
  document.getElementById("BlogTytulBox").style.height="290px";
  document.getElementById("BlogGlownyBox").style.width="1200px";
  if(wpis == 'w')
  {     
   document.getElementById("SkomentujWazkaSzpalta").style.width="200px";
  } else {
   document.getElementById("BlogWazkaSzpalta").style.width="200px";
  }
  document.getElementById("BlogWazkaSzpaltaLewa").style.width="200px";
  document.getElementById("BlogSzerokaSzpalta").style.width="710px";
  document.getElementById("logowanie").style.width="194px";
  document.getElementById("newsletter").style.width="194px";
 } else if (screen.width<=1024 && screen.width>800) {
  document.getElementById('img_top').src="../resource/top1x900.jpg";
  document.getElementById('img_top_area').coords="0,0,185,233";
  document.getElementById("BlogTytulBox").style.height="233px";
  document.getElementById("BlogGlownyBox").style.width="900px";
  if(wpis == 'w')
  {     
   document.getElementById("SkomentujWazkaSzpalta").style.width="160px";
  } else {
   document.getElementById("BlogWazkaSzpalta").style.width="160px";
  }
  document.getElementById("BlogWazkaSzpaltaLewa").style.width="160px";
  document.getElementById("BlogSzerokaSzpalta").style.width="500px";
  document.getElementById("logowanie").style.width="158px";
  document.getElementById("newsletter").style.width="158px";
 } else if (screen.width <= 800) {
  document.getElementById('img_top').src="../resource/top1x720.jpg";
  document.getElementById('img_top_area').coords="0,0,150,186";
  document.getElementById("pokaz_szpalte").style.display = "none";
  document.getElementById("nawigacja").style.display = "block";
  document.getElementById("BlogGlownyBox").style.background = 'url(../resource/top1x720.jpg) no-repeat left top';
  document.getElementById("BlogTytulBox").style.height="186px";
  document.getElementById("BlogGlownyBox").style.width="720px";
  document.getElementById("BlogSzerokaSzpalta").style.paddingLeft = "10px";
  document.getElementById("BlogSzerokaSzpalta").style.width="500px";
  if(wpis == 'w')
  {
   document.getElementById("SkomentujWazkaSzpalta").style.width="160px";
  } else {
   document.getElementById("BlogWazkaSzpalta").style.width="160px";
  }
  if(wpis == 'o')
  {
   document.getElementById("BlogPrzerwa").style.display = "none";
   document.getElementById("BlogKategorieBox").style.display = "block";
  }
 }
}

function email(wpis)
{
 alert("Uzupełnij adres email!");
 css(wpis)
}

function insertElement(owner, elem, revers) 
{
 if (owner) 
 {
  var node = document.createElement(elem);
  if (revers) {return owner.insertBefore(node, owner.firstChild)}
  return owner.appendChild(node);
 }
 return null;
}

function listArchive(revYears,revMonths) 
{
 var year = 0;
 var tdiv = document.getElementById('BlogArchiwumBox');
 var end = tdiv.removeChild(document.getElementById('ArchiwumTytul'));
 tdiv.appendChild(end);
 var mUl = insertElement(tdiv,'ul',false);
 mUl.setAttribute('id','nav');
 while (tdiv.firstChild != end) 
 {
  if (tdiv.firstChild.nodeType==1) 
  {
   var a = tdiv.firstChild.getElementsByTagName('a')[0];
   var date = (/20[0-9]{2}/.exec(a.innerHTML))[0];
   if (date != year) 
   {
    year = date;
    var li = insertElement(mUl,'li',revYears);
    li.appendChild(document.createTextNode(year));
    ul = insertElement(li,'ul');
    li.onmouseover=function(){this.className="over";};
    li.onmouseout=function(){this.className="";};
   }
   a = tdiv.firstChild.removeChild(a);
   a.innerHTML = a.innerHTML.substring(0,a.innerHTML.length -5);
   var li = insertElement(ul,'li',revMonths);
   li.appendChild(a);
  }
  tdiv.removeChild(tdiv.firstChild);
 }
}

function kom(nast,pop)
{
 var tdiv = document.getElementById('SkomentujListaKomentarzy');
 var end = tdiv.removeChild(document.getElementById('SkomentujTytListyKomentarzy'));
 var dod = document.getElementById('DodKomentarz');
 var kolejnosc = document.getElementById('kolejnosc');
 tdiv.appendChild(end);
 var tab1=new Array(0);
 var tab2=new Array(0);
 var tab3=new Array(0);

 while (tdiv.firstChild != end)
 {
  if (tdiv.firstChild.nodeType==1) 
  {
   if(tdiv.firstChild.className == "Infoniepar" || tdiv.firstChild.className == "Infopar")
   {
    tab1.push(tdiv.firstChild.innerHTML);
    tab2.push(tdiv.firstChild.id);
   }
  }
  tdiv.removeChild(tdiv.firstChild);
 }
 document.getElementById('SkomentujListaKomentarzy').appendChild(end);
 document.getElementById('SkomentujListaKomentarzy').appendChild(kolejnosc);
 if(nast != pop)
 {
  tab1.reverse();
  tab2.reverse();
  document.getElementById('od').href="javascript: kom(1, "+ nast +")";
  document.getElementById('nor').href="javascript: kom(0, "+ nast +")";
 }else {
  document.getElementById('od').href="javascript: kom(1, "+ nast +")";
  document.getElementById('nor').href="javascript: kom(0, "+ nast +")";
 }

 for (var i=0; i < tab1.length; i++) 
 {
  newDiv = document.createElement("div");
  newDiv.innerHTML = tab1[i];
  newDiv.id = tab2[i];
  if(i%2 == 1)
  {
   newDiv.className = "Infoniepar";
  } else {
   newDiv.className = "Infopar";
  }
  
  document.getElementById('SkomentujListaKomentarzy').appendChild(newDiv);
 }
 document.getElementById('SkomentujListaKomentarzy').appendChild(dod);
}
