// apply inline-box only for mozilla
if( jQuery.browser.mozilla ) {
	// do when DOM is ready
	$( function() {
		// search form, hide it, search labels to modify, filter classes nocmx and error
		$( 'form.cmxform' ).hide().find( 'p>label:not(.nocmx):not(.error)' ).each( function() {
			var $this = $(this);
			var labelContent = $this.html();
			var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
			// create block element with width of label
			var labelSpan = $("<span>")
				.css("display", "block")
				.width(labelWidth)
				.html(labelContent);
			// change display to mozilla specific inline-box
			$this.css("display", "-moz-inline-box")
				// remove children
				.empty()
				// add span element
				.append(labelSpan);
		// show form again
		}).end().show();
	});
};


//$.validator.setDefaults({
//	submitHandler: function() { alert("submitted!"); }
//});


$().ready(function() {
	// validate the comment form when it is submitted
	$('#signupKontakt').append('<input type="hidden" name="kluczyk" value="10762346498743087237867698790">');
	$('#signupKontakt input[name="wyslij"]').removeAttr('name');
	$("#commentForm").validate();
	$('#signupForm').append('<input type="hidden" name="klucz" value="23464982378676987">');
	$('#signupForm input[name="send"]').removeAttr('name');
	// validate signup form on keyup and submit
	$("#signupKontakt").validate({
		rules: {
			captcha: { 
			required: true,
				remote: {
				url: "http://sklep.rottka.pl/check.php",
				type: "post"
				}
			}, 
			KlientImie: {
				required: true,
				minlength: 2
			},
			KlientNazwisko: {
				required: true,
				minlength: 3
			},
			KlientMail: {
				required: true,
				KlientMail: true
			},
			temat: {
				required: true,
				minlength: 5
			},
			tresc: {
				required: true,
				minlength: 15
			},
			agree: "required"
		},
		messages: {
			captcha: { 
				required: "Wpisz znaki widoczne obok na orazku (zachowaj wielkość):",
				remote: jQuery.format("Wpisz poprawnie znaki.") 
			 }, 
			KlientImie: {
				required:"Proszę wypełnić popranie pole Imię",
				minlength: "Imię wymaga minimum 2 znaków"
			},
			KlientNazwisko: {
				required:"Proszę wypełnić popranie pole Nazwisko",
				minlength: "Nazwisko wymaga minimum 3 znaków"
			},
			
			KlientMail: "Proszę poprawnie wypełnić pole E-mail",
			temat: {
				required: "Proszę wypełnić pole Temat",
				minlength: "Temat wymaga minimum 5 znaków"
			},
			tresc: {
				required: "Proszę wypełnić pole Pytanie",
				minlength: "Pytanie wymaga minimum 15 znaków"
			},
			agree: "Akceptacja obowiązkowa"
		}
	});
	$("#signupForm").validate({
		rules: {
			
			KlientImie: {
				required: true,
				minlength: 2,
				KlientImie: true
				
			},
			KlientNazwisko: {
				required: true,
				minlength: 2,
				KlientNazwisko: true
				
			},
			KlientUlica: "required",
			KlientDom: "required",
			KlientLokal: "required",
			KlientPostcode: "required",
			KlientPostcode: {
				required: true,
				KlientPostcode: true
			},
			KlientMiasto: "required",
			KlientTelefon: "required",
			KlientWysDom: "required",
			KlientWysLokal: "required",
			
			KlientWysPostcode: {
				required: true,
				KlientPostcode: true
			},
			KlientWysMiasto: "required",
			KlientWysUlica: "required",
			FakturaUlica: "required",
			FakturaDom: "required",
			FakturaLokal: "required",
			temat: {
				required: true,
				minlength: 5
			},
			tresc: {
				required: true,
				minlength: 15
			},
			FakturaPostcode: {
				required: true,
				KlientPostcode: true
			},
			FakturaMiasto: "required",
			
			FakturaNip: {
				required: true,
				FakturaNip: true
			},
			KlientMail: {
				required: true,
				KlientMail: true
			},
			password: {
				required: true,
				minlength: 6,
				maxlength: 12
			},
			confirm_password: {
				required: true,
				minlength: 6,
				maxlength: 12,
				equalTo: "#password"
			},
			loginemail: {
				required: true,
				loginemail: true
			},
			haslo: {
				required: true,
				minlength: 6,
				maxlength: 12
			},
			osNazwa: "required",
			osCena: {
				required: true,
				waga: true
			},
			osPrzesylka: {
				required: true,
				waga: true
			},
			
			agree: "required"
			
			
		},
		messages: {
			KlientImie: "Proszę wypełnić poprawnie pole Imię",
			KlientNazwisko: "Proszę wypełnić poprawnie pole Nazwisko",
			KlientUlica: "Proszę wypełnić pole Ulica",
			KlientDom: " ",
			KlientLokal: "Proszę wypełnić zaznaczone pole",
			KlientPostcode: "Proszę wypełnić poprawnie Kod pocztowy",
			KlientMiasto: "Proszę wypełnić pole Miejscowość",
			KlientTelefon: "Proszę wypełnić pole Telefon",
			KlientWysDom: " ",
			KlientWysLokal: "Proszę wypełnić zaznaczone pole",
			KlientWysPostcode: "Proszę wypełnić poprawnie Kod pocztowy",
			KlientWysMiasto: "Proszę wypełnić pole Miejscowość",
			KlientWysUlica: "Proszę wypełnić pole Ulica",
			FakturaUlica: "Proszę wypełnić pole Ulica",
			FakturaDom: " ",
			FakturaLokal: "Proszę wypełnić zaznaczone pole",
			FakturaPostcode: "Proszę wypełnić poprawnie Kod pocztowy",
			FakturaMiasto: "Proszę wypełnić pole Miejscowość",
			FakturaNip: "Proszę wypełnić pole NIP",
			KlientMail: "Proszę poprawnie wypełnić pole E-mail",
			temat: {
				required: "Proszę wypełnić pole Temat",
				minlength: "Temat wymaga minimum 5 znaków"
			},
			tresc: {
				required: "Proszę wypełnić pole Pytanie",
				minlength: "Pytanie wymaga minimum 15 znaków"
			},
			password: {
				required: "Proszę wypełnić pole Hasło",
				minlength: "Hasło wymaga minimum 6 znaków",
				maxlength: "Hasło nie może przekraczać 12 znaków"
			},
			confirm_password: {
				required: "Proszę wypełnić pole Powtórz hasło",
				minlength: "Hasło wymaga minimum 6 znaków",
				maxlength: "Hasło nie może przekraczać 12 znaków",
				equalTo: "Wpisane hasła nie są takie same!"
			},
			loginemail: "Proszę poprawnie wypełnić pole E-mail",
			haslo: {
				required: "Proszę wypełnić pole Hasło",
				minlength: "Hasło wymaga minimum 6 znaków",
				maxlength: "Hasło nie może przekraczać 12 znaków"
			},
			osNazwa: "Proszę wypełnić nazwę produktu",
			osCena: "Proszę wypełnić poprawnie cenę produktu",
			osPrzesylka: "Proszę wypełnić poprawnie wagę produktu",
			agree: "Akceptacja obowiązkowa"
			
		}
	});
	
	// propose username by combining first- and lastname
	$("#username").focus(function() {
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		if(firstname && lastname && !this.value) {
			this.value = firstname + "." + lastname;
		}
	});
	
	// check if confirm password is still valid after password changed
	$("#password").blur(function() {
		$("#confirm_password").valid();
	});
	
	//code to hide topic selection, disable for demo
	var addres = $("#addres");
	// addres topics are optional, hide at first
	var inital = addres.is(":checked");
	var topics = $("#addres_topics")[inital ? "removeClass" : "addClass"]("gray");
	var topicInputs = topics.find("input").attr("disabled", !inital);
	// show when addres is checked
	addres.click(function() {
		topics[this.checked ? "removeClass" : "addClass"]("gray");
		topicInputs.attr("disabled", !this.checked);

	});

var faktura = $("#faktura");
	// faktura topics are optional, hide at first
	var inital2 = faktura.is(":checked");
	var topics2 = $("#faktura_topics")[inital2 ? "removeClass" : "addClass"]("fakt");
	var topicInputs2 = topics2.find("input").attr("disabled", !inital2);
	// show when faktura is checked
	faktura.click(function() {
		topics2[this.checked ? "removeClass" : "addClass"]("fakt");
		topicInputs2.attr("disabled", !this.checked);

	});






	var kontakt = $("#kontakt");
	// faktura topics are optional, hide at first
	var inital3 = faktura.is(":checked");
	var topics3 = $("#kontakt_topics")[inital3 ? "removeClass" : "addClass"]("fakt");
	var topicInputs3 = topics3.find("input").attr("disabled", !inital3);
	// show when faktura is checked
	kontakt.click(function() {
		topics3[this.checked ? "removeClass" : "addClass"]("fakt");
		topicInputs3.attr("disabled", !this.checked);

	});


	$("#signupForm2").validate({
		rules: {
			
			KlientImie: {
				required: true,
				minlength: 2,
				KlientImie: true
				
			},
			KlientNazwisko: {
				required: true,
				minlength: 2,
				KlientNazwisko: true
				
			},
			
			KlientMail: {
				required: true,
				KlientMail: true
			},
			password: {
				required: true,
				minlength: 6,
				maxlength: 12
			},
			confirm_password: {
				required: true,
				minlength: 6,
				maxlength: 12,
				equalTo: "#password"
			},

			
			agree: "required"
			
			
		},
		messages: {
			KlientImie:  {
				required: "Proszę wypełnić poprawnie pole Imię",
				minlength: "Imię wymaga minimum 2 znaków"
			},
			KlientNazwisko: {
				required: "Proszę wypełnić poprawnie pole Nazwisko",
				minlength: "Nazwisko wymaga minimum 2 znaków"
			},
			KlientMail: "Proszę poprawnie wypełnić pole E-mail",
			password: {
				required: "Proszę wypełnić pole Hasło",
				minlength: "Hasło wymaga minimum 6 znaków",
				maxlength: "Hasło nie może przekraczać 12 znaków"
			},
			confirm_password: {
				required: "Proszę wypełnić pole Powtórz hasło",
				minlength: "Hasło wymaga minimum 6 znaków",
				maxlength: "Hasło nie może przekraczać 12 znaków",
				equalTo: "Wpisane hasła nie są takie same!"
			},
			agree: "Akceptacja obowiązkowa"
			
		}
	});
	


});


   

$(document).ready(
	function()
	{
		$('a#form_open').click(function()
			{
				$('div.kontakt:hidden').show();
				$('a#form_open:visible').hide();
				$('a#form_close:hidden').show();
				return false;
			}
		);
		$('a#form_close').click(function()
			{
				$('div.kontakt:visible').hide();
				$('a#form_close:visible').hide();
				$('a#form_open:hidden').show();
				return false;
			}
		);
	}
);


	
