
  // katalog.gery.pl
  // autor: Łukasz Milewski
  // copyright (c) 2005 Gery(R) Design

  var niet = false;
  var akt = 1;
  var num_dodaj = 0;

  var isIE = (navigator.appName == "Microsoft Internet Explorer");
  var isOP = false;
  if (window.opera)
  {
      isIE = false;
      isOP = true;
  }

  function combo ()
  {
      // przerywamy
      if (niet == true) return;
      // pobieramy
      var el = document.getElementById ('lista');
      var elc = document.getElementById ('listacien');
      // pokazujemy jeśli jest ukryte
      if (el.style.display == 'none' || el.style.display == '')
      {
          // pokazujemy
          el.style.display = 'block';
          elc.style.display = 'block';
          elc.style.height = (el.offsetHeight + 2) + 'px';
          document.onclick = combo;
      }
      else
      {
          // ukrywamy
          el.style.display = 'none';
          elc.style.display = 'none';
          if (isIE)
          {
              document.onclick = '';
          }
          else
          {
              document.onclick = undefined;
          }
          // niet
          niet = true;
          // licznik na znikanie
          licznikST = window.setTimeout('wait()', 10);
      }
      // to wszystko :)
  }

  function combo_kat_hide ()
  {
      combo_kat (num_dodaj);
  }

  function combo_kat (num)
  {
      // przypisanie
      num_dodaj = num;
      // przerywamy
      if (niet == true) return;
      // pobieramy
      var el = document.getElementById ('lista_kat' + num);
      var elc = document.getElementById ('listacien_kat' + num);
      // pokazujemy jeśli jest ukryte
      if (el.style.display == 'none' || el.style.display == '')
      {
          // pokazujemy
          el.style.display = 'block';
          elc.style.display = 'block';
          elc.style.height = (el.offsetHeight + 2) + 'px';
          document.onclick = combo_kat_hide;
      }
      else
      {
          // ukrywamy
          el.style.display = 'none';
          elc.style.display = 'none';
          if (isIE)
          {
              document.onclick = '';
          }
          else
          {
              document.onclick = undefined;
          }
          // niet
          niet = true;
          // licznik na znikanie
          licznikST = window.setTimeout('wait()', 10);
      }
      // to wszystko :)
  }

  function wait ()
  {
      niet = false;
  }

  function zaznacz (num)
  {
      // pobieramy element
      var el = document.getElementById ('el' + num);
      // ustawiamy dane
      document.getElementById ('f').t.value = num;
      if (isIE)
      {
          document.getElementById ('ftxt').value = el.innerHTML;
      }
      else
      {
          document.getElementById ('ftxt').value = el.text;
      }
  }

  function zaznacz_kat (gdzie, num)
  {
      // pobieramy element
      var el = document.getElementById ('k' + gdzie + 'el' + num);
      // ustawiamy dane
      document.getElementById ('k' + gdzie).value = num;
      if (isIE)
      {
          document.getElementById ('kategoria' + gdzie).value = el.innerHTML;
      }
      else
      {
          document.getElementById ('kategoria' + gdzie).value = el.text;
      }
  }

  function ustawienia ()
  {
      // zmienne
      var ust = document.getElementById ('ustawienia');

      // czy ukryć?
      if (ust.style.display == 'block')
      {
          ust.style.display = 'none';
          return;
      }
      ust.style.display = 'block';

      // ustawianie danych
      document.getElementById('ff').checked = ff;
      document.getElementById('nw').checked = nw;
      document.getElementById('so').checked = sd;
      document.getElementById('sd').checked = so;
      document.getElementById('sk').checked = sk;

      // da end
      return;
  }

  function ocen (num)
  {
      // otwieramy popupa
      window.open ('/ocen.php?id=' + num, 'katoc', 'width=160,height=120,left=200,top=200');
  }

  function dodaj_open (num)
  {
      // otwieramy popupa
      window.open ('/kategorie.php?num=' + num, 'katoc', 'width=330,height=420,left=200,top=200');
  }

  function pagerank ()
  {
      // zmienne
      var prmain = document.getElementById ('pr');
      var prwait = document.getElementById ('rpr');
      var prform = document.getElementById ('fpr');

      // piszemy waita
      prwait.innerHTML = '<div style="text-align:center;padding-top:20px;"><img src="/img/klepsydra.gif" style="margin-bottom: -4px; margin-right: 6px; width: 13px; height: 17px;">sprawdzam UserRank</div>';

      // ukrywamy
      prmain.style.display = 'none';
      prwait.style.display = 'block';

      // a teraz wgrywamy
      var s = document.createElement ('script');
      s.type = 'text/javascript';
      s.src = '/a87as432e.php?strona=' + prform.strona.value + '&token=' + prform.token.value + '&kod=' + prform.kod.value;
      document.body.appendChild (s);
  }

  function pagerank_pokaz (ile, adres, kod)
  {
      // zmienne
      var prwait = document.getElementById ('rpr');
      var prform = document.getElementById ('fpr');
      var primag = document.getElementById ('ipr');

      // okej, więc piszemy tekst
      if (isIE)
      {
          prwait.innerHTML = '<div style="text-align:center;padding-top:2px;">UserRank dla strony:<br /><b>' + adres + '</b><br />wynosi<br /><div style="margin-left: 60px; margin-top: 4px; position:absolute;"><a style="text-decoration: underline;" href="javascript:pagerank_przywroc();">sprawdź inną</a></div><b><span style="font-size: 14px;">' + ile + '</span>/10</b></div>';
      }
      else
      {
          prwait.innerHTML = '<div style="text-align:center;padding-top:2px;">UserRank dla strony:<br /><b>' + adres + '</b><br />wynosi<br /><div style="margin-left: 160px; margin-top: 2px; position:absolute;"><a style="text-decoration: underline;" href="javascript:pagerank_przywroc();">sprawdź inną</a></div><b><span style="font-size: 14px;">' + ile + '</span>/10</b></div>';
      }

      // czyscimy
      prform.strona.value = 'http://';
      prform.token.value = '';
      prform.kod.value = kod;

      // wgrywamy obrazek
      primag.src = '/img/token.png?t=' + kod;
  }

  function pagerank_przywroc ()
  {
      // zmienne
      var prmain = document.getElementById ('pr');
      var prwait = document.getElementById ('rpr');

      // ukrywamy
      prmain.style.display = 'block';
      prwait.style.display = 'none';
  }

  function pagerank_error (error, kod)
  {
      // zmienne
      var prwait = document.getElementById ('rpr');
      var prform = document.getElementById ('fpr');
      var primag = document.getElementById ('ipr');

      // okej, więc piszemy tekst
      if (isIE)
      {
          prwait.innerHTML = '<div style="text-align:center;padding-top:2px;">Wystąpił błąd:<br /><br /><b>' + error + '</b><br /><div style="margin-left: 50px; margin-top: 4px; position:absolute;"><a style="text-decoration: underline;" href="javascript:pagerank_przywroc();">sprawdź inną</a></div><b><span style="font-size: 14px;">&nbsp;</span></b></div>';
      }
      else
      {
          prwait.innerHTML = '<div style="text-align:center;padding-top:2px;">Wystąpił błąd:<br /><br /><b>' + error + '</b><br /><div style="margin-left: 160px; margin-top: 2px; position:absolute;"><a style="text-decoration: underline;" href="javascript:pagerank_przywroc();">sprawdź inną</a></div><b><span style="font-size: 14px;">&nbsp;</span></b></div>';
      }

      // czyscimy
      prform.strona.value = 'http://';
      prform.token.value = '';
      prform.kod.value = kod;

      // wgrywamy obrazek
      primag.src = '/img/token.png?t=' + kod;
  }

  function top (num)
  {
      // pętla
      for (var a = 1; a <= 3; a++)
      {
          // pobieramy elementy
          var d = document.getElementById('ctop' + a);
          var t = document.getElementById('ttop' + a);
          // czy nasz?
          if (a == num)
          {
              // widoczny i kolor zielony
              d.style.display = 'block';
              t.style.background = '#e5f5a4';
          }
          else
          {
              // niewidoczne i szare
              d.style.display = 'none';
              t.style.background = '#f9f9f9';
          }
      }
  }

  function setff (element)
  {
      ff = element.checked;
      zapisz ();
      window.location = adres;
  }

  function setnw (element)
  {
      nw = element.checked;
      update ();
      zapisz ();
  }

  function setso (element)
  {
      so = element.checked;
      opisy ();
      zapisz ();
  }

  function setsd (element)
  {
      sd = element.checked;
      dodatki ();
      zapisz ();
  }
  
  function setsk (element)
  {
      sk = element.checked;
      kategorieSlowa();
      zapisz ();
  }

  function update ()
  {
      if (!document.getElementsByTagName) return;
      var linki = document.getElementsByTagName("a");
      for (var i = 0; i < linki.length; i++)
      {
          var link = linki[i];
          if (link.getAttribute("href") && link.getAttribute ("rel") == "new")
          {
              if (nw == true) link.target = "_blank"; else link.target = "";
          }
      }
  }
                                                                                          
  function opisy ()
  {
      if (!document.getElementsByTagName) return;
      var linki = document.getElementsByTagName("div");
      for (var i = 0; i < linki.length; i++)
      {
          var link = linki[i];
          if (link.className == "mt5 opiss")
          {
              if (so == true) link.style.display = "block"; else link.style.display = "none";
          }
      }
  }

  function kategorieSlowa()
  {
      if (!document.getElementsByTagName) return;
      var linki = document.getElementsByTagName("div");
      for (var i = 0; i < linki.length; i++)
      {
          var link = linki[i];
          if (link.className == "mt5 katSlo")
          {
              if (sk == true) link.style.display = "block"; else link.style.display = "none";
          }
      }
  }
  
  function dodatki ()
  {
      if (!document.getElementsByTagName) return;
      var linki = document.getElementsByTagName("div");
      for (var i = 0; i < linki.length; i++)
      {
          var link = linki[i];
          if (link.className == "mt5 dodatki")
          {
              if (sd == true) link.style.display = "block"; else link.style.display = "none";
          }
      }
  }

  function setCookie (name, value)
  {
      document.cookie = name + '=' + escape (value) + '; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;';
  }

  function zapisz ()
  {
      var t = '';
      if (ff == true) t += '1'; else t += '0';
      if (nw == true) t += '1'; else t += '0';
      if (so == true) t += '1'; else t += '0';
      if (sd == true) t += '1'; else t += '0';
      if (sk == true) t += '1'; else t += '0';
      setCookie ('ustawienia', t);
  }

  function zmien ()
  {
      // zmiana zakładki
      akt = akt + 1;
      if (akt == 4) akt = 1;
      // zmieniamy
      top (akt);
      // ustawiamy timeouta
      window.setTimeout ('zmien()', 15000);
  }

  function odliczanie ()
  {
      // ustawiamy timeouta
      window.setTimeout ('zmien()', 15000);
  }

  function ero ()
  {
      return confirm ('Kategoria zawiera strony o tematyce erotycznej, przeznaczone dla osób pełnoletnich. Jesteś pełnoletni?');
  }
  
  function ustawStrone()
  {
  	update();
  	opisy();
  	dodatki();
  	kategorieSlowa();
  }
  
function swapToken()
	{
	 var token = document.getElementById('tokenimg');
	 token.src = token.src.replace(/(\?[0-9a-z]+)/,'?'+Math.round(Math.random()*100000));
	}  
  
  
  
function _geb(div_id)
	{
	 return document.getElementById(div_id);
	}

function show_comments(div_id)
	{
	 var comm_obj=_geb('comments_page_'+div_id);//div komentarzy
	 var href_comm_obj=_geb('href_comm_page_'+div_id);//link komentarzy
	 
	 //sprawdzamy ile komentarzy wyswietlamy 
	 if(window.location.toString().indexOf('katalog.gery.pl/strona')>-1)show_all='true';//dla strony strony wyswietlamy wszystkie komentarze
	  else show_all='false'; //dla strony listy stron wyswietlamy 3 pierwsze komentarze
	 	 
	 if(comm_obj.style.display=='block')//zamykamy
	  {
	   comm_obj.style.display='none';
	   href_comm_obj.innerHTML='&laquo; zobacz';
	  }
	 else //pokazujemy
	  {
	 	cancel_new_comment(div_id);
	 	comm_obj.innerHTML='<div><img src="http://katalog.gery.pl/img/loader.gif" border="0"></div>';
		advAJAX.get({
	 		url : '/kategorie_ajax.php',
			parameters : {
			"action" : "show_comments",
			"id" : div_id,
			"show_all" : show_all
			},
			onSuccess : function(obj) { eval(obj.responseText); },
			onError : function(obj) { alert("Error: " + obj.status); },
			mimeType: 'text/plain'
			});
	 	comm_obj.style.display='block';
	    href_comm_obj.innerHTML='&laquo; zamknij';	 	

	  }
	}
	
function add_new_comment(div_id)
	{
	 var comm_obj=_geb('comments_page_'+div_id);//ukrywamy liste komentarzy
	 //if(window.location.toString().indexOf('katalog.gery.pl/strona')==-1)if(comm_obj)comm_obj.style.display='none';//dla strony listy stron ukrywamy komentarze
	 comm_obj=_geb('href_comm_page_'+div_id);
	 if(comm_obj)comm_obj.innerHTML='&laquo; zobacz';	 	 
	 
	 comm_obj=_geb('new_comment_page_'+div_id);//div nowego komentarza
	 comm_obj.innerHTML='<textarea id="new_comment_content_'+div_id+'" rows="5" cols="20"></textarea><br/><a href="javascript:accept_new_comment('+div_id+')" class="fc4 nou">Dodaj</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:cancel_new_comment('+div_id+')" class="fc4 nou">Anuluj</a>';
	 comm_obj.style.display='block';
	}
	
function accept_new_comment(div_id)
	{
	 var comm_obj_content=_geb('new_comment_content_'+div_id);//tresc nowego komentarza
	 var comm_obj=_geb('new_comment_page_'+div_id);//div nowego komentarza
	 var href_comm_obj=_geb('href_comm_page_'+div_id);//div nowego komentarza

	 comm_obj.innerHTML='<div><img src="http://katalog.gery.pl/img/loader.gif" border="0"></div>';
		advAJAX.get({
	 		url : '/kategorie_ajax.php',
			parameters : {
			"action" : "accept_new_comment",
			"id" : div_id,
			"comment" : comm_obj_content.value
			},
			onSuccess : function(obj) { eval(obj.responseText); },
			onError : function(obj) { alert("Error: " + obj.status); },
			mimeType: 'text/plain'
			});

	 	comm_obj.style.display='block';
	    if(href_comm_obj)href_comm_obj.innerHTML='&laquo; zamknij';	 
	 	cancel_new_comment(div_id);
	 	show_comments(div_id);
	}
	
function cancel_new_comment(div_id)
	{
	 var comm_obj=_geb('new_comment_page_'+div_id);//div nowego komentarza
	 comm_obj.style.display='none';	
	}		
	
	
	
	