// deflasherizer [Eolas Patent Remover]
function deflasherizer()
{
	objects = document.getElementsByTagName("noscript");
	for (var i = objects.length - 1; i >= 0 ; i--)
	{
		var html = objects[i].innerHTML;
		html = html.substring(12, html.length-12);
		objects[i].outerHTML = html;
	}
}

function findObj(obj) {
	return document.getElementById(obj);
}

function preloadimages(images) {
	if (!images) {
		var images = new Array();
	}
	var img = new Array();
	for (i=0; i<images.length; i++) {
		img[i] = new Image();
		img[i].src = images[i];
	}
}

function swapImage(id, img) {
	o = findObj(id);
	if(o) {
		o.src = img;
	}
}

function SendTo(before, after, user, host, label) {
	label = label.replace(' // ', '@');
	document.write('<a' + before + 'href="mailto:' + user + '@' + host + '"' + after+'>' + label + '</a>');
}

/* Przegladarka zdjec */
$(document).ready(function() {
	$('a[@rel*=lightbox]').lightBox();
	$('a[@class*=lightbox]').lightBox();
}); 


// zdjecie bez opisu
function showImage(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (w > aw) {
		w = aw;
	}
	if (h > ah) {
		h = ah;
	}
	
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=no,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// zdjêcie z opisem
function showOImage(src, w, h, opis) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		w = w + 32;
		oldH = h;
		h = h + 45;
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		noweOkienko = window.open("/showImage.php?src="+src+":"+opis, 'obrazek', ustawienia);
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// popup
function popUpWindow(src, w, h) {
	noweOkienko = null;
	if (window.screen) {
		aw = screen.availWidth;
		ah = screen.availHeight;
	} else {
		aw = 640;
		ah = 450;
	}
	if (noweOkienko==null || noweOkienko.closed) {
		ustawienia=
		"left=" + (aw-w)/2 + ","
		+"top=" + (ah-h)/2 + ","
		+"screenX=" + (aw-w)/2 + ","
		+"screenY=" + (ah-h)/2 + ","
		+"width=" + w + ","
		+"height=" + h + ","
		+"innerWidth=" + w + ","
		+"innerHeight=" + h + ","
		+"toolbar=no,"
		+"location=no,"
		+"directories=no,"
		+"status=yes,"
		+"menubar=no,"
		+"scrollbars=yes,"
		+"resizable=no"
		var url = '/' + src; 
		noweOkienko = window.open(url, 'plik', ustawienia);
		
	}
	try {
		noweOkienko.focus();
	}
	catch (e) {
	}
}

// drukuj
function printWindow(src) {
	popUpWindow(src, 640, 450);
}

// base64 decode script
function decode64(input) {
	var output = "";
	var chr1, chr2, chr3 = "";
	var enc1, enc2, enc3, enc4 = "";
	var i = 0;
	var keyStr = 	"ABCDEFGHIJKLMNOP" +
					"QRSTUVWXYZabcdef" +
					"ghijklmnopqrstuv" +
					"wxyz0123456789+/" +
					"=";

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;
	if (base64test.exec(input)) {
		alert("There were invalid base64 characters in the input text.\n" +
					"Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
					"Expect errors in decoding.");
	}
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64) {
			output = output + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			output = output + String.fromCharCode(chr3);
		}

		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	} while (i < input.length);

	return output;
}

// rozwijanie listy wynikow w wyszukiwarce
function showResult(id) {
	o = document.getElementById(id);
	if (o.style.display == 'none') {
		o.style.display = 'block';
	} else {
		o.style.display = 'none';
	}
}

function limiter(obj, limit) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
	}
}

// obliczanie pozostalych znakow w textarea
function limit(obj, limit, msg) {
	if (obj.value.length > limit) {
		obj.value = obj.value.substring(0,limit);
		alert(msg);
	}
}

function getCookie(name)
{
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	
	while (cbegin < clen)
	{ 
		var vbegin = cbegin + cname.length;
	
		if (dc.substring(cbegin, vbegin) == cname)
		{ 
			var vend = dc.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
	
			return unescape(dc.substring(vbegin, vend));
		}
	
		cbegin = dc.indexOf(" ", cbegin) + 1;
	
		if (cbegin== 0) break;
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure)
{
	path = '/';
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function replaceStyle (symbol) 
{
	document.getElementById(symbol).className = 'tabelkaMenuHover';		
}

function replaceStyle_ (symbol) 
{
	document.getElementById(symbol).className = 'tabelkaMenu';
}

function fadeIn(sEl, startFade, endFade) {
	clearTimeout(iFadeInTimeOut);
	var iFadeTimer = 0;
	// ustawienie warstwy jako nieprzezroczystej
	setOpacity(0, sEl.id);
	for (i = startFade; i <= endFade; i++) {
		iFadeInTimeOut = setTimeout("setOpacity(" + i + ", '" + sEl.id + "')", (iFadeTimer * 5));
		iFadeTimer++;
	}
}

function setOpacity(opacity, sEl) {
	el = document.getElementById(sEl);
	
	el.style.opacity = (opacity / 100);
	el.style.MozOpacity = (opacity / 100);
	el.style.KhtmlOpacity = (opacity / 100);
	el.style.filter = "alpha(opacity=" + opacity + ")";
}

function showNextProduct() {
	clearTimeout(iTimeOut);
	
	var oContainer = document.getElementById('produkty_kontener');
	if(oContainer)
	{
	var aProducts = oContainer.getElementsByTagName('DIV');
	for (var i = 0; i < aProducts.length; i++) {
		if (aProducts[i].id.indexOf('produkt__') != -1) {
			if (aProducts[i].style.display == 'block') {
				aProducts[i].style.display = 'none';
				// sprawdzenie czy produkt nie jest ostatnim produktem
				// jezeli nie ustawienie display nastepnego produktu na block
				// w przeciwnym wypadku ustawienie na block pierwszego elementu
				if ((i+1) <= aProducts.length-1) {
					fadeIn(aProducts[i+1], 0, 99.99);
					aProducts[i+1].style.display = 'block';
				}
				else {
					fadeIn(aProducts[0], 0, 99.99);
					aProducts[0].style.display = 'block';
				}
				break;
			}
		}
	}
	iTimeOut = setTimeout("showNextProduct()", 5000);
	}
}

function showPreviousProduct() {
	clearTimeout(iTimeOut);
	var oContainer = document.getElementById('produkty_kontener');
	var aProducts = oContainer.getElementsByTagName('DIV');
	for (var i = aProducts.length - 1; i >= 0; i--) {
		if (aProducts[i].id.indexOf('produkt__') != -1) {
			if (aProducts[i].style.display == 'block') {
				aProducts[i].style.display = 'none';
				// sprawdzenie czy produkt nie jest ostatnim produktem
				// jezeli nie ustawienie display nastepnego produktu na block
				// w przeciwnym wypadku ustawienie na block pierwszego elementu
				if ((i-1) >= 0) {
					fadeIn(aProducts[i-1], 0, 99.99);
					aProducts[i-1].style.display = 'block';
				}
				else {
					fadeIn(aProducts[aProducts.length-1], 0, 99.99);
					aProducts[aProducts.length-1].style.display = 'block';
				}
				break;
			}
		}
	}
	iTimeOut = setTimeout("showPreviousProduct()", 5000);
}

function runNewProducts() {
	iTimeOut = setTimeout("showNextProduct()", 5000);
	iFadeInTimeOut = 0;
}


function insert_flash(naglowek, napis1, napis2)
{
	document.write(
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="678" height="101" id="naglowki" align="middle">' + 
	'	<param name="allowScriptAccess" value="sameDomain" />' + 
	'	<param name="movie" value="flash/naglowki.swf?link='+naglowek+'&amp;napis1='+napis1+'&amp;napis2='+napis2+'" />' + 
	'	<param name="quality" value="high" />' + 
	'	<param name="bgcolor" value="#ffffff" />' + 
	'	<param name="FlashVars" value="link='+naglowek+'&amp;napis1='+napis1+'&amp;napis2='+napis2+'" />' + 
	'	<embed src="flash/naglowki.swf?link='+naglowek+'&amp;napis1='+napis1+'&amp;napis2='+napis2+'" quality="high" bgcolor="#ffffff" width="678" height="101" name="naglowki" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' + 
	'</object>'
	);
}

	function banerboczny(id)
	{
		if(id==1)
		{
			//$("#mapkaFlash1").css('top','0px');
			document.getElementById('mapkaFlash1').style.top = "0px";
			//$("#mapkaFlash").css('top','-1000px');
			document.getElementById('mapkaFlash').style.top = "-1000px";
		}
		if(id==0)
		{
			//$("#mapkaFlash").css('top','0px');
			document.getElementById('mapkaFlash').style.top = "0px";
			//$("#mapkaFlash1").css('top','-1000px');
			document.getElementById('mapkaFlash1').style.top = "-1000px";
		}
	}
	
	function hideflash ()
	{
		var mapka = null;
		if (mapka = document.getElementById('mapkaFlash')) {
			mapka.style.display = "none";
			setTimeout("pokaziukryj()",'2000');
		}
	}
	
	function pokaziukryj()
	{
		document.getElementById('mapkaFlashFirst').style.display = "none";
		document.getElementById('mapkaFlash').style.display = "block";
	}