function okno(adres,nazwa,szer,wys) {
	var left = (screen.width-szer)/2;
	left = Math.round(left);
	var top = (screen.height-wys-100)/2;
	top = Math.round(top);
	nazwa = window.open(adres,nazwa,'resizable=0,height='+wys+',width='+szer+',top='+top+',left='+left);
	nazwa.moveTo(left,top);
	nazwa.focus();
}
	
function openfull(parametr){
w = window.open(parametr, "", "scrollbars=yes,resizable=yes,menubar=no", true);
w.focus ();
}	

function PoliczRate(koszyk) { 
	var price = document.getElementById('productPrice').value;
	window.open('http://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo=28011111&goodsValue='+price, 'Policz_rate', 'width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}


function CaptchaRefreshs() { 
  image = "_tools/captcha/captcha_image.php" //name of the image 
  date = new Date(); 
  tmp = "?"+date.getTime() 
  document.images["captcha"].src = image+tmp 
}  

function pokazdiv(el) {
         for(var i=1; i<=30; i++) {
                 if(el == i) {
                       document.getElementById(el).style.display = "block";
//                         document.getElementById(el).fadeIn(1800);
                 } else {
                       document.getElementById(i).style.display = "none";
                 }
        }
}

function isEmail(value) {
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
};

jQ(function() {
	jQ("#slider form").submit(function() {
		var errors = false;
		
		if(jQ('input[name=typ]').val() == '')
			jQ('input[name=typ]').val('Brak');
		
		jQ("#slider input[type=text]").not('input[name=typ]').each(function() {
			if(jQ(this).val() == '') {
				errors = true;
			}
		});
		
		if(!isEmail(jQ('#slider input[name=email]').val())) {
			errors = true;
		}
		
		if(errors == false) {
			jQ("#slider input[type=submit]").remove();
			jQ.post("form.php", jQ("#slider form").serialize(), function(data) {
				if(data == 'ok') {
					alert("Dziękujemy za przesłania formularza.\n\nNasz konsultant skontaktuje się z Państwem w celu przedstawienia naszej oferty.");
				} else
					alert("Wystąpił błąd. Przepraszamy za utrudnienia.");
				jQ("#slider").remove();
				jQ("#overlay").fadeOut(200).remove();
			});
		} else {
			alert('Wypełnij formularz przed wysłaniem. Pamiętaj o podaniu poprawnego adresu e-mail.');
		}
		
		return false;
	});
	
	jQ("#slider #handle").click(function() {
		
		if(jQ("#slider").css("right") == "-259px")
		{
			jQ("#slider").animate({"right": "0px"}, 300);
			jQ("#overlay").fadeTo(300, 0.7);
		}
		else
		{
			jQ("#slider").animate({"right": "-259px"}, 200);
			jQ("#overlay").fadeOut(200);
		}
	});
	
	jQ("#overlay").click(function() {
		jQ("#slider").animate({"right": "-259px"}, 200);
		jQ("#overlay").fadeOut(200);
	});
	
	jQ('#slider select').css({opacity: 0});
	
	/*jQ('#slider select').change(function() {
		jQ(this).prev('span').html(jQ('option:selected', this).val());
	});*/
	
	/*jQ('#slider #producent').change(function() {
		var select = jQ('#select-container select[rel="'+jQ(this).val()+'"]').html();
		jQ('#slider #typ').html(select);
	});*/
	
	if(jQ.browser.msie) {
		if(jQ.browser.version == 9)
			jQ('#slider input[type=text], #slider select').css({marginBottom: 38});
		if(jQ.browser.version == 8)
			jQ('#slider input[type=text]').css({marginBottom: 37});
		if(jQ.browser.version == 7) {
			jQ('#slider select').css({marginBottom: 34});
			jQ('#slider input[type=text]').css({marginBottom: 35});
		}
	}

	jQ.widget("ui.combobox", {
		_create: function() {
			var self = this,
				select = this.element.hide(),
				selected = select.children(":selected"),
				value = selected.val() ? selected.text() : "";
			var input = this.input = jQ("<input>")
				.attr({'name': select.attr('name'), 'type': 'text'})
				.insertAfter(select)
				.val(value)
				.autocomplete({
					delay: 0,
					minLength: 0,
					source: function(request, response) {
						var matcher = new RegExp(jQ.ui.autocomplete.escapeRegex(request.term), "i");
						response(select.children("option").map(function() {
							var text = jQ(this).text();
							if (this.value && (!request.term || matcher.test(text)))
								return {
									label: text.replace(
										new RegExp(
											"(?![^&;]+;)(?!<[^<>]*)(" +
											jQ.ui.autocomplete.escapeRegex(request.term) +
											")(?![^<>]*>)(?![^&;]+;)", "gi"
										), "<strong>$1</strong>"),
									value: text,
									option: this
								};
						}));
					},
					select: function(event, ui) {
						ui.item.option.selected = true;
						self._trigger("selected", event, {
							item: ui.item.option
						});
						
						if(jQ(this).prev().attr('name') == 'producent') {
							jQ('#slider #typ').val('');
							jQ('#slider #typ').next().val('');
							
							var select = jQ('#select-container select[rel="'+jQ('#slider #producent').val()+'"]').html();
							jQ('#slider #typ').html(select);
							jQ("#slider #typ").combobox();
						}
					},
					change: function(event, ui) {
						if (!ui.item) {
							var matcher = new RegExp("^" + jQ.ui.autocomplete.escapeRegex(jQ(this).val()) + "$", "i"),
								valid = false;
							select.children("option").each(function() {
								if (jQ(this).text().match(matcher)) {
									this.selected = valid = true;
									return false;
								}
							});
							if (!valid) {
								// remove invalid value, as it didn't match anything
								//jQ(this).val("");
								select.val(jQ(this).val());
								input.data("autocomplete").term = "";
								return false;
							}
						}
					}
				})
				.addClass("ui-widget ui-widget-content ui-corner-left")
				.click(function() {
					// close if already visible
					if (input.autocomplete("widget").is(":visible")) {
						input.autocomplete("close");
						return;
					}

					// work around a bug (likely same cause as #5265)
					//jQ(this).blur();

					// pass empty string as value to search for, displaying all results
					input.autocomplete("search", "");
					input.focus();
				});

			input.data("autocomplete")._renderItem = function(ul, item) {
				return jQ("<li></li>")
					.data("item.autocomplete", item)
					.append("<a>" + item.label + "</a>")
					.appendTo(ul);
			};

			this.button = jQ("<button type='button'>&nbsp;</button>")
				.attr("tabIndex", -1)
				.attr("title", "Show All Items")
				.insertAfter(input)
				.button({
					icons: {
						primary: "ui-icon-triangle-1-s"
					},
					text: false
				})
				.removeClass("ui-corner-all")
				.addClass("ui-corner-right ui-button-icon")
				.click(function() {
					// close if already visible
					if (input.autocomplete("widget").is(":visible")) {
						input.autocomplete("close");
						return;
					}

					// work around a bug (likely same cause as #5265)
					jQ(this).blur();

					// pass empty string as value to search for, displaying all results
					input.autocomplete("search", "");
					input.focus();
				});
		},

		destroy: function() {
			this.input.remove();
			this.button.remove();
			this.element.show();
			jQ.Widget.prototype.destroy.call(this);
		}
	});
	
	jQ("#producent").combobox();
	jQ("#slider #typ").combobox();
});
