jQr(document).ready(function(){  
	
	// Popup z okienkiem do zapisu do newslettera
	if ( popup_newsletter_pokaz == 1 ) {
		jQr.fancybox({
			content: jQr('#popup_newsletter'),
			autoScale: false,
			margin: 0,
			overlayOpacity: 0.5,
			padding: 0,
			scrolling: 'no',
			transitionIn: 'none',
			transitionOut: 'none',
			showCloseButton: false,
			hideOnOverlayClick: false,
			hideOnContentClick: false,
			opacity: false
		});
		
		jQr('.close', '#popup_newsletter').live('click', function() {
			var popup_newsletter_zamkniecia = readCookie('popup_newsletter_zamkniecia');
			
			if ( popup_newsletter_zamkniecia != 0 && popup_newsletter_zamkniecia != 1 && popup_newsletter_zamkniecia != 2 && popup_newsletter_zamkniecia != 3) {
				popup_newsletter_zamkniecia = 0;
			}
			
			createCookie('popup_newsletter_zamkniecia', (parseInt(popup_newsletter_zamkniecia)+1), 999);

			jQr.fancybox.close();
			return false;
		});
	}
	
	jQr("#fCartAddProduct").bind("click", function() {
		var ilosc = jQr("#fProductCount").val();
		var opcja = jQr("#fWybierzOpcje").val();
		var prodID = jQr("#fProductId").val();
		var page = jQr("#fProductPage").val();
		
		jQr.fancybox.showActivity();
		jQr.ajax({
			type	: "POST",
			cache	: false,
			url		: "koszyk_dodaj.php",
			data	: "fProductCount=" + ilosc + "&fProductOptions=" + opcja + "&fProductId=" + prodID+ "&page=" + page,
			success: function(data) {
				jQr.fancybox(
					data,
					{
						'titleShow'     : false,
						'transitionIn'	: 'elastic',
						'transitionOut'	: 'elastic',
						'easingIn'      : 'easeOutBack',
						'speedIn'		: 500, 
						'speedOut'		: 200,
						'autoScale'		: false,
						'width'			: 375,
						'height'		: 200,
						'overlayOpacity': 0.8
					}
				);
			}
		});
		
		return false;
	});
	
	jQr(".baner_main_a").bind("click", function() {
		jQr(".baner_main_a").attr('class', 'baner_main_a');
		jQr(this).attr('class', 'baner_main_a baner_main_a_selected');
		
		jQr(".main_baners").hide();
		jQr("#"+ jQr(this).attr('rel')).show();
		return false;
	});
	
	jQr(".przechowaj-porownaj-produkty").hover(
		function () {
			jQr(this).find('img').attr('src', 'images/przechowaj_on.gif');
		},
		function() {
			jQr(this).find('img').attr('src', 'images/przechowaj_off.gif');
		}
	);
	
	jQr(".usun-wszystko-porownaj-produkty").hover(
			function () {
				jQr(this).find('img').attr('src', 'images/delete_all_on.gif');
			},
			function() {
				jQr(this).find('img').attr('src', 'images/delete_all_off.gif');
			}
		);

	//
	// Czat
	//
	if (jQr('#chat.index').length == 1) {
		Chat.index();
	}
	else if (jQr('#chat.admin_index').length == 1) {
		Chat.admin_index();
	}
	
	//
	// Aktualnosci na stronie glownej
	//
	jQr('.BoxProdMain').bind('mouseover', function() {
		jQr(this).css('border-color', '#ff6600');
	});
	
	jQr('.BoxProdMain').bind('mouseout', function() {
		jQr(this).css('border-color', '#c5c6ca');
	});
	
	//
	// Zakladki na stronie glownej
	//
	jQr('.zakladki_oferta > li').bind('click', function() {
		jQr('.zakladki_oferta > li').removeClass('active');
		jQr('.tresc_oferta > div').removeClass('active');
		
		if ( jQr(this).attr('class') == 'first' ) {
			jQr(this).attr('class', 'first_active');
		} else if ( jQr(this).attr('class') == 'first_active' ) {
			jQr(this).attr('class', 'first');
		} else {
			jQr(this).addClass('active');
			jQr(".first_active").attr('class', 'first');
		}
		
		jQr(".tresc_oferta > ." + jQr(this).attr('id')).addClass('active');
		return false;
	});
	
	//
	// Kontakt po lewej stronie
	//
	jQr("#KontaktLewy_Click").bind("click", function() {
		if ( jQr("#KontaktLewy").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_kontakt_on.png');
			jQr("#KontaktLewy").show();
		} else {
			jQr(this).attr('src', 'images/btn_kontakt.png');
			jQr("#KontaktLewy").hide();
		}
		return false;
	});
	jQr('#KontaktLewy_Click').bind('mouseover', function() {
		jQr(this).attr('src', 'images/btn_kontakt_on.png');
	});
	jQr('#KontaktLewy_Click').bind('mouseout', function() {
		if ( jQr("#KontaktLewy").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_kontakt.png');
		}
	});
	
	//
	// Newsletter po lewej stronie
	//
	jQr("#NewsletterLewy_Click").bind("click", function() {
		if ( jQr("#Newsletter").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_newsletter_on.png');
			jQr("#Newsletter").show();
		} else {
			jQr(this).attr('src', 'images/btn_newsletter.png');
			jQr("#Newsletter").hide();
		}
		return false;
	});
	jQr('#NewsletterLewy_Click').bind('mouseover', function() {
		jQr(this).attr('src', 'images/btn_newsletter_on.png');
	});
	jQr('#NewsletterLewy_Click').bind('mouseout', function() {
		if ( jQr("#Newsletter").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_newsletter.png');
		}
	});
	
	//
	// Status po lewej stronie
	//
	jQr("#StatusLewy_Click").bind("click", function() {
		if ( jQr("#StatusLewy").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_status_on.png');
			jQr("#StatusLewy").show();
		} else {
			jQr(this).attr('src', 'images/btn_status.png');
			jQr("#StatusLewy").hide();
		}
		return false;
	});
	jQr('#StatusLewy_Click').bind('mouseover', function() {
		jQr(this).attr('src', 'images/btn_status_on.png');
	});
	jQr('#StatusLewy_Click').bind('mouseout', function() {
		if ( jQr("#StatusLewy").css('display') == 'none' ) {
			jQr(this).attr('src', 'images/btn_status.png');
		}
	});
	
	//
	// Czat po lewej stronie
	//
	jQr('#CzatLewy_offline').bind('mouseover', function() {
		jQr(this).attr('src', 'images/btn_czat_offline_on.png');
	});
	jQr('#CzatLewy_offline').bind('mouseout', function() {
		jQr(this).attr('src', 'images/btn_czat_offline.png');
	});
	jQr('#CzatLewy_online').bind('mouseover', function() {
		jQr(this).attr('src', 'images/btn_czat_online_on.png');
	});
	jQr('#CzatLewy_online').bind('mouseout', function() {
		jQr(this).attr('src', 'images/btn_czat_online.png');
	});
	
	//
	// Karuzelka
	//
	jQr(".carousel_super_oferty").jCarouselLite({
		btnNext: ".next_super_oferty",
		btnPrev: ".prev_super_oferty",
		visible: 4,
		circular: true,
		speed: 100
	});
	
	jQr(".carousel_outlet").jCarouselLite({
		btnNext: ".next_outlet",
		btnPrev: ".prev_outlet",
		visible: 4,
		circular: true,
		speed: 100
	});
	
	jQr(".carousel_nowe_dostawy").jCarouselLite({
		btnNext: ".next_nowe_dostawy",
		btnPrev: ".prev_nowe_dostawy",
		visible: 4,
		circular: true,
		speed: 100
	});
	
	jQr(".carousel_top_brands").jCarouselLite({
		btnNext: ".next_top_brands",
		btnPrev: ".prev_top_brands",
		visible: 6,
		circular: true,
		speed: 100
	});
	
	jQr('.carousel_top_brands > ul > li').bind('mouseover', function() {
		jQr(this).css('border-color', '#ff6600');
		jQr('a', this).css({'color':'#ff6600', 'text-decoration' : 'underline'});
	});
	
	jQr('.carousel_top_brands > ul > li').bind('mouseout', function() {
		jQr(this).css('border-color', '#fff');
		jQr('a', this).css({'color':'#161616', 'text-decoration' : 'none'});
	});
	
	//
	// E-przesylki
	//
	jQr('#e_przesylki_email_checkbox').bind('click', function() {
		jQr('#e_przesylki_sms_checkbox').removeAttr('checked');
		zmienSume(jQr('#e_przesylki_email_checkbox').attr('rel'));
	});
	
	jQr('#e_przesylki_sms_checkbox').bind('click', function() {
		jQr('#e_przesylki_email_checkbox').removeAttr('checked');
		zmienSume(jQr('#e_przesylki_sms_checkbox').attr('rel'));
	});
	
	//
	// Opcje produktu
	//
	if ( typeof(opcje_nowe_ilosc) != 'undefined' ) {
		var Option_Type = 'Option_Type_' + opcje_nowe_ilosc;
		if (window[Option_Type] != undefined) {
			if (typeof(window[Option_Type]['init']) == 'function') {
				window[Option_Type]['init']();
			}
		}
	}
	
});

function dodajPrzechowalnia(prodID) {
	
	jQr.fancybox.showActivity();
	jQr.ajax({
		type	: "POST",
		cache	: false,
		url		: "przechowalnia_dodaj.php",
		data	: "fProductId=" + prodID,
		success: function(data) {
			jQr.fancybox(
				data,
				{
					'titleShow'     : false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'easingIn'      : 'easeOutBack',
					'speedIn'		: 500, 
					'speedOut'		: 200,
					'autoScale'		: false,
					'width'			: 375,
					'height'		: 200,
					'overlayOpacity': 0.8
				}
			);
		}
	});
	
	return false;
	
}

function dodajPrzechowalniaPorownyw(prodID) {
	
	jQr.fancybox.showActivity();
	jQr.ajax({
		type	: "POST",
		cache	: false,
		url		: "przechowalnia_dodaj.php",
		data	: "fProductId=" + prodID + "&page=porownaj",
		success: function(data) {
			jQr.fancybox(
				data,
				{
					'titleShow'     : false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'easingIn'      : 'easeOutBack',
					'speedIn'		: 500, 
					'speedOut'		: 200,
					'autoScale'		: false,
					'width'			: 375,
					'height'		: 200,
					'overlayOpacity': 0.8
				}
			);
		}
	});
	
	return false;
	
}

function dodajProduktBox() {
	
	var ilosc = jQr("#fProductCountBox").val();
	var opcja = jQr("#fWybierzOpcjeBox").val();
	var prodID = jQr("#fProductIdBox").val();
	var page = jQr("#fProductPageBox").val();
	
	jQr.fancybox.showActivity();
	jQr.ajax({
		type	: "POST",
		cache	: false,
		url		: "koszyk_dodaj.php",
		data	: "fProductCount=" + ilosc + "&fProductOptions=" + opcja + "&fProductId=" + prodID+ "&page=" + page,
		success: function(data) {
			jQr.fancybox(
				data,
				{
					'titleShow'     : false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'easingIn'      : 'easeOutBack',
					'speedIn'		: 500, 
					'speedOut'		: 200,
					'autoScale'		: false,
					'width'			: 375,
					'height'		: 200,
					'overlayOpacity': 0.8
				}
			);
		}
	});
	
	return false;	
}


function dodajProduktBoxPrzech(prodID) {
	
	var ilosc = 1;
	var opcja = 0;
	
	jQr.fancybox.showActivity();
	jQr.ajax({
		type	: "POST",
		cache	: false,
		url		: "koszyk_dodaj.php",
		data	: "fProductCount=" + ilosc + "&fProductOptions=" + opcja + "&fProductId=" + prodID+ "&page=porownaj",
		success: function(data) {
			jQr.fancybox(
				data,
				{
					'titleShow'     : false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'easingIn'      : 'easeOutBack',
					'speedIn'		: 500, 
					'speedOut'		: 200,
					'autoScale'		: false,
					'width'			: 375,
					'height'		: 200,
					'overlayOpacity': 0.8
				}
			);
		}
	});
	
	return false;	
}

function textCounter( maxlimit) 
{
	if (document.getElementById('tresckartki').value.length > maxlimit) document.getElementById('tresckartki').value = document.getElementById('tresckartki').value.substring(0, maxlimit);
	else document.getElementById('iloscznakow').innerHTML = maxlimit - document.getElementById('tresckartki').value.length;
}

function textCounterReklamacje(id, maxlimit) 
{
	if (document.getElementById(id).value.length > maxlimit) document.getElementById(id).value = document.getElementById(id).value.substring(0, maxlimit);
	else document.getElementById('iloscznakow').innerHTML = maxlimit - document.getElementById(id).value.length;
}

function wlaczCheckbox(ilosc)
{
	if (document.getElementById('placwk').checked==true) stan='block';
		else stan='none';
	
	for (i=1; i<=ilosc; i++)
	{
		if (document.getElementById('checkzam'+i))document.getElementById('checkzam'+i).style.display = stan; 
	}
}

function podmienCeneProd()
{
	opcja = document.getElementById('fWybierzOpcje').value;
	if (opcja==0) return ''; 
	
	cena = document.getElementById('opcCena'+opcja).value;
	
	cena = parseFloat(cena);
	if (cena>0) document.getElementById('CenaProdukty').innerHTML = '<table style="float:right; margin-right:10px;"><tr><td valign="bottom" style=" font-size:12px; color: #777A81; font-weight:bold;">Cena:</td><td><span id="cenaProd" style="color:#000000; font-size:25px; ">'+ cena +'</span> <span style="color:#000000; font-size:14px;">PLN</span></td></tr></table>'
}

function ePrzesylka() {
	jqueryToggle('e_przesylki_form', 'e_przesylki_checkbox');
}

function ePrzesylkaWojewodztwo( wybierz_wojewodztwo_id ) {
	if ( wybierz_wojewodztwo_id == undefined ) {
		var wojewodztwo_id = jQuery('#e_przesylki_wojewodztwo').val();
	} else {
		var wojewodztwo_id = wybierz_wojewodztwo_id;
	}
	
	var miejscowosc_html = '';
	
	jQuery('#e_przesylki_punkt_td').html('<select name="e_przesylki_punkt" style="width:165px; margin-left:0;"><option value="0">- wybierz miejscowość -</option></select>');		
	
	if ( wojewodztwo_id == 0 ) {
		jQuery('#e_przesylki_miejscowosc_td').html('<select name="e_przesylki_miejscowosc" id="e_przesylki_miejscowosc" style="width:165px; margin-left:0;"><option value="0">- wybierz województwo -</option></select>');
	} else {
		jQuery('#e_przesylki_miejscowosc_td').html('<select name="e_przesylki_miejscowosc" id="e_przesylki_miejscowosc" style="width:165px; margin-left:0;"><option value="0">Trwa pobieranie danych...</option></select>');
		jQuery.ajax({
			type: "POST",
			url: "eprzesylki.php",
			data: "wojewodztwo_id="+wojewodztwo_id,
			dataType: "json",
			success: function(msg){
				miejscowosc_html = '<select name="e_przesylki_miejscowosc" id="e_przesylki_miejscowosc" style="width:165px; margin-left:0;" onchange="ePrzesylkaMiejscowosc()">';
				jQuery.each(msg, function(i,item){
					miejscowosc_html += '<option value="' + i + '">' + item + '</option>';
				});
				miejscowosc_html += '</select>';
				jQuery('#e_przesylki_miejscowosc_td').html(miejscowosc_html);
				
				if ( wybierz_wojewodztwo_id == undefined ) {
					ePrzesylkaMiejscowosc();
				}
			}
		});
	}
}

function ePrzesylkaMiejscowosc(wybierz_miejscowosc_id) {
	if ( wybierz_miejscowosc_id == undefined ) {
		var miejscowosc_id = jQuery('#e_przesylki_miejscowosc').val();
	} else {
		var miejscowosc_id = wybierz_miejscowosc_id;
	}

	var wojewodztwo_id = jQuery('#e_przesylki_wojewodztwo').val();
	var punkt_html = '';
	
	if ( miejscowosc_id == 0 ) {
		jQuery('#e_przesylki_punkt_td').html('<select name="e_przesylki_punkt" style="width:165px; margin-left:0;"><option value="0">- wybierz miejscowość -</option></select>');		
	} else {
		jQuery('#e_przesylki_punkt_td').html('<select name="e_przesylki_punkt" style="width:165px; margin-left:0;"><option value="0">Trwa pobieranie danych...</option></select>');
		
		jQuery.ajax({
			type: "POST",
			url: "eprzesylki.php",
			data: "miejscowosc_id="+miejscowosc_id+"&wojewodztwo_id="+wojewodztwo_id,
			dataType: "json",
			success: function(msg){
				punkt_html = '<select name="e_przesylki_punkt" id="e_przesylki_punkt" style="width:165px; margin-left:0;" onchange="ePrzesylkaPunkt();">';
				jQuery.each(msg, function(i,item){
					punkt_html += '<option value="' + i + '">' + item + '</option>';
				});
				punkt_html += '</select>';
				jQuery('#e_przesylki_punkt_td').html(punkt_html);
				
				if ( wybierz_miejscowosc_id == undefined ) {
					ePrzesylkaPunkt();
				}
			}
		});
	}
}


function ePrzesylkaPunkt(wybierz_punkt_id) {
	if ( wybierz_punkt_id == undefined ) {
		var punkt_id = jQuery('#e_przesylki_punkt').val();
	} else {
		var punkt_id = wybierz_punkt_id;
	}

	var punkt_msg = '';
	
	jQuery('#e_przesylki_punkt_msg').html(punkt_msg);
		
	jQuery.ajax({
		type: "POST",
		url: "eprzesylki.php",
		data: "punkt_id="+punkt_id,
		dataType: "json",
		success: function(msg){
			jQuery('#e_przesylki_punkt_msg').html('<span style="margin-top:10px; display:block; font-weight: bold;">Adres odbioru przesyłki:</span>' + msg.msg);
		}
	});
}

function ePrzesylkaZaznacz(wojewodztwo_id, miejscowosc_id, punkt_id) {
	var miejscowosc_html = '';
	var punkt_html = '';
	
	jQuery.ajax({
		type: "POST",
		url: "eprzesylki.php",
		data: "wojewodztwo_id="+wojewodztwo_id,
		dataType: "json",
		success: function(msg){
			miejscowosc_html = '<select name="e_przesylki_miejscowosc" id="e_przesylki_miejscowosc" style="width:165px; margin-left:0;" onchange="ePrzesylkaMiejscowosc()">';
			jQuery.each(msg, function(i,item){
				if ( miejscowosc_id == i ) {
					miejscowosc_html += '<option value="' + i + '" selected="selected">' + item + '</option>';
				} else {
					miejscowosc_html += '<option value="' + i + '">' + item + '</option>';
				}
			});
			miejscowosc_html += '</select>';
			jQuery('#e_przesylki_miejscowosc_td').html(miejscowosc_html);
		}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "eprzesylki.php",
		data: "miejscowosc_id="+miejscowosc_id+"&wojewodztwo_id="+wojewodztwo_id,
		dataType: "json",
		success: function(msg){
			punkt_html = '<select name="e_przesylki_punkt" id="e_przesylki_punkt" style="width:165px; margin-left:0;" onchange="ePrzesylkaPunkt();">';
			jQuery.each(msg, function(i,item){
				if ( punkt_id == i ) {
					punkt_html += '<option value="' + i + '" selected="selected">' + item + '</option>';
				} else {
					punkt_html += '<option value="' + i + '">' + item + '</option>';
				}
			});
			punkt_html += '</select>';
			jQuery('#e_przesylki_punkt_td').html(punkt_html);
		}
	});
	
	jQuery.ajax({
		type: "POST",
		url: "eprzesylki.php",
		data: "punkt_id="+punkt_id,
		dataType: "json",
		success: function(msg){
			jQuery('#e_przesylki_punkt_msg').html('<span style="margin-top:10px; display:block; font-weight: bold;">Adres odbioru przesyłki:</span>' + msg.msg);
		}
	});
}

function zamowienie_realizacja() {
	wysylka = document.getElementById('selDost').value;
	
	if ( wysylka == '12' || wysylka == '13' || wysylka == '14' ) {
		if ( document.getElementById('e_przesylki_wojewodztwo').value == 0 || document.getElementById('e_przesylki_miejscowosc').value == 0 || document.getElementById('e_przesylki_punkt').value == 0 ) {
			alert('Proszę wybrać adres odbioru przesyłki.');
			return false;
		}
		
		if ( document.getElementById('e_przesylki_email_checkbox').checked == true && jQuery("input[name='e_przesylki_email']").val() != '' && jQuery("input[name='e_przesylki_email']").val() != null && jQuery("input[name='e_przesylki_email']").val() != undefined ) {
			
		} else if ( document.getElementById('e_przesylki_sms_checkbox').checked == true && jQuery("input[name='e_przesylki_sms']").val() != '' && jQuery("input[name='e_przesylki_sms']").val() != null && jQuery("input[name='e_przesylki_sms']").val() != undefined ) {
			
		} else {
			alert('Proszę podać chociaż jedną formę powiadomienia o dostarczeniu przesyłki.');
			return false;
		}
	}
	
}
	
function zmienSume(wartosc)
{
	wartosc=parseFloat(wartosc);
	wysylka = document.getElementById('selDost').value;
	
	paczka = document.getElementById('selPaczka').value;
	
	iloscprod = document.getElementById('iloscProd').value; 
	iloscprod=parseFloat(iloscprod);
	
	kwotaWys = document.getElementById('kosztWys'+wysylka).value;
	gratisWys = document.getElementById('gratisOd'+wysylka).value;
	
	kwotaWys=parseFloat(kwotaWys);
	gratisWys=parseFloat(gratisWys);
	
	kwotaPaczki = document.getElementById('kosztOpak'+paczka).value;
	kwotaPaczki=parseFloat(kwotaPaczki);
	//kwotaPaczki = kwotaPaczki*iloscprod;
	
	// BEGIN - Dodatkowe koszta zwiazane z E-Przesylka
	if ( document.getElementById('e_przesylki_email_checkbox').checked == true ) {
		eprzesylka_sms = document.getElementById('e_przesylki_email_value').value;
		eprzesylka_sms = parseFloat(eprzesylka_sms);
	} else {
		eprzesylka_sms = 0;
	}
	
	if ( document.getElementById('e_przesylki_sms_checkbox').checked == true ) {
		eprzesylka_email = document.getElementById('e_przesylki_sms_value').value;
		eprzesylka_email = parseFloat(eprzesylka_email);
	} else {
		eprzesylka_email = 0;
	}
	
	kwotaWys = parseFloat(kwotaWys + eprzesylka_sms + eprzesylka_email);
	// END - Dodatkowe koszta zwiazane z E-Przesylka
	
	if (wysylka=='4' || wysylka=='5') 
	{
		document.getElementById('formaopakowania').style.display='block';
		document.getElementById('kartkazzycz').style.display='block';
	}
	else 
	{
		document.getElementById('formaopakowania').style.display='none';
		document.getElementById('kartkazzycz').style.display='none';
		kwotaPaczki = 0;
	}
	
	// BEGIN - E-Przesylka
	if ( wysylka == '12' || wysylka == '13' || wysylka == '14' ) {
		document.getElementById('e_przesylki').style.display = 'block';
		document.getElementById('e_przesylki_form').style.display = 'block';
		document.getElementById('e_przesylki_txt').style.display = 'block';
	} else {
		document.getElementById('e_przesylki').style.display = 'none';
		document.getElementById('e_przesylki_form').style.display = 'none';
		document.getElementById('e_przesylki_txt').style.display = 'none';
	}
	// END - E-Przesylka
	
	if (document.getElementById('kartka').checked == true && (wysylka=='4' || wysylka=='5')) kwotaKartki = document.getElementById('kosztKartki').value;
	else kwotaKartki=0;
	
	kwotaKartki=parseFloat(kwotaKartki);
	
	suma = wartosc + kwotaWys + kwotaPaczki + kwotaKartki;
	suma=parseFloat(suma);
	if ( suma < 0 ) {
		suma = 0.00;
	}
		
	document.getElementById('kosztWysylki').innerHTML = kwotaWys+' PLN';
	document.getElementById('kosztOpakowania').innerHTML = kwotaPaczki+' PLN';
	document.getElementById('sumaKoszyk').innerHTML = Numbers.Round(suma, 2);
	
	if ( kwotaWys > 0 ) { 
		doDarmowej = Numbers.Round( (gratisWys - wartosc) , 2);
		
		if ( doDarmowej <= 50 && doDarmowej > 0 ) { 
			document.getElementById('darmowaWysylkaInfo').innerHTML = 'Do darmowej przesyłki brakuje Ci zakupów za: <span style="font-size: 12px; font-weight: bold; color:#FF6600">' + doDarmowej + ' PLN</span>';
			document.getElementById('darmowaWysylkaInfo2').innerHTML = 'Pamiętaj, że jeśli suma Twoich zakupów przekroczy <span style="color:#FF6600">' + gratisWys + ' zł</span> koszt przesyłki pokryje sklep<br />' + 
			'Do otrzymania darmowej przesyłki brakuje Ci zakupów za: <span style="font-size: 12px; font-weight: bold; color:#FF6600">' + doDarmowej + ' PLN</span>';
			j("#darmowaWysylkaProdukt").show();
		} else {
			document.getElementById('darmowaWysylkaInfo').innerHTML = '';
			document.getElementById('darmowaWysylkaInfo2').innerHTML = '';
			j("#darmowaWysylkaProdukt").hide();
		}
	} else {
		document.getElementById('darmowaWysylkaInfo').innerHTML = '';
		document.getElementById('darmowaWysylkaInfo2').innerHTML = '';
		j("#darmowaWysylkaProdukt").hide();
	}
	
	jqueryToggle('formZyczenia', 'kartka');
}

function sprKupTaniej()
{
	opcja1 = opcja2 = opcja3 = 0

	if (document.getElementById('wybOpcjKup1'))
	{
	 if (document.getElementById('wybOpcjKup1').value==0) 
	 {
	 	alert('Proszę wybrać opcję produktu!!');
	 	return false;
	 }
	}
	
	if (document.getElementById('wybOpcjKup2')) 
	{
	 if (document.getElementById('wybOpcjKup2').value==0) 
	 {
	 	alert('Proszę wybrać opcję produktu!!');
	 	return false;
	 }
	}
	
	if (document.getElementById('wybOpcjKup3')) 
	{
	 if (document.getElementById('wybOpcjKup3').value==0) 
	 {
	 	alert('Proszę wybrać opcję produktu!!');
	 	return false;
	 }
	}

}

function obliczKupTaniej()
{
	opcja1 = opcja2 = opcja3 = 0
	cenaRabat1 = cena1 = cenaRabat2 = cena2 = cenaRabat3 = cena3 = 0;
	
	if (document.getElementById('wybOpcjKup1')) opcja1 = document.getElementById('wybOpcjKup1').value;
	if (document.getElementById('wybOpcjKup2')) opcja2 = document.getElementById('wybOpcjKup2').value;
	if (document.getElementById('wybOpcjKup3')) opcja3 = document.getElementById('wybOpcjKup3').value;	
	
	
	if (opcja1>0) 
	{
		cena1 = document.getElementById('opcCenaOrg'+opcja1).value;
		cenaRabat1 = document.getElementById('opcCenaRabat'+opcja1).value;
		
		document.getElementById('normal1').innerHTML = cena1+' PLN';
		document.getElementById('komplet1').innerHTML = cenaRabat1+' PLN';
	}
	else if (document.getElementById('cenaOrg1'))
	{
		cena1 = document.getElementById('cenaOrg1').value;
		cenaRabat1 = document.getElementById('CenaRabat1').value;
	}
	
	
	if (opcja2>0) 
	{
		cena2 = document.getElementById('opcCenaOrg'+opcja2).value;
		cenaRabat2 = document.getElementById('opcCenaRabat'+opcja2).value;
		
		document.getElementById('normal2').innerHTML = cena2+' PLN';
		document.getElementById('komplet2').innerHTML = cenaRabat2+' PLN';
	}
	else if (document.getElementById('cenaOrg2'))
	{
		cena2 = document.getElementById('cenaOrg2').value;
		cenaRabat2 = document.getElementById('CenaRabat2').value;
	}
	
	if (opcja3>0) 
	{
		cena3 = document.getElementById('opcCenaOrg'+opcja3).value;
		cenaRabat3 = document.getElementById('opcCenaRabat'+opcja3).value;
		
		document.getElementById('normal3').innerHTML = cena3+' PLN';
		document.getElementById('komplet3').innerHTML = cenaRabat3+' PLN';
	}
	else if (document.getElementById('cenaOrg3'))
	{
		cena3 = document.getElementById('cenaOrg3').value;
		cenaRabat3 = document.getElementById('CenaRabat3').value;
	}
	
	cena1 = parseFloat(cena1);
	cena2 = parseFloat(cena2);
	cena3 = parseFloat(cena3);
	
	cenaRabat1 = parseFloat(cenaRabat1);
	cenaRabat2 = parseFloat(cenaRabat2);
	cenaRabat3 = parseFloat(cenaRabat3);
	
	sumaCena = cena1+cena2+cena3;
	SumaRabat = cenaRabat1+cenaRabat2+cenaRabat3;
	
	sumaCena = parseFloat(sumaCena);
	SumaRabat = parseFloat(SumaRabat);
	
	sumaCena = (Math.round(sumaCena*100)/100);
	SumaRabat = (Math.round(SumaRabat*100)/100);
	
	document.getElementById('sumaNormal').innerHTML = sumaCena+' PLN';
	document.getElementById('sumaKomplet').innerHTML = SumaRabat+' PLN';
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function podmienObrazek(srckolor, idkol, srcbig)
{
	
	document.getElementById('produktGlowny').src = srckolor;
	document.getElementById('prodGlID').href = srcbig;	
	
	

	for (i=1; i<=14; i++)
	{
		if (document.getElementById('DivKolor'+i))
		{
			document.getElementById('DivKolor'+i).style.border = '2px';
			document.getElementById('DivKolor'+i).style.borderColor = '#ffffff';
			document.getElementById('DivKolor'+i).style.borderStyle = 'solid';
		}
	}
	
	if ( document.getElementById('DivKolor'+idkol) ) {
		document.getElementById('DivKolor'+idkol).style.border = '2px';
		document.getElementById('DivKolor'+idkol).style.borderColor = '#E36E1F';
		document.getElementById('DivKolor'+idkol).style.borderStyle = 'solid';
	}
}

function zmienTabelke(stan)
{
	
	for(i=1; i<=5; i++)
	{
		if (document.getElementById('imgzakladki' + i)) document.getElementById('imgzakladki' + i).style.backgroundImage = 'url("images/tabprod' + i + '_off.jpg")';
		if (document.getElementById('zakladkaTabelki' + i)) document.getElementById('zakladkaTabelki' + i).style.display = 'none';
	}
	
	document.getElementById('zakladkaTabelki' + stan).style.display = 'block';
	document.getElementById('imgzakladki' + stan).style.backgroundImage = 'url("images/tabprod' + stan + '_on.jpg")';
}


function RozwinKoszykPrzechowalnie(wlacz,wylacz)
    {
    document.getElementById(wlacz).style.display = "block";
    document.getElementById(wylacz).style.display = "none";
	
	if ( wlacz == 'BoxKoszyk') {
		document.getElementById('ZakladkaKoszyk').src = "images/btn_koszyk2.jpg";
		document.getElementById('ZakladkaPrzechowalnia').src = "images/btn_przechowalnia2.jpg";
		document.getElementById('zakladka1').style.display = "block";
		document.getElementById('zakladka2').style.display = "none";
	} else {
		document.getElementById('ZakladkaKoszyk').src = "images/btn_koszyk3.jpg";
		document.getElementById('ZakladkaPrzechowalnia').src = "images/btn_przechowalnia3.jpg";
		document.getElementById('zakladka2').style.display = "block";
		document.getElementById('zakladka1').style.display = "none";
	}
	
	document.getElementById('zakladka1').style.borderLeft = "1px solid #d1d5e0";
	document.getElementById('zakladka1').style.borderRight = "1px solid #d1d5e0";
	document.getElementById('zakladka1').style.width = "293px";	 
	
	document.getElementById('zakladka2').style.borderLeft = "1px solid #d1d5e0";
	document.getElementById('zakladka2').style.borderRight = "1px solid #d1d5e0";
	document.getElementById('zakladka2').style.width = "293px";
	
    }

function ZwinKoszykPrzechowalnie(wylacz)
    {
    document.getElementById(wylacz).style.display = "none";
	
	document.getElementById('zakladka1').style.borderLeft = "0px";
	document.getElementById('zakladka1').style.borderRight = "0px";
	document.getElementById('zakladka1').style.width = "295px";
	
	document.getElementById('zakladka2').style.borderLeft = "0px";
	document.getElementById('zakladka2').style.borderRight = "0px";
	document.getElementById('zakladka2').style.width = "295px";
    }
	
function Menu(id, style, otworz, wysun, czasRozwin, czasZwin, czasOtworz, czasZamknij, nieInicjalizuj)
{
	if (typeof czasRozwin == 'undefined' || czasRozwin < 0) czasRozwin = 0;
	if (typeof czasZwin == 'undefined' || czasZwin < 0) czasZwin = 0;
	if (typeof czasOtworz == 'undefined' || czasOtworz < 0) czasOtworz =0;
	if (typeof czasZamknij == 'undefined' || czasZamknij < 0) czasZamknij = 0;
	
	var url = unescape(window.location.href);
	var base = window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/[^\/\\]+$/, '');
	
	if (style)
	{
		if (style.indexOf(':') < 0)
		{
			document.getElementById(id).className += ' ' + style;
		}
		else
		{
			style = style.replace(/(^\s+|(\s|;)+$)/g, '').split(/\s*;\s*/);
			for (var i = 0; i < style.length; i++)
			{
				style[i] = style[i].split(/\s*:\s*/);
				for (var j = 0, c, property = ''; j < style[i][0].length; j++)
				{
					c = style[i][0].charAt(j);
					property += c == '-' ? style[i][0].charAt(++j).toUpperCase() : c.toLowerCase();
				}
				eval('document.getElementById("' + id + '").style.' + property + ' = "' + style[i][1].replace(/"/g, '\\"') + '"');
			}
		}
	}
	
	for (var i = 0; i < document.getElementById(id).getElementsByTagName('dt').length; i++)
	{
		var dd = new Array();
		var el = document.getElementById(id).getElementsByTagName('dt')[i].nextSibling;
		var nodeName;
		while (el && (nodeName = el.nodeName.toLowerCase()) != 'dt')
		{
			if (nodeName == 'dd')
			{
				el._dt = document.getElementById(id).getElementsByTagName('dt')[i];
				if (otworz)
				{
					el.onmouseover = function()
					{
						clearTimeout(this._dt._timoutID);
						this._dt._displayed = false;
						this._dt.onclick();
					}
					el.onmouseout = function()
					{
						clearTimeout(this._dt._timoutID);
						var dt = this._dt;
						this._dt._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
					};
				}
				dd[dd.length] = el;
			}
			el = el.nextSibling;
		}
		document.getElementById(id).getElementsByTagName('dt')[i]._dd = dd;
		document.getElementById(id).getElementsByTagName('dt')[i]._timoutID = null;
		document.getElementById(id).getElementsByTagName('dt')[i]._displayed = false;
		document.getElementById(id).getElementsByTagName('dt')[i].onclick = function()
		{
			clearTimeout(this._timoutID);
			if (!this._displayed)
			{
				var el = this.parentNode.getElementsByTagName('dt')[0];
				while (el)
				{
					if (el.nodeName.toLowerCase() == 'dt' && el != this)
					{
						el._displayed = false;
						if (czasZwin) display(el, 0);
						else display(el);
					}
					el = el.nextSibling;
				}
			}
			this._displayed = !this._displayed;
			if (this._displayed && czasRozwin || !this._displayed && czasZwin) display(this, 0);
			else display(this);
		};
		if (otworz)
		{
			document.getElementById(id).getElementsByTagName('dt')[i].onmouseover = function()
			{
				clearTimeout(this._timoutID);
				var dt = this;
				this._timoutID = setTimeout(function () { dt._displayed = false; dt.onclick(); }, czasOtworz);
			};
			document.getElementById(id).getElementsByTagName('dt')[i].onmouseout = function()
			{
				clearTimeout(this._timoutID);
				var dt = this;
				this._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
			};
		}
	}
	
	start(document.getElementById(id).getElementsByTagName('dt')[0]);
	
	function start(dt)
	{
		var hide = true;
		var el = dt;
		while (el)
		{
			var nodeName = el.nodeName.toLowerCase();
			if (nodeName == 'dt')
			{
				dt = el;
				hide = true;
			}
			if (nodeName == 'dt' || nodeName == 'dd')
			{
				if (!nieInicjalizuj && el.getElementsByTagName('a').length)
				{
					var active = el.getElementsByTagName('a')[0].href && unescape(el.getElementsByTagName('a')[0].href) == url;
					if (!active)
					{
						var rel = el.getElementsByTagName('a')[0].getAttribute('rel');
						if (rel)
						{
							var matches = (' ' + rel + ' ').match(/\s+Collection\(([^)]+)\)\s+/i);
							if (matches)
							{
								matches = matches[1].split(',');
								for (var k = 0; k < matches.length; k++)
								{
									if (/^[\/\\]/.test(matches[k])) matches[k] = window.location.protocol + '//' + window.location.host + matches[k];
									else if (!/^[a-z0-9]+:/i.test(matches[k])) matches[k] = base + matches[k];
									if (unescape(matches[k].replace(/[\/\\]\.([\/\\])/g, '$1').replace(/[^\/\\]+[\/\\]\.\.[\/\\]/g, '')) == url)
									{
										active = true;
										break;
									}
								}
							}
						}
					}
					if (active)
					{
						el.className = (el.className ? el.className + ' ' : '') + 'active';
						dt._displayed = true;
						display(dt);
						hide = false;
						var el_parentNode = el.parentNode;
						while (el_parentNode != document.getElementById(id))
						{
							if (el_parentNode.nodeName.toLowerCase() == 'dd')
							{
								var el_sibling = el_parentNode.previousSibling;
								while (el_sibling)
								{
									if (el_sibling.nodeName.toLowerCase() == 'dt')
									{
										el_sibling._displayed = true;
										display(el_sibling)
										break;
									}
									el_sibling = el_sibling.previousSibling;
								}
							}
							el_parentNode = el_parentNode.parentNode;
						}
					}
				}
			}
			if (nodeName == 'dd')
			{
				if (hide) el.style.display = 'none';
				start(el.getElementsByTagName('dt')[0]);
			}
			el = el.nextSibling;
		}
	}
	
	function display(dt, i)
	{
		if (typeof i == 'undefined')
		{
			for (var i = 0; i < dt._dd.length; i++)
			{
				dt._dd[i].style.display = dt._displayed ? 'block' : 'none';
				if (!dt._displayed)
				{
					for (var j = 0; j < dt._dd[i].getElementsByTagName('dt').length; j++)
					{
						dt._dd[i].getElementsByTagName('dt')[j]._displayed = false;
						display(dt._dd[i].getElementsByTagName('dt')[j]);
					}
				}
			}
		}
		else if (i < dt._dd.length)
		{
			var dir = wysun ? !dt._displayed : dt._displayed;
			var n = dir ? i : dt._dd.length - 1 - i;
			dt._dd[n].style.display = dt._displayed ? 'block' : 'none';
			if (!dt._displayed)
			{
				for (var j = 0; j < dt._dd[n].getElementsByTagName('dt').length; j++)
				{
					dt._dd[n].getElementsByTagName('dt')[j]._displayed = false;
					display(dt._dd[n].getElementsByTagName('dt')[j]);
				}
			}
			dt._timoutID = setTimeout(function() { display(dt, i + 1); }, dt._displayed ? czasRozwin : czasZwin);
		}
	}
}


	function pokazMenu ( idElementu, iloscElementow ) {
		
		element = document.getElementById('menu'+idElementu);
		link = document.getElementById('link'+idElementu);
		
		
		/* ukryj menu */
		for (i=1; i<=iloscElementow; i++) {
			if ( i != idElementu ) {
				document.getElementById('menu'+i).style.display = 'none';
				document.getElementById('link'+i).className = 'linkMenu';
			}
		}
		
		if ( element.style.display == 'none' ) {
			element.style.display = 'block';
			link.className = 'linkMenu2';
		} else {
			element.style.display = 'none';
			link.className = 'linkMenu';
		}
		
		
	}
	
	
	function ocena ( id ) {
		document.getElementById('twojaOcena').value = id;
		
		for ( i=1; i<=id; i++) {
			document.getElementById('glos'+i).src = 'images/gwiazdka_on.gif';
		}
		
		id = parseFloat(id)+1;
		
		for ( i=id; i<=5; i++) {
			document.getElementById('glos'+i).src = 'images/gwiazdka_off.gif';
		}

	}
	
	function jqueryToggle( iddiv, iddiv2 ) {
	 if ( document.getElementById(iddiv2).checked ) {
	 j("#"+iddiv).slideDown("slow");
	 } else {
	 j("#"+iddiv).slideUp("slow");
	 }
	}
	
/*	
	// teraz jest to w mootools. trzeba opracowac rozwijanie i zwijanie.
	function jqueryToggle( iddiv, iddiv2 ) {
		if ( document.getElementById(iddiv2).checked ) {
			var slider = new Fx.Slide(iddiv);
		} else {
			var slider = new Fx.Slide(iddiv);
		} 
	}
*/	
	
	
	function dodajOpinie() {
		
			lista  = document.getElementById('listaOpinii');
			dodaj = document.getElementById('dodajOpinie');
			btn = document.getElementById('btnOpinie');
			
			if ( dodaj.style.display == 'none' ) {
				dodaj.style.display = 'block';
				lista.style.display = 'none';
				btn.innerHTML = 'Wyświetl opinie';
				
			} else {
				dodaj.style.display = 'none';
				lista.style.display = 'block';
				btn.innerHTML = 'Dodaj opinie';
			}
		
	}
	
	function produktKoszykOn( id ) {
		document.getElementById('produkt' + id + '_zdjecie').style.border = '1px  solid #ff6600';
		document.getElementById('produkt' + id + '_odnosnik').style.color = '#ff6600';
	}
	
	
	function produktKoszykOff( id ) {
		document.getElementById('produkt' + id + '_zdjecie').style.border = '1px solid #ebeef3';
		document.getElementById('produkt' + id + '_odnosnik').style.color = '#464646';
	}
	
	/* otworz nowe okno - popup */
	function openWindow( adres ) {
		window.open(adres, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=no, status=no,width=650, height=650');
	}

	function showSzczegolyOn (id) {
		document.getElementById('link'+id).style.textDecoration = 'underline';
		document.getElementById(id).src='images/strz_dol_on.gif';
		document.getElementById(id).style.cursor='pointer';
		document.getElementById('link'+id).style.color='#ff6600';
	}
	
	
	function showSzczegolyOff (id) {
		document.getElementById('link'+id).style.textDecoration = 'none';
		document.getElementById(id).src='images/strz_dol_off.gif';
		document.getElementById('link'+id).style.color='#000000';
	}
	
	function porownajKolor ( id ) {
		document.getElementById('divImage'+id).style.border = '3px solid #e2e3e5';
		document.getElementById('divImage'+id).style.padding = '1px 0px 1px 0px';
		document.getElementById('spanNazwa'+id).style.color = '#ff6700';
		
		document.getElementById('tdProducent'+id).style.color = '#ff6700';
		document.getElementById('tdProducent'+id).style.textDecoration = 'underline';
		
	}
	
	
	function porownajKolorOut ( id ) {
		document.getElementById('divImage'+id).style.border = '1px solid #e2e3e5';
		document.getElementById('divImage'+id).style.padding = '3px 2px 3px 2px';
		document.getElementById('spanNazwa'+id).style.color = '#1a1a1a';
		
		document.getElementById('tdProducent'+id).style.color = '#1a1a1a';
		document.getElementById('tdProducent'+id).style.textDecoration = 'none';
	}
	
	
	function porownajKolor2 ( id ) {
		document.getElementById('spanNazwa'+id).style.color = '#ff6700';
		
		
		document.getElementById('tdProducent'+id).style.textDecoration = 'underline';
		document.getElementById('tdProducent'+id).style.color = '#ff6700';
		
	}
	
	
	function porownajKolorOut2 ( id ) {
		document.getElementById('spanNazwa'+id).style.color = '#1a1a1a';
		
		
		document.getElementById('tdProducent'+id).style.textDecoration = 'none';
		document.getElementById('tdProducent'+id).style.color = '#1a1a1a';
	}
	
	function pokazZamowiome ( id ) {
		div = document.getElementById(id);
			
		if ( div.style.display == 'none' ) {
			div.style.display  = 'block';
		} else {
			div.style.display  = 'none';
		}
	}
	
	function sprawdzOpcje() {
		
		if ( document.getElementById('fWybierzOpcje') ) {
			if ( document.getElementById('fWybierzOpcje').value == "0" ) {
				alert("Wybierz opcję produktu.");
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}
	

	function ocenProdukt ( idprod, ocena ) {
		var id = ocena;
				
		for ( i=1; i<=5; i++) {
			if ( i<= ocena ) {
				document.getElementById('prod_glos'+i).src = 'images/gwiazdka_on.gif';
			} else {
				document.getElementById('prod_glos'+i).src = 'images/gwiazdka_off.gif';
			}
		}
		
		
		j("#oceny").html('Czekaj...');
			
		j.ajax (
			{
				url: "ajax/ocenProdukt.php",
				data: "ocena="+ocena+"&idprod="+idprod,
				type: "GET",
				success: function(data){
					j("#oceny").html(data);
				},
				error: function(data){
					j("#oceny").html("Timeout error!");
				}

			}
		);
	}
	

var Numbers = {

	Config: {
		Glue: '.'
	},

	Round: function( number, round ) {
		var round = round + 1;
		var number_string = number.toString();
		
		var return_string = '';
		var iterator;
	
		for ( i=0; i < number_string.length; i = i + 1 ) {
			if ( number_string.charAt(i) == Numbers.Config.Glue ) {
				iterator = round;
			}
		
			if ( iterator == undefined || iterator > 0 ) {
				if ( iterator != undefined && iterator > 0 ) {
					iterator = iterator - 1;
				}
				
				return_string = return_string + number_string.charAt(i);
			} else {
				break;
			}
		}
		
		if ( iterator != undefined && iterator > 0 ) {
			for ( i=0; i < iterator; i = i + 1 ) {
				return_string = return_string + "0";
			}
		}
		
		return parseFloat( return_string );
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function popup_newsletter_submit() {
	if ( jQr('.zgoda', '#popup_newsletter').is(':checked') ) {
		createCookie('popup_newsletter_zapisano', 1, 999);
		var t = setTimeout("jQr.fancybox.close();", 1000);
	} else {
		alert('Musisz wyrazić zgodę na otrzymywanie informacji handlowych od 8a.pl');
		return false;
	}
}
