//ukrywanie i wyswietlanie diva
function shDiv(id){
	//lapanie elementu
	elem = document.getElementById(id);
	if(elem.style.display == 'none') {
		elem.style.display='block';
	} else {
		elem.style.display = 'none';
	}
}

// Inicjalizacja skryptow
function init()
{
  prepend();
//  initLightbox();
  winOnLoad();
}
/*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 ChangeAttribute( elem, attr, value )
{
	elem.attr = value;
}

function prepend()
{
  document.cookie = "screenWidth="+ screen.width;
  document.cookie = "screenHeight="+ screen.height;
  var leftMarg = (screen.width/2)-100;
  var topMarg = (screen.height/3);
  if( $('error-layer') )  {
    document.getElementById( 'error-layer' ).style.left = leftMarg+'px';
    document.getElementById( 'error-layer' ).style.top = topMarg+'px';
    new Draggable( 'error-layer' );
  }
  if( $('info-layer') )  {
		document.getElementById( 'info-layer' ).style.left = leftMarg+'px';
		document.getElementById( 'info-layer' ).style.top = topMarg+'px';
		new Draggable( 'info-layer' );
  }
}

// Zamykanie banera
function closeBanner()
{
  document.getElementById('floater').style.visibility="hidden";
  document.getElementById('floater').style.display="none";
  document.getElementById('topbanner').style.visibility="visible";
}

// Zamykanie banera
function closeSkyscraper()
{
  document.getElementById('floater2').style.visibility="hidden";
  document.getElementById('floater2').style.display="none";
  document.getElementById('towerbanner').style.visibility="visible";
}

// Zamykanie banera
function closeScroller()
{
  document.getElementById('floater3').style.display="none";
}

// Funkcje do "latajacych" banerow {{{
var slideTime = 700;
var topMargin1, topMargin2;
var height;
function winOnLoad()
{
  // do banera
  topMargin1 = xPageY('topbanner');
  topMargin1 = topMargin1 - 15;
  // do scrollera
  topMargin3 = 500;
  height = getHeight();
  topMargin3 = height - 55;
  winOnResize(); // set initial position
  xAddEventListener(window, 'resize', winOnResize, false);
  xAddEventListener(window, 'scroll', winOnScroll, false);
  return;
}

function winOnResize()
{
  height = getHeight();
  topMargin3 = height - 55;
  // do banera
  xMoveTo('floater', xPageX('topbanner'), topMargin1);
  xShow('floater');
  // do scrollera
  xMoveTo('floater3', 0, topMargin3);
  xShow('floater3');
  winOnScroll(); // initial slide
}

function winOnScroll()
{
  // do banera
  xSlideTo('floater', xLeft('floater'), xScrollTop() + topMargin1, slideTime);
  // do scrollera
  xSlideTo('floater3', xLeft('floater3'), xScrollTop() + topMargin3, slideTime);
}

function setSlideTime(st) {
  st = parseInt(st);
  if (!isNaN(st)) slideTime = st;
  var e = xGetElementById('st');
  e.value = st;
  return false;
}

function getWidth()
{
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getHeight()
{
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}









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.jpg';
      $( cross ).title = 'zwiń';
    }
  } else {
    Effect.BlindUp(id, {duration:0.1});
    if( cross )  {
      $( cross ).src = 'css/img/katalog-plus.jpg';
      $( 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++ )  {
    if( elem[i].type == 'text' )  {
      elem[i].value = '';
    }
    else if( elem[i].type == 'select-one' )  {
      elem[i].value = '';
    }
  }
  document.getElementById( name ).submit();
}

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

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

function OcenyZwin()  {
  $( 'marks' ).style.display = 'none';
  $( 'dodajocene' ).style.display = 'none';
  $( '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')
}

/**************** zamienik dla target="_blank" w XHTML *****************/
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;


function checkNip(id,length) {
	var elem=document.getElementById(id).size;
	if( elem < 10) {
		alert("Wprowadz poprawny NIP");
		document.getElementById("dalej").diabled=true;
	} else {
		document.getElementById("dalej").diabled=false;
	}
}