/* Zarządzanie wykonywaniem skryptow po doczytaniu strony */
var EditoStart = new Object();
EditoStart.functions = new Array();

EditoStart.Add = function(fnc)
{
	EditoStart.functions[EditoStart.functions.length] = fnc;
}

EditoStart.init = function()
{
	for(var i = 0; i < EditoStart.functions.length; i++)
	{
		EditoStart.functions[i]();
	}
}

window.onload = function()
{
	EditoStart.init();
}

/* Przegladarka zdjec */
$(document).ready(function()
{
	$('a[@rel*=lightbox]').lightBox();

});

/* Deflasherizer [Eolas Patent Remover] */
function deflasherizer()
{
	var objects = document.getElementsByTagName("noscript");
	for (var i = objects.length - 1; i >= 0 ; i--)
	{
		var html = objects[i].innerHTML;
		html = html.replace(/.*<\!\[endif\]-->|<\!--\[if\sIE\]>.*/gi, '');
		objects[i].outerHTML = html;
	}
}
EditoStart.Add(deflasherizer);


/* Galeria zdjec */
var EditoImg = new Object();
EditoImg.Keyword = new String("editoimg");
EditoImg.BorderSize = 1;
EditoImg.Index = 0;
EditoImg.Images = new Array();

EditoImg.init = function()
{
	var anchors = document.getElementsByTagName('a');
	
	for(var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		var rel = anchor.getAttribute('rel');
		
		if(anchor.getAttribute('href') && rel && rel.toLowerCase().match(EditoImg.Keyword))
		{
			anchor.onclick = EditoImg.Click;
		}
	}
	
	var html = '';
	html += '<div id="EditoImg$Overlay" class="PopupOverlay" style="display:none;"></div>';
	html += '<iframe id="EditoImg$Background" style="display:none;"></iframe>';
	html += '<table cellspacing="0" cellpadding="0" border="0" id="EditoImg$Panel" class="Popup" style="display:none;">';
	html += '	<tr>';
	html += '		<td align="right"><div id="EditoImg$IcoClose" class="IcoClose"></div></td>';
	html += '	</tr>';
	html += '	<tr>';
	html += '		<td id="EditoImg$Container" class="ImageContainer">';
	html += '			<img id="EditoImg$Preview" class="Preview"/>';
	html += '			<div id="EditoImg$Loader" class="Loader"></div>';
	html += '		</td>';
	html += '	</tr>';
	html += '	<tr id="EditoImg$Bottom"><td>';
	html += '		<table width="100%" cellspacing="0" cellpadding="0" border="0">';
	html += '			<tr>';
	html += '				<td id="EditoImg$Prev" class="Prev"><div></div></td>';
	html += '				<td id="EditoImg$Caption" class="Caption"></td>';
	html += '				<td id="EditoImg$Next" class="Next"><div></div></td>';
	html += '			</tr>';
	html += '		</table>';
	html += '	</td></tr>';
	html += '</table>';
	
	var body = document.getElementsByTagName("body")[0];
	var span = document.createElement("span");
	span.innerHTML = html;
	body.appendChild(span);
	
	EditoImg.Item("Prev").onclick = EditoImg.PrevImage;
	EditoImg.Item("Next").onclick = EditoImg.NextImage;
}

EditoImg.Item = function(id)
{
	return document.getElementById("EditoImg$" + id);
}

EditoImg.Screen = function()
{
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		return [window.innerWidth, window.innerHeight];
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		return [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		return [document.body.clientWidth, document.body.clientHeight];
	}
}

EditoImg.Scroll = function()
{
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		return [window.pageXOffset, window.pageYOffset];
	}
	else if( document.documentElement && ( typeof(document.documentElement.scrollLeft) != 'undefined' || typeof(document.documentElement.scrollTop) != 'undefined' ) )
	{
		//IE6 standards compliant mode
		return [document.documentElement.scrollLeft, document.documentElement.scrollTop];
	}
	else if( document.body && ( typeof(document.body.scrollLeft) != 'undefined' || typeof(document.body.scrollTop) != 'undefined' ) )
	{
		//DOM compliant
		return [document.body.scrollLeft, document.body.scrollTop];
	}
}

EditoImg.Click = function()
{
	EditoImg.Images = new Array();
	EditoImg.Index = 0;
	EditoImg.Navigators(false);
	
	if(this.getAttribute('rel') != EditoImg.Keyword)
	{
		var counter = 0;
		var anchors = document.getElementsByTagName('a');
		
		for(var i=0; i<anchors.length; i++)
		{
			var anchor = anchors[i];
			var rel = anchor.getAttribute('rel');
			
			if(anchor.getAttribute('href') && rel == this.getAttribute('rel'))
			{
				EditoImg.Images[EditoImg.Images.length] = anchor;
				
				if(this == anchor)
				{
					EditoImg.Index = counter;
				}
				
				counter++;
			}
		}
		
		EditoImg.Navigators(true);
	}
	
	EditoImg.Show(this, EditoImg.Images);
	
	return false;
}

EditoImg.Show = function(imgLink, images)
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Bottom").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Item("Container").style.width = "500px";
	EditoImg.Item("Container").style.height = "400px";
	EditoImg.Item("Panel").style.width = "500px";
	EditoImg.Item("Panel").style.height = "400px";
	EditoImg.Item("Panel").style.position = "absolute";
	EditoImg.Item("Panel").style.display = "";
	EditoImg.ChangePosition();
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = imgLink.title;
	img.src = imgLink.href;
}

EditoImg.NextImage = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Index++;
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = EditoImg.Images[EditoImg.Index].title;
	img.src = EditoImg.Images[EditoImg.Index].href;
}

EditoImg.PrevImage = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Loader").style.display = "";
	
	EditoImg.Index--;
	
	var img = new Image();
	img.onload = EditoImg.ImageLoad;
	img.title = EditoImg.Images[EditoImg.Index].title;
	img.src = EditoImg.Images[EditoImg.Index].href;
}

EditoImg.ChangePosition = function()
{
	var screen = EditoImg.Screen();
	var scroll = EditoImg.Scroll();
	
	var offsetWidth = parseInt(EditoImg.Item("Panel").style.width);
	var offsetHeight = parseInt(EditoImg.Item("Panel").style.height);
	
	var left = ((screen[0] - offsetWidth) / 2);
	var top = ((screen[1] - offsetHeight) / 2);
	
	EditoImg.Item("Panel").style.zIndex = "100";
	EditoImg.Item("Panel").style.left = ((left > 0) ? left : 0) + "px";
	EditoImg.Item("Panel").style.top = scroll[1] + ((top > 0) ? top : 0) + "px";
	
	var overlayHeight = document.body.offsetHeight;
	if(overlayHeight < screen[1])
	{
		overlayHeight = screen[1];
	}
	if(parseInt(EditoImg.Item("Panel").style.top) + offsetHeight > overlayHeight)
	{
		overlayHeight = parseInt(EditoImg.Item("Panel").style.top) + offsetHeight;
	}
	
	if(!((document.getElementById && !document.all) || window.opera))
	{
		EditoImg.Item("Background").style.position = "absolute";
		EditoImg.Item("Background").style.zIndex = "95";
		EditoImg.Item("Background").style.left = EditoImg.Item("Panel").style.left;
		EditoImg.Item("Background").style.top = EditoImg.Item("Panel").style.top;
		EditoImg.Item("Background").style.height = offsetHeight;
		EditoImg.Item("Background").style.width = offsetWidth;
		EditoImg.Item("Background").style.display = "";
	}
	
	EditoImg.Item("Overlay").style.position = "absolute";
	EditoImg.Item("Overlay").style.zIndex = "90";
	EditoImg.Item("Overlay").style.left = "0px";
	EditoImg.Item("Overlay").style.top = "0px";
	EditoImg.Item("Overlay").style.height = overlayHeight + "px";
	EditoImg.Item("Overlay").style.display = "";
}

EditoImg.Navigators = function(visibility)
{
	var display = visibility  ? "" : "none";
	
	EditoImg.Item("Prev").style.display = display;
	EditoImg.Item("Next").style.display = display;
	
	if(visibility && EditoImg.Index == 0)
	{
		EditoImg.Item("Prev").style.display = "none";
	}
	if(visibility && EditoImg.Index == (EditoImg.Images.length - 1))
	{
		EditoImg.Item("Next").style.display = "none";
	}
}

EditoImg.ImageLoad = function()
{
	EditoImg.Item("Background").style.display = "none";
	EditoImg.Item("Panel").style.width = "";
	EditoImg.Item("Panel").style.height = "";
	
	var sWidth = parseInt(EditoImg.Item("Container").style.width);
	var sHeight = parseInt(EditoImg.Item("Container").style.height);
	
	var pWidth = EditoImg.Item("Panel").offsetWidth - sWidth;
	var pHeight = EditoImg.Item("Panel").offsetHeight - sHeight;
	
	EditoImg.Item("Container").style.width = this.width + 2 * EditoImg.BorderSize + "px";
	EditoImg.Item("Container").style.height = this.height + 2 * EditoImg.BorderSize + "px";
	EditoImg.Item("Panel").style.width = this.width + 2 * EditoImg.BorderSize + pWidth + "px";
	EditoImg.Item("Panel").style.height = this.height + 2 * EditoImg.BorderSize + pHeight + "px";
	
	EditoImg.Item("Loader").style.display = "none";
	
	EditoImg.Item("Preview").onclick = EditoImg.Close;
	EditoImg.Item("IcoClose").onclick = EditoImg.Close;
	EditoImg.Item("Preview").src = this.src;
	EditoImg.Item("Preview").style.display = "";
	
	EditoImg.Item("Caption").innerHTML = this.title;
	
	if(EditoImg.Images.length == 0)
	{
		EditoImg.Navigators(false);
	}
	else
	{
		EditoImg.Navigators(true);
	}
	
	if(this.title.replace(/^\s*|\s*$/g, "") != "" || EditoImg.Images.length > 0)
	{
		EditoImg.Item("Bottom").style.display = "";
	}
	
	EditoImg.ChangePosition();
}

EditoImg.Close = function()
{
	EditoImg.Item("Preview").style.display = "none";
	EditoImg.Item("Panel").style.display = "none";
	EditoImg.Item("Overlay").style.display = "none";
	EditoImg.Item("Background").style.display = "none";
}

EditoStart.Add(EditoImg.init);


/* Pozostale skrypty */
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>');
}

// zdjęcie bez opisu
function showImage(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=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;
}

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" : "");
}

/* obiekt zakladek TabStrip */
function TabStrip(id, tabsCount)
{
	this.selected = id;
	this.tabsCount = tabsCount;

	this.renderTabs(this.selected);
}

TabStrip.prototype.renderTabs = function(selected)
{
	for(var i=0; i < this.tabsCount; i++)
	{
		if(i == selected)
			this.setActive(i);
		else
			this.setInactive(i);
	}
}

TabStrip.prototype.setActive = function(id)
{
	findObj('TabStrip_'+id).style.display = '';
	findObj('TabStripHeader_'+id).className = 'TabStripActive';
	setCookie('TabStrip_activeTab', id);
}

TabStrip.prototype.setInactive = function(id)
{
	findObj('TabStrip_'+id).style.display = 'none';
	findObj('TabStripHeader_'+id).className = 'TabStripInactive';
}

TabStrip.prototype.showTab = function(id)
{
	this.renderTabs(id);
}

/* sklep porownywarka */
function makeCompare(typ_oferty, id_uniq)
{
	var form = document.getElementById('porownaj_' + id_uniq);
	var typhidden = document.getElementById('typ_oferty_' + id_uniq);
	
	typhidden.value = typ_oferty;
	form.submit();
}

function delCompare(id_uniq, suma, komunikat)
{
	var form = document.getElementById('porownaj_' + id_uniq);
	var akcjausun = document.getElementById('por_akcja_usun_' + id_uniq);	
	var hiddenakcja = document.getElementById('usun_hidden_' + id_uniq);	
	var zaznaczone = false;
	
	for(i=0; i < suma; i++)
	{
		if(document.getElementById('prd' + id_uniq + '_' + i).checked == true)
			zaznaczone = true;
	}
	if(zaznaczone)
	{
		form.action = akcjausun.value;
		hiddenakcja.value = 'usun';
		form.submit();
	}
	else
	{
		alert(komunikat);
	}
}
/* wyszukuwarka produktow */

function ShowHideOpction(grupa)
{
	var region = document.getElementById(grupa);
	var ico = document.getElementById('i'+grupa);
	
	var tab = region.getElementsByTagName("input");
	
	if(region.style.display == 'none')
	{
		region.style.display = '';
		ico.src = 'images/ikon/up.gif';
	}
	else
	{
		region.style.display = 'none';
		ico.src = 'images/ikon/down.gif';
		
		//zeruj pola
		for(i=0; i < tab.length; i++)
		{
			if(tab[i].getAttribute('type') == 'checkbox')
			{
				tab[i].checked = false;
			}
		}	
	}		
}

function MarkOpctions(grupa)
{
	var region = document.getElementById(grupa);
	var tab = region.getElementsByTagName("input");
	
	//zaznacz pola
	for(i=0; i < tab.length; i++)
	{
		if(tab[i].getAttribute('type') == 'checkbox')
		{
			tab[i].checked = true;
		}
	}
}

function ClearOpctions(grupa)
{
	var region = document.getElementById(grupa);
	var tab = region.getElementsByTagName("input");
	
	//zeruj pola
	for(i=0; i < tab.length; i++)
	{
		if(tab[i].getAttribute('type') == 'checkbox')
		{
			tab[i].checked = false;
		}
	}
}

// tooltip

var offsetxpoint = -0 // x offset
var offsetypoint = 20 // y offset
var ie = document.all
var moz = document.getElementById && !document.all
var ttEnableToolTip = false;
var ttToolTip = null;

function ietruebody() {
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function ShowToolTip(text, width) {
	if (ttToolTip == null) {
		ttToolTip = document.getElementById("pnlToolTip");
	}
	if (typeof width !="undefined") ttToolTip.style.width = width+"px";
	ttToolTip.innerHTML = text;
	ttEnableToolTip = true;
	return false;
}

function MoveToolTip(e) {
	if (ttEnableToolTip) {
		var curX = (moz) ? e.pageX : event.x+ietruebody().scrollLeft;
		var curY = (moz) ? e.pageY : event.y+ietruebody().scrollTop;

		// sprawdzanie pozycji ToolTip'a
		var rightedge = ie ? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge = ie ? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
		var leftedge = (offsetxpoint<0) ? offsetxpoint*(-1) : -1000;

		// if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < ttToolTip.offsetWidth) {
			// move the horizontal position of the menu to the left by it's width
			ttToolTip.style.left = ie ? ietruebody().scrollLeft+event.clientX-ttToolTip.offsetWidth+"px" : window.pageXOffset+e.clientX-ttToolTip.offsetWidth+"px";
		} else if (curX < leftedge) {
			ttToolTip.style.left = "5px";
		} else {
			// position the horizontal position of the menu where the mouse is positioned
			ttToolTip.style.left = curX+offsetxpoint+"px";
		}

		// same concept with the vertical position
		if (bottomedge<ttToolTip.offsetHeight) {
			ttToolTip.style.top = ie ? ietruebody().scrollTop+event.clientY-ttToolTip.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-ttToolTip.offsetHeight-offsetypoint+"px";
		} else {
			ttToolTip.style.top = curY+offsetypoint+"px";
		}
		ttToolTip.style.visibility = "visible";
	}
}

function HideToolTip() {
	ttEnableToolTip = false;
	ttToolTip.style.visibility = "hidden";
	ttToolTip.style.left = "-1000px";
	ttToolTip.style.backgroundColor = '';
	ttToolTip.style.width = '';
}

document.write('<div id="pnlToolTip"></div>');
document.onmousemove = MoveToolTip;


function toggleResult(id)
{
	var link1 = document.getElementById('link_1defi_'+id);
	var link2 = document.getElementById('link_2defi_'+id);
	var grupa = document.getElementById('grupa_'+id);
	var defi = document.getElementById('defi_'+id);
	
	if(grupa && grupa.style.display == 'none')
	{
		// otwarcie calej kategorii
		grupa.style.display = 'block';
	}
	else if (grupa && grupa.style.display == 'block' && link1 && link1.style.display == 'block')
	{
		// klik na wiecej
		link1.style.display = 'none';
		link2.style.display = 'block';
		defi.style.display = 'block';
	}
	else if (grupa && grupa.style.display == 'block' && defi && defi.style.display == 'block')
	{
		link1.style.display = 'block';
		link2.style.display = 'none';
		defi.style.display = 'none';
		grupa.style.display = 'none';
	}
	else if (grupa && grupa.style.display == 'block' && !defi)
	{
		grupa.style.display = 'none';
	}
	else if (grupa && grupa.style.display == 'none' && !defi)
	{
		grupa.style.display = 'block';
	}
}

function toggleResult2(id, bloczek)
{
	var link1 = document.getElementById('link_1defi_'+id);
	var link2 = document.getElementById('link_2defi_'+id);
	var grupa = document.getElementById('grupa_'+id);
	var defi = document.getElementById('defi_'+id);
		
	if(grupa && grupa.style.display == 'none')
	{
		// otwarcie calej kategorii
		grupa.style.display = 'block';
		
		$(bloczek).removeClass('bloczekZwin');
		$(bloczek).addClass('bloczekRozwin');			
	}
	else if (grupa && grupa.style.display == 'block' && link1 && link1.style.display == 'block')
	{
		// klik na wiecej
		link1.style.display = 'none';
		link2.style.display = 'block';
		defi.style.display = 'block';
		
		$(bloczek).removeClass('bloczekZwin');
		$(bloczek).addClass('bloczekRozwin');				
	}
	else if (grupa && grupa.style.display == 'block' && defi && defi.style.display == 'block')
	{
		link1.style.display = 'block';
		link2.style.display = 'none';
		defi.style.display = 'none';
		grupa.style.display = 'none';
		
		$(bloczek).removeClass('bloczekRozwin');
		$(bloczek).addClass('bloczekZwin');		
	}
	else if (grupa && grupa.style.display == 'block' && !defi)
	{
		grupa.style.display = 'none';

		$(bloczek).removeClass('bloczekRozwin');
		$(bloczek).addClass('bloczekZwin');			
	}
	else if (grupa && grupa.style.display == 'none' && !defi)
	{
		grupa.style.display = 'block';
		
		$(bloczek).removeClass('bloczekZwin');
		$(bloczek).addClass('bloczekRozwin');		
	}
}

// rozwijanie listy wynikow w wyszukiwarce
function showResult(id) {
	o = document.getElementById(id);
	if (o.style.display == '' || o.style.display == 'none') {
		o.style.display = 'block';
	} else {
		o.style.display = 'none';
	}
}

// rozwijanie listy kategorii sklepu
function showMoreResult(id) 
{
	o = document.getElementById(id);
	lo1 = document.getElementById('link_1' + id);
	lo2 = document.getElementById('link_2' + id);
	
	if (o.style.display == '' || o.style.display == 'none') 
	{
		o.style.display = 'block';
		lo1.style.display = 'none';
		lo2.style.display = 'block';
		setCookie(id, '1');
	} 
	else 
	{
		o.style.display = 'none';
		lo1.style.display = 'block';
		lo2.style.display = 'none';
		setCookie(id, '');
	}
}

function d2h(d) {
	return (d-0).toString(16);
}

function HSBtoRGB(h,s,b)
{
	var H = h/360.0;
	var S = s/100.0;
	var V = b/100.0;
	if(S==0) {
		var R=V;	var G=V;	var B=V;
	}
	else{
		var th = H*6;
		var ti = Math.floor(th);
		var t1 = V*(1.0-S);
		var t2= V*(1.0-S*(th-ti));
		var t3= V*(1.0-S*(1.0-(th-ti)));
		switch (ti){
		  case 0: R=V; G=t3; B=t1; break;
		  case 1: R=t2; G=V; B=t1; break;
		  case 2: R=t1; G=V; B=t3; break;
		  case 3: R=t1; G=t2; B=V; break;
		  case 4: R=t3; G=t1; B=V; break;
		  case 5: R=V; G=t1; B=t2; break;
		}
	}
  R = Math.floor(R*255.0); 	R=d2h(R);		if(R < 10) R = '0' + R;
  G = Math.floor(G*255.0); 	G=d2h(G);		if(G < 10) G = '0' + G;
  B = Math.floor(B*255.0); 	B=d2h(B);		if(B < 10) B = '0' + B;

	return '#'+R+G+B;
}

function pokaz_ukryj_legende()
{
	var legenda = document.getElementById("legenda");
	if(legenda.style.display == "none") legenda.style.display = "";
	else legenda.style.display = "none";
}

function pokaz_dane_firmy()
{
	var daneFirmy = document.getElementById("dane_firmy");
	if(daneFirmy.style.display == "none") daneFirmy.style.display = "";
	else daneFirmy.style.display = "none";
}

function pokaz_tabele_kosztow_dostawy()
{
	var kosztDostawyTabela = document.getElementById("koszt_dostawy_tabela");
	if(kosztDostawyTabela.style.display == "none") kosztDostawyTabela.style.display = "";
	else kosztDostawyTabela.style.display = "none";
}

function katalog(lang, id_projektu)
{
	$.ajax({
		type: "GET",
		url: baseHref + 'losowanie_produktow_glowna.php',
		data: 'lang='+lang+'&id_projektu='+id_projektu+'&r='+Math.random(),
		dataType: "text",
		success: function(text){			
			$("#katalog_produktow").html(text);
		}
	
	});
}

function katalog_pp(lang, id_projektu, id_programu_partnerskiego, szablon)
{
	$.ajax({
		type: "GET",
		url: baseHref + 'losowanie_produktow_glowna.php',
		data: 'lang='+lang+'&id_projektu='+id_projektu+'&id_programu_partnerskiego='+id_programu_partnerskiego+'&szablon='+szablon+'&r='+Math.random(),
		dataType: "text",
		success: function(text){			
			$("#katalog_produktow").html(text);
		}
		
	});
}

function pokaz_kontakt_do_sprzedawcy() {
	
	$('.kontenerProducent').css('position', 'relative')
		.css('background-color', 'white')
		.animate({left: '-350'}, 'slow')
		.animate({opacity: 'hide'}, 'fast')
		.animate({opacity: 'show'}, 'normal')
		.animate({opacity: 'hide'}, 'fast')
		.animate({opacity: 'show'}, 'normal')
		.animate({left: '0'}, 'slow');
		
	setTimeout(function(){$('.kontenerProducent').removeAttr('style');} ,5000);
}
/**
 / THIRD FUNCTION
 * getPageSize() by quirksmode.com
 *
 * @return Array Return an array with page width, height and window width, height
 */
function getOverlayWindowSize() {		

	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	arrayWindowSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayWindowSize;
}
/**
 / THIRD FUNCTION
 * getPageScroll() by quirksmode.com
 *
 * @return Array Return an array with x,y page scroll values.
 */
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
};

function usunProdukt(ajaxLink, idProjektu, daneUsun, zwrocLiczbeProduktow, klasa)
{
	$.post(ajaxLink, {ajax: "usun_z_koszyka", id_projektu: idProjektu , dane_usun: daneUsun, zwroc_liczbe_produktow: zwrocLiczbeProduktow},
		function(response)
		{
			if(response == '-1')
			{
				if(klasa != '')
				{
					$("#img_koszyk").attr("class",klasa);
				}
				else
				{
					var ico_koszyk = document.getElementById('img_koszyk');
					ico_koszyk.src = 'images/ikon/menu_gora_btn_koszyk.gif';
				}
				
				$('#dodaj_do_koszyka_info').html("");					
			}	
		}			
	);	
}

//wyszukiwarka
$(document).ready(function() {
			
	$('#queryBlok').keyup(function (event) {
		if(event.keyCode != 40 && event.keyCode != 38) {
			podpowiedzBlok('queryBlok','divPodpowiedzBlok');
		}
		$('#queryBlok').focus();
	});
	
	
	$('#queryBlok').blur(function () { queryBlurBlok(); });
	$('#queryBlok').focus(function () { queryFocusBlok(); });
	
	$('#queryBlok').keydown(function(event){
		if($('#divPodpowiedzBlok').is(":visible"))
		{
			if(event.keyCode == 40)
			{
				for(i=2; i<maxBlok; i++)
				{
					if($('#p'+i).attr('class') == 'keynav_focusbox')
					{
						$('#p'+i).removeClass().addClass('keynav_box');
						$('#p'+(i+1)).removeClass().addClass('keynav_focusbox');
						$('#queryBlok').val($('#p'+(i+1)).attr('alt'));
						break;
					}
				}
				if(i==maxBlok)
				{
					$('#p2').removeClass().addClass('keynav_focusbox');
					$('#queryBlok').val($('#p2').attr('alt'));
				}
			}
			else if(event.keyCode == 38)
			{
				for(i=maxBlok-1; i>0; i--)
				{
					if($('#p'+i).attr('class') == 'keynav_focusbox')
					{
						$('#p'+i).removeClass().addClass('keynav_box');
						$('#p'+(i-1)).removeClass().addClass('keynav_focusbox');
						$('#queryBlok').val($('#p'+(i-1)).attr('alt'));
						break;
					}
				}
				if(i==0)
				{
					$('#p'+(maxBlok-1)).removeClass().addClass('keynav_focusbox');
					$('#queryBlok').val($('#p'+(maxBlok-1)).attr('alt'));
				}
			}
			$('#queryBlok').focus();
		}
		else if($('#divPodpowiedz').is(":hidden"))
		{
			if(event.keyCode == 40)
			{
				podpowiedzBlok('queryBlok','divPodpowiedzBlok');
			}
		}
	});
	
	$('#queryModul').keyup(function (event) {
		if(event.keyCode != 40 && event.keyCode != 38) {
			podpowiedzBlok('queryModul','divPodpowiedzModul');
		}
		$('#queryModul').focus();
	});
	
	
	$('#queryModul').blur(function () { queryBlurBlok(); });
	$('#queryModul').focus(function () { queryFocusBlok(); });
	
	$('#queryModul').keydown(function(event){
		if($('#divPodpowiedzModul').is(":visible"))
		{
			if(event.keyCode == 40)
			{
				for(i=2; i<maxBlok; i++)
				{
					if($('#p'+i).attr('class') == 'keynav_focusbox')
					{
						$('#p'+i).removeClass().addClass('keynav_box');
						$('#p'+(i+1)).removeClass().addClass('keynav_focusbox');
						$('#queryModul').val($('#p'+(i+1)).attr('alt'));
						break;
					}
				}
				if(i==maxBlok)
				{
					$('#p2').removeClass().addClass('keynav_focusbox');
					$('#queryModul').val($('#p2').attr('alt'));
				}
			}
			else if(event.keyCode == 38)
			{
				for(i=maxBlok-1; i>0; i--)
				{
					if($('#p'+i).attr('class') == 'keynav_focusbox')
					{
						$('#p'+i).removeClass().addClass('keynav_box');
						$('#p'+(i-1)).removeClass().addClass('keynav_focusbox');
						$('#queryModul').val($('#p'+(i-1)).attr('alt'));
						break;
					}
				}
				if(i==0)
				{
					$('#p'+(maxBlok-1)).removeClass().addClass('keynav_focusbox');
					$('#queryModul').val($('#p'+(maxBlok-1)).attr('alt'));
				}
			}
			$('#queryModul').focus();
		}
		else if($('#divPodpowiedzModul').is(":hidden"))
		{
			if(event.keyCode == 40)
			{
				podpowiedzBlok('queryModul','divPodpowiedzModul');
			}
		}
	});	
	
});

var maxBlok = 0;
var blokadaSzukania = false;

function podpowiedzBlok(idInputSzukaj, idPodpowiedz)
{
	var query = $('#'+idInputSzukaj).val();
	$('#'+idPodpowiedz).hide();
	$('#'+idPodpowiedz).html('');
	
	if(query.length >= 3 && !blokadaSzukania)
	{
		
		$.post(category_link_wyszuk, {ajax: "podpowiedz", q: query},
			function(response)
			{
				if(response.length > 10)
				{
					$('#'+idPodpowiedz).html(response);
					$('#'+idPodpowiedz).show();
					
					$('#'+idPodpowiedz+' p').unbind();
					
					maxBlok = $('#'+idPodpowiedz+' p').length+1;
					
					for(i=1; i<maxBlok; i++)
					{
						$('#p'+i).bind("mouseover", {element: i}, mouseOverPBlok);
						$('#p'+i).bind("mouseout", {element: i}, mouseOutPBlok);
					}
				}
				else
				{
					blokadaSzukania = true;
				}
			}
		);
	}
	else if(query.length <= 3)
	{
		blokadaSzukania = false;
	}
}

function setSzukaneBlok(slowo)
{
	$('#queryBlok').val(slowo);
	$('#divPodpowiedzBlok').hide();
	$('#blok_sz_form').submit();
}

function queryBlurBlok()
{
	if($('#divPodpowiedzBlok').is(":visible"))
	{
		for(i=1; i<maxBlok; i++)
		{
			if($('#p'+i).attr('class') == 'keynav_focusbox')
			{
				$('#queryBlok').val($('#p'+(i)).attr('alt'));
				document.wyszukiwarkaBlok.submit();
			}
		}
		
		$('#divPodpowiedzBlok').hide();
		$('#divPodpowiedzBlok').html('');
	}
}

function queryFocusBlok()
{
	$('#divPodpowiedz').hide();
	$('#divPodpowiedz').html('');
}


function mouseOverPBlok(event)
{
	var i = event.data.element;
	
	$('#divPodpowiedzBlok p').removeClass().addClass('keynav_box');
	$('#p'+i).removeClass().addClass('keynav_focusbox');
}

function mouseOutPBlok(event)
{
	var i = event.data.element;
	
	$('#divPodpowiedzBlok p').removeClass().addClass('keynav_box');
	$('#p'+i).removeClass().addClass('keynav_box');
}