function $( id )  {
  return document.getElementById( id );
}

function imgshow(url, width, height)
{
	LeftPosition=(screen.width)?(screen.width-width)/2:100;
	TopPosition=(screen.height)?(screen.height-height)/2:100;
	var win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top=' + TopPosition + ',left=' + LeftPosition + ',resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no');
}

function showpic(url,name, width, height)
{
        LeftPosition=(screen.width)?(screen.width-width)/2:100;
    	 TopPosition=(screen.height)?(screen.height-height)/2:100;
        var Win = window.open(url,name,'width=' + width + ',height=' + height + ',top=70,left='+LeftPosition+',resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no')
}

function polecam(url, width, height)
{
	LeftPosition=(screen.width)?(screen.width-width)/2:100;
	TopPosition=(screen.height)?(screen.height-height)/2:100;
	try{
	 var popup = window.open(url,'popup','width=' + width + ',height=' + height + ',top=' + TopPosition + ',left=' + LeftPosition + ',resizable=0,scrollbars=no,menubar=no,toolbar=no,status=no');
	} catch(e) {}
}

// Zmiana wyswietlania faq w kategorii
function changeDisplay(id, cross)
{
  if( $(id).style.display=="none") {
    Effect.BlindDown(id, {duration:0.1});
    if( cross )  {
      $( cross ).src = 'css/img/katalog-minus.gif';
      $( cross ).title = 'zwiń';
    }
  } else {
    Effect.BlindUp(id, {duration:0.1});
    if( cross )  {
      $( cross ).src = 'css/img/katalog-plus.gif';
      $( cross ).title = 'rozwiń';
    }
  }
}

// Sprawdzanie czy zostala wybrana odpowiedz w sondzie przez zaglosowaniem
function checkPools(id)
{
  var sonda = document.getElementById(id);
  var tags = sonda.getElementsByTagName("input");
  for(i=0;i<tags.length;i++) {
    if(tags[i].checked) {
      sonda.submit();
      return;
    }
  }
  alert("Wybierz odpowiedź na którą chcesz zagłosować!");
}

// Sprawdzanie czy slowo kluczowe nie jest puste
function checkKeyword()
{
  if(document.getElementById("keyword").value == "") {
    return false;
  } else {
    return true;
  }
}

function opinieChangeStatus()  {
  var oldStatus = document.getElementById( 'opinietable' ).style.display;
  //alert( oldStatus );
  if( oldStatus == 'block' )  {
    document.getElementById( 'opiniebuton' ).innerHTML = '(+)';
    document.getElementById( 'opinietable' ).style.display = 'none';
  }
  else  {
    document.getElementById( 'opiniebuton' ).innerHTML = '(-)';
    document.getElementById( 'opinietable' ).style.display = 'block';
  }
}

function SearcherSubmit()  {
  if( checkKeyword() && document.getElementById( "keyword" ).value != "Podaj frazę!" )  {
    document.wyszukiwarka.submit ()
  }
  else  {
    document.getElementById( "keyword" ).value = "Podaj frazę!"
  }
}
// do karty produktów - ładuje klikniete male zdjecie do duzego boxa na zdjecie
function LoadToBigImage(zdjecie,idElement){
  document.getElementById(idElement).src = "{#toolsPath#}thumb.php?file="+zdjecie+"&dir={#fotoPath#}&w=210";
}

function getElementsByClassName(cn){
  var arr = new Array();
  var els = document.getElementsByTagName("*");
  var exp= new RegExp("^(.* )?"+cn+"( .*)?$", "g");
  for (var i = 0; i < els.length; i++ ){
    if (exp.test(els[i].className)){
      arr.push(els[i]);
    }
  }
  return arr;
}

function TrybWyszukiwarki()  {
  var oldStatus = $( 'szukaj-extra' ).style.display;
  if( oldStatus == 'none' || oldStatus == '' )  {
    $( 'szukaj-extra' ).style.display = 'block';
    $( 'szuk-but' ).src = 'css/img/szukajka-button-tooff.jpg';
  }
  else  {
    $( 'szukaj-extra' ).style.display = 'none';
    $( 'szuk-but' ).src = 'css/img/szukajka-button-toon.jpg';
  }
}

function SearcherClear(name)  {
  var elem = $(name).elements;
  var count = elem.length;
  for( i=0; i<count; i++ )  {
      elem[i].value = '';
  }
  document.getElementById( 'szukajka-form' ).submit();
}

function PokazOceny()  {
  $( 'marks' ).style.display = 'block';
  $( 'panel-switcher' ).innerHTML = '[ zwiń panel ]';
  $( 'panel-switcher' ).onclick = function()  { OcenyZwin(); };
  $( 'dodajocene' ).style.display = 'none';
  $( 'zobaczoceny' ).style.display = 'block';
}

function OcenyZwin()  {
  $( 'marks' ).style.display = 'none';
  $( 'panel-switcher' ).innerHTML = '[ zobacz ]';
  $( 'panel-switcher' ).onclick = function()  { PokazOceny(); };
  $( 'dodajocene' ).style.display = 'none';
  $( 'zobaczoceny' ).style.display = 'none';
}

function Ocen()  {
  $( 'marks' ).style.display = 'block';
  $( 'dodajocene' ).style.display = 'block';
  $( 'zobaczoceny' ).style.display = 'none';
}


function timer()  {
  var data = new Date();
  var godzina = data.getHours().toString();;
  var minuta = data.getMinutes().toString();
  if( minuta.length == '1' )  {
    minuta = '0'+minuta;
  }
  $( 'aktualnaGodzina' ).innerHTML = godzina +':'+ minuta;
  t = setTimeout( "timer()", 1000 );
}


//popup
function popup(url,width, height)
{
   LeftPosition=(screen.width)?(screen.width-width)/2:100;
   TopPosition=(screen.height)?(screen.height-height)/2:100;
   var Win = window.open(url,'showpic','width=' + width + ',height=' + height + ',top='+TopPosition+',left='+LeftPosition+',resizable=0,scrollbars=yes,menubar=no,toolbar=no,status=no')
}

function pokazAlboUkryj(id,max) { 
  for(i=0; i<=max; i++){
    if(i==id && document.getElementById( 'rodz'+i )){
      document.getElementById( 'rodz'+i ).style.display = 'block';
    } 
    else if (i!=id && document.getElementById( 'rodz'+i )) {
      document.getElementById( 'rodz'+i ).style.display = 'none';
    }
  }
}

function pokazAlboUkryjModele(id,max) { 
  for(i=0; i<=max; i++){
    if(i==id && document.getElementById( 'mod'+i )){
      document.getElementById( 'mod'+i ).style.display = 'block';
    } 
    else if (i!=id && document.getElementById( 'mod'+i )) {
      document.getElementById( 'mod'+i ).style.display = 'none';
    }
  }
}

function pokazAlboUkryjRodzine(id,max) { 
  for(i=0; i<=max; i++){
    if(i==id && document.getElementById( 'rodz'+i )){
      document.getElementById( 'rodz'+i ).style.display = 'block';
    } 
    else if (i!=id && document.getElementById( 'rodz'+i )) {
      document.getElementById( 'rodz'+i ).style.display = 'none';
    }
  }
}