function ajaxPokazWartosciSladu(idElementu, idSladu, plik){
	new Ajax.Updater(idElementu, plik, {
		method: 'post', 
		ghosting:false,
		constraint:false,
		parameters:'id_sladu='+idSladu, 
		evalScripts:true, 
		asynchronous:true
	});
	return true;
}

function ustawWartosc(nazwaPola, wartosc){
	document.getElementById(nazwaPola).value = wartosc;
}

function zaznacz_wszystko(co, formularz, przyc){
	d = eval("document." + formularz + "");
	p = document.getElementById(przyc);
	zaznaczone = 0;
	if(p.checked){
		zaznaczone = 1;
	}
	for (i = 0; i<d.elements.length; i++){
		if(d.elements[i].type=='checkbox'){
			pom = d.elements[i].name.split("_");
			if(pom[0]==co){
				if(zaznaczone){
					d.elements[i].checked = true;
				}else{
					d.elements[i].checked = false;
				}
			}
		}
	}
}

function ustaw_checkboxy(formularz, opcja){
	d = eval("document." + formularz + "");
	if(opcja == "select"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				d.elements[i].checked = true;
			}
		}
	}else if(opcja == "deselect"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				d.elements[i].checked = false;
			}
		}
	}else if(opcja == "invert"){
		for (i = 0; i<d.elements.length; i++){
			if(d.elements[i].type == "checkbox"){
				if(d.elements[i].checked == true){
					d.elements[i].checked = false;
				}else{
					d.elements[i].checked = true;
				}
			}
		}
	}
}

function pokazUkryjPola(id, znacznik, ukryjClass, pokazClass){
	elts = document.getElementsByTagName(znacznik);
	check = document.getElementById(id);
	for(i=0;i<elts.length;i++){
		if(check.checked){
			if(elts[i].className==ukryjClass){
			   elts[i].className=pokazClass;
			}
		}else{
			if(elts[i].className==pokazClass){
			     elts[i].className=ukryjClass;
			}
		}
	}
	return true;
}

function formatuj_liczbe(n, dokladnosc){
	/*
	n = Math.round(n * 100) / 100;
	//n = (n + 0.001) + '';
	n = (n + 0.001) + '';
	n = (n - 0.001) + '';
	//alert("n: " + n);
	return n.substring(0, n.indexOf('.') + 3);
	*/
	//num = 930.9805;
	//result = n.toFixed(2);
	return n.toFixed(dokladnosc);
}

function limit_dla_pola(limit, pole, span_pole){
	if (document.getElementById(pole).value.length > limit){
		document.getElementById(pole).value = document.getElementById(pole).value.substring(0, limit);
	}
	if(span_pole.length > 0){
		txt = "";
		ile_pozostalo = limit - document.getElementById(pole).value.length;
		txt = "<br>Pozostało/Remaining " + ile_pozostalo + " z/from " + limit + " znaków/chars.";
		document.getElementById(span_pole).innerHTML = txt;
	}
}

function migajacy_text(id, k1, t1, k2, t2){
  if (document.getElementById){
    document.getElementById(id).style.color = k1;
	setTimeout('migajacy_text("' +  id + '","' + k2 + '",' + t2 + ',"' + k1 + '",' + t1 + ')', t1);
  }else if (document.all){
    document.all[id].style.color = k1;
	setTimeout('migajacy_text("' +  id + '","' + k2 + '",' + t2 + ',"' + k1 + '",' + t1 + ')', t1);
  }
}

function popraw_telefon(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^0-9\(\)\ ]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function sprawdz_mail(email_pole) {
	if (document.getElementById(email_pole).value.length>0){
		Wzor = /^[0-9a-zA-Z.-_\-]+\@[0-9a-zA-Z.-_\-]+\.[0-9a-zA-Z.]{2,4}$/;
	   	if (Wzor.test(document.getElementById(email_pole).value) == false){
    		alert("Niewłasciwy format adresu e-mail!");
	    	return false;
	    }  
   		return true; 
    }
  	return true;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore(){ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages(){ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d){ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage(){ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function pop_new_window(nazwa_pliku, zmienna, id, qs){
	var plik = nazwa_pliku + "?" + zmienna + "=" + id + qs;
	var Win = window.open(plik, "text","menubar=0,location=0,status=0,toolbar=0,directories=0,alwaysRaised=1,scrollbars=1,titlebar=1,resizable=1");
}

function pop_zdjecie(nazwa_zdjecia_big, nazwa_podkatalogu){
	var plik = "pop_zdjecie.php?foto=" + nazwa_zdjecia_big + "&podkatalog=" + nazwa_podkatalogu;
	var Win = window.open(plik, "big_foto","width=100,height=100,menubar=0,location=0,status=0,toolbar=0,directories=0,alwaysRaised=1,scrollbars=1,titlebar=1,resizable=1");
}

function przytnij_text(text, max_znakow){
	if (text.length > max_znakow){
		text = text.substring(0, max_znakow);
	}
	return text;
}

function tylko_cyfry(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^0-9]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function tylko_litery(nazwa_pola, max_znakow) {
    document.getElementById(nazwa_pola).value = document.getElementById(nazwa_pola).value.replace(/[^a-z]/g,"");
	if(max_znakow.length > 0){
		document.getElementById(nazwa_pola).value = przytnij_text(document.getElementById(nazwa_pola).value, max_znakow);
	}
}

function usun_biale_znaki(ciag){
	ciag = ciag.replace(/\r/g, " ");
  	ciag = ciag.replace(/[^ A-Za-z0-9`~!@#\$%\^&\*\(\)-_=\+\\\|\]\[\}\{'";:\?\/\.>,<]/g, "");
	ciag = ciag.replace(/'/g, "");
	ciag = ciag.replace(/ +/g, " ");  
	ciag = ciag.replace(/^\s/g, "");
	ciag = ciag.replace(/\s$/g, "");	
	return ciag;
}

function wylicz_wartosc(licznik, pole_baza, pole_zmiana, pole_vat, opcja){
	if(opcja == 'brutto'){
		document.getElementById(pole_zmiana).value = formatuj_liczbe(document.getElementById(pole_baza).value * (1 + usun_biale_znaki(document.getElementById(pole_vat).value) / 100), 3);
	}else if(opcja == 'netto'){
		document.getElementById(pole_zmiana).value = formatuj_liczbe(document.getElementById(pole_baza).value / (1 + usun_biale_znaki(document.getElementById(pole_vat).value) / 100), 3);
		//netto=(brutto*100)/(100+VAT)
		//alert("baza: " + document.getElementById(pole_baza).value * 100);
		//alert("vat: " + usun_biale_znaki(document.getElementById(pole_vat).value);
		//document.getElementById(pole_zmiana).value = formatuj_liczbe( (document.getElementById(pole_baza).value * 100) / (100 + usun_biale_znaki(document.getElementById(pole_vat).value)) );
		
	}
	document.getElementById("oszczedzasz_"+licznik).value = formatuj_liczbe((1*document.getElementById("cena_"+licznik).value) - (1*document.getElementById("cenaspecjalna_"+licznik).value),3);
	document.getElementById("oszczedzaszbrutto_"+licznik).value = formatuj_liczbe((1*document.getElementById("cenabrutto_"+licznik).value) - (1*document.getElementById("cenaspecjalnabrutto_"+licznik).value),3);
}

function scrolling(elementId, szer){
	
   var IE = (document.all && document.getElementById && !window.opera );
   var FF = (!document.all && document.getElementById && !window.opera);
   var OP = (document.all && document.getElementById && window.opera);
   
   pom = document.getElementById(elementId);	 
   tab = pom.clientHeight;
   
   if(window.innerHeight){
	   mouseX = (screen.width/2) - (szer/2) - ((screen.width-window.innerWidth)/2)+window.pageXOffset;
	   mouseY = (screen.height/2) - (tab/2) - ((screen.height-window.innerHeight)/2)+window.pageYOffset;
	}else if(document.documentElement && document.documentElement.clientWidth){
	   mouseX = (screen.width/2) - (szer/2) - ((screen.width-document.documentElement.clientWidth)/2)+document.documentElement.scrollLeft;
	   mouseY = (screen.height/2) - (tab/2) - ((screen.height-document.documentElement.clientHeight)/2)+document.documentElement.scrollTop;
	}else if(document.body && document.body.clientWidth){
	  mouseX = (screen.width/2) - (szer/2) - ((screen.width-document.body.clientWidth)/2)+document.body.scrollLeft;	
	  mouseY = (screen.height/2) - (tab/2) - ((screen.height-document.body.clientHeight
		
)/2)+document.body.scrollTop;
	}
		
	document.getElementById(elementId).style.display='block';
	document.getElementById(elementId).style.top=mouseY+"px";
	document.getElementById(elementId).style.left=mouseX+"px";
}

function dodajIframe(elementId, szer){

       var IE = (document.all && document.getElementById && !window.opera );
       var FF = (!document.all && document.getElementById && !window.opera);
       var OP = (document.all && document.getElementById && window.opera);
	   
		if(IE){
			var pom1 = document.getElementById(elementId);
			pom1.innerHTML += '<iframe style="position: absolute; display: block; z-index: -1; width: '+szer+'px; height: '+pom1.clientHeight+'px; top: 0; left: 0; filter: mask(); border:1px solid #333333;"></iframe>';
		}
}

function dodajIframe1(elementId){

       var IE = (document.all && document.getElementById && !window.opera );
       var FF = (!document.all && document.getElementById && !window.opera);
       var OP = (document.all && document.getElementById && window.opera);
	   
		if(IE){
			var pom1 = document.getElementById(elementId);
			pom1.innerHTML += '<iframe style="position: absolute; display: block; z-index: -1; width: 100%; height: '+pom1.clientHeight+'px; top: 0; left: 0; filter: mask(); border:1px solid #333333;"></iframe>';
		}
}

function showhide_layer(elementId, idTekstu, akcja, prod, rozm, szer){
    
	var mouseX = 0;
	var mouseY = 0;
	
	var IE = (document.all && document.getElementById && !window.opera );
    var FF = (!document.all && document.getElementById && !window.opera);
    var OP = (document.all && document.getElementById && window.opera);
	
    var pom = document.getElementById(elementId);
	
	if(akcja){
			
		if(pom){
			document.body.removeChild(pom);
		}
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id',elementId);
		newdiv.style.width=szer+'px';
		newdiv.style.backgroundColor = '#FFFFFF';
		newdiv.style.border='1px solid #333333';
		newdiv.style.position = 'absolute';
		newdiv.style.zIndex = 9;
		newdiv.innerHTML = 'Trwa ładowanie danych ...';
		document.body.appendChild(newdiv);
		scrolling(elementId,szer);
		
		
		variables='idp='+idTekstu+'&akcja='+akcja+'&id_produktu='+prod+'&rozmiar='+rozm+'&szer='+szer;
		url = 'http://www.outlet.bartek.com.pl/ajax_pokaz_info.php';
		new Ajax.Updater(elementId, url, {
		method: 'post', 
		ghosting:false,
		constraint:false,
		parameters: variables, 
		onComplete: function(){
			dodajIframe(elementId,szer);
		},
		evalScripts:true, 
		asynchronous:true
	});
		
	    scrolling(elementId);
		
	    window.onscroll = function(){
			scrolling(elementId,szer);
		};	
		
		window.onresize = function(){
			scrolling(elementId,szer);
		};
		
		
	}else{
		if(pom){
			document.body.removeChild(pom);
		}
		window.onscroll = function(){
			void(0);
		}
	}
	
	return false;
}

function showhide_layer_history(elementId, idProduktu, akcja, szer){
    
	var mouseX = 0;
	var mouseY = 0;
	
	var IE = (document.all && document.getElementById && !window.opera );
    var FF = (!document.all && document.getElementById && !window.opera);
    var OP = (document.all && document.getElementById && window.opera);
	
    var pom = document.getElementById(elementId);
	
	if(akcja){
			
		if(pom){
			document.body.removeChild(pom);
		}
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id',elementId);
		newdiv.style.width=szer+'px';
		newdiv.style.height='350px';
		newdiv.style.backgroundColor = '#FFFFFF';
		newdiv.style.border='1px solid #333333';
		newdiv.style.position = 'absolute';
		newdiv.style.overflow = 'auto';
		newdiv.style.zIndex = 9;
		newdiv.innerHTML = 'Trwa ładowanie danych ...';
		document.body.appendChild(newdiv);
		scrolling(elementId,szer);
		
		
		variables='akcja='+akcja+'&id_produktu='+idProduktu+'&szer='+szer;
		url = 'ajax_pokaz_historie_cen.php';
		new Ajax.Updater(elementId, url, {
		method: 'post', 
		ghosting:false,
		constraint:false,
		parameters: variables, 
		onComplete: function(){
			dodajIframe(elementId,szer);
		},
		evalScripts:true, 
		asynchronous:true
	});
		
	    scrolling(elementId);
		
	    window.onscroll = function(){
			scrolling(elementId,szer);
		};	
		
		window.onresize = function(){
			scrolling(elementId,szer);
		};
		
		
	}else{
		if(pom){
			document.body.removeChild(pom);
		}
		window.onscroll = function(){
			void(0);
		}
	}
	
	return false;
}

function pokazUkryjTopLayer(id1, id2, opcja){
	
   if(opcja){
       document.getElementById(id1).style.display='block';
       document.getElementById(id2).style.display='block';
	   animacjaPrzezroczystosci(id2, 0, 70);
   }else{
	   document.getElementById(id1).style.display='none';
       document.getElementById(id2).style.display='none';
   }
   
}

function animacjaPrzezroczystosci(id, aktualny, wspolczynnik){
	
	if(aktualny<=wspolczynnik){
	
		var object = document.getElementById(id).style;
	    object.opacity = (aktualny / 100);
        object.MozOpacity = (aktualny / 100);
        object.KhtmlOpacity = (aktualny / 100);
        //object.filters.alpha.opacity = aktualny;
        object.filter = "alpha(opacity=" + aktualny + ")";
		
		setTimeout('animacjaPrzezroczystosci(\''+id+'\', '+(aktualny+10)+', \''+wspolczynnik+'\')',100);
   }
   
   return true;
}

function showhide_layer2(elementId, akcja){
    
	var mouseX = 0;
	var mouseY = 0;
	
	var IE = (document.all && document.getElementById && !window.opera );
    var FF = (!document.all && document.getElementById && !window.opera);
    var OP = (document.all && document.getElementById && window.opera);
	
    var pom = document.getElementById(elementId);
	
	if(akcja){
			
		pom.style.display = 'block';
		scrolling(elementId,pom.clientWidth);
		
	    window.onscroll = function(){
			scrolling(elementId,pom.clientWidth);
		};	
		
		window.onresize = function(){
			scrolling(elementId,pom.clientWidth);
		};
		
		
	}else{
		window.onscroll = function() {};
		window.onresize = function() {};
		pom.style.display = 'none';
	}
	
	return false;
}


function ShowEffect(element1, element2){
	   
	   if(!getCookie('bartek_ankieta') && !getCookie('bartek_ankieta_nie')){
		   
		   el = document.getElementById(element1);
		   el.style.display='block'; 
		   if(document.getElementById('glowny').offsetHeight){
			   
			   el.style.height = document.getElementById('glowny').offsetHeight+'px';
		   }
		   dodajIframe1(element1);
		   new Effect.Opacity(element1, 
		   {duration:2, from:0, to:0.7});
			setTimeout('showhide_layer2(\''+element2+'\', 1)',1800);
	   }
	   
	 return true;
}

function HideEffect(element1, element2){
       new Effect.Opacity(element1, 
       {duration:2, from:0.7, to:0});
	   setTimeout('showhide_layer2(\''+element1+'\', 0)',500);
	   el = document.getElementById(element2);
	   el.style.display='none'; 
	   return true;
 }
 
 function przekieruj(element1, element2){
	 HideEffect(element1, element2);
	 document.location = 'http://www.outlet.bartek.com.pl/wypelnij_ankiete.php?id=8';
	 return true;
 }

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function zamknij(ile_dni){
	setCookie('bartek_ankieta_nie', 'nie', ile_dni);
	HideEffect('fade', 'light');
}