SubmittingForm=function() {
	//alert("Dane wprowadzone poprawnie.");
	// pobieramy wartości odpowiednich pól
	
	var emailVal   = $("#fEmail").val();
	var passwordVal   = $("#fPassword").val();
	var password2Val   = $("#fPassword2").val();
	
	var companyVal   = $("#fCompany").val();
	var nipVal   = $("#fNIP").val();
	
	var nameVal    = $("#fName").val();
	var surnameVal    = $("#fSurname").val();
	var streetVal   = $("#fStreet").val();
	var postCodeVal   = $("#fPostCode").val();
	var localityVal   = $("#fLocality").val();
	var provinceIDVal   = $("#fProvincyID").val();
	var countryIDVal   = $("#fCountryID").val();
	
	var phoneVal   = $("#fPhone").val();
	var phone2Val   = $("#fPhone2").val();
	
	var shipmentVal = $("#fShipment").val();
	
	var messageVal = $("#fMessage").val();
	var agreeVal   = $("#fAgree:checked").val();

	$.ajax({
		type: "POST",
		url:  "sendmail.php",
		data: { email: emailVal, 
				password: passwordVal,
				password2: password2Val,
				name: nameVal, 
				surname: surnameVal, 
				company: companyVal, 
				nip: nipVal,
				street: streetVal, 
				postCode: postCodeVal,
				locality: localityVal,
				provinceID: provinceIDVal,
				countryID: countryIDVal,
				phone: phoneVal,
				phone2: phone2Val,
				gg: ggVal,
				shipment: shipmentVal,
				message: messageVal },
			// msg zawiera wartość zwróconą przez skrypt php w przypadku poprawnego zakończenia działania
			success: function(msg) {
			// zapiszmy wynik działania skryptu na stronie html w div o id="content"
			$("#content").html(msg);
			// schowajmy fomę
			$("#form").fadeOut("slow");
		},
		// wystąpiły błędy
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			$("#content").html('Wystąpił błąd. Proszę spróbować jeszcze raz.');
			$("#form").fadeOut("slow");
		}
	});
}

validationForm=function() {
	$(document).ready(function() {
		$("#form").validate({
			success: function(label) {
	//			label.addClass("valid").html("ok")
			},
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {		// simple rule, converted to {required:true}
				fEmail: {				// compound rule
					required: true,
					email: true
				},
				fPassword: "required",
				fPassword2: "required",
				fName: "required",
				fSurname: "required",
				fStreet: "required",
				fPostCode: "required",
				fLocality: "required",
				fProvinceID: "required",
				fCountryID: "required",
				fPhone: "required",
				fShipmentID: "required",
				fMessage: {
					required: true
				},
				fAgree: "required"
			},
			messages: {
				fEmail: "Podaj e-mail.",
				fPassword: "Podaj hasło.",
				fPassword2: "Podaj hasło.",
				fName: "Podaj imię.",
				fSurname: "Podaj nazwisko.",
				fStreet: "Podaj ulicę.",
				fPostCode: "Podaj kod pocztowy.",
				fLocality: "Podaj miejscowość.",
				fProvinceID: "Podaj województwo.",
				fCountryID: "Podaj kraj.",
				fPhone: "Podaj numer telefonu.",
				
				fShipmentID: "Wybierz sposób dostawy.",
				fMessage: "Wprowadź treść wiadomości.",
				fAgree: "Wysłanie formularza, wymaga wyrażenia zgody." 
			}
		});
		
	});
}


validationFormENG=function() {
	$(document).ready(function() {
		$("#form").validate({
			success: function(label) {
	//			label.addClass("valid").html("ok")
			},
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {		// simple rule, converted to {required:true}
				fEmail: {				// compound rule
					required: true,
					email: true
				},
				fPassword: "required",
				fPassword2: "required",
				fName: "required",
				fSurname: "required",
				fStreet: "required",
				fPostCode: "required",
				fLocality: "required",
				fProvinceID: "required",
				fCountryID: "required",
				fPhone: "required",
				fShipmentID: "required",
				fMessage: {
					required: true
				},
				fAgree: "required"
			},
			messages: {
				fEmail: "Enter the e-mail.",
				fPassword: "Enter the password.",
				fPassword2: "Enter the password.",
				fName: "Enter the name.",
				fSurname: "Enter the surname.",
				fStreet: "Enter the street.",
				fPostCode: "Enter the post code.",
				fLocality: "Enter the locality.",
				fProvinceID: "Enter the province.",
				fCountryID: "Enter the country.",
				fPhone: "Enter the phone.",
				
				fShipmentID: "Choose delivery method.",
				fMessage: "Enter message.",
				fAgree: "By submitting this form, requires the consent." 
			}
		});
		
	});
}

validationModelENG=function() {
	$(document).ready(function() {
		$("#form").validate({
			success: function(label) {
	//			label.addClass("valid").html("ok")
			},
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {		// simple rule, converted to {required:true}
				fSize: "required",
				fSizeBra: "required",
				fColor: "required",
				fVersion: "required"
			},
			messages: {
				fSize: "Choose the size.",
				fSizeBra: "Choose the size.",
				fColor: "Choose the color.",
				fVersion: "Choose the version."
			}
		});
		
	});
}


validationModel=function() {
	$(document).ready(function() {
		$("#form").validate({
			success: function(label) {
	//			label.addClass("valid").html("ok")
			},
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {		// simple rule, converted to {required:true}
				fSize: "required",
				fSizeBra: "required",
				fColor: "required",
				fVersion: "required"
			},
			messages: {
				fSize: "Wybierz rozmiar.",
				fSizeBra: "Wybierz rozmiar.",
				fColor: "Wybierz kolor.",
				fVersion: "Wybierz wersję."
			}
		});
		
	});
}

