/*
 * Translated default messages for the jQuery validation plugin.
 * Language: PL
 */
jQuery.extend(jQuery.validator.messages, {
	required: "To pole jest wymagane.",
	remote: "Proszę o wypełnienie tego pola.",
	email: "Proszę o podanie prawidłowego adresu email.",
	url: "Proszę o podanie prawidłowego URL.",
	date: "Proszę o podanie prawidłowej daty.",
	dateISO: "Proszę o podanie prawidłowej daty (ISO).",
	number: "Proszę o podanie prawidłowej liczby.",
	digits: "Proszę o podanie samych cyfr.",
	creditcard: "Proszę o podanie prawidłowej karty kredytowej.",
	equalTo: "Proszę o podanie tej samej wartości ponownie.",
	accept: "Proszę o podanie wartości z prawidłowym rozszerzeniem.",
	maxlength: jQuery.format("Proszę o podanie nie więcej niż {0} znaków."),
	minlength: jQuery.format("Proszę o podanie przynajmniej {0} znaków."),
	rangelength: jQuery.format("Proszę o podanie wartości o długości od {0} do {1} znaków."),
	rangeValue: jQuery.format("Proszę o podanie wartości z przedziału od {0} do {1}."),
	range: jQuery.format("Proszę o podanie wartości z przedziału od {0} do {1}."),
	maxValue: jQuery.format("Proszę o podanie wartości mniejszej bądź równej {0}."),
	max: jQuery.format("Proszę o podanie wartości mniejszej bądź równej {0}."),
	minValue: jQuery.format("Proszę o podanie wartości większej bądź równej {0}."),
	min: jQuery.format("Proszę o podanie wartości większej bądź równej {0}.")
});

$(document).ready(function() {
	  var validator = $("#formreservationstep1").validate({
			highlight: function(element, errorClass) {
				 var id = $(element).attr('id');
				 $('#p'+id).addClass('perror');
		  	},		
		  	unhighlight: function(element, errorClass) {
				 var id = $(element).attr('id');
				 $('#p'+id).removeClass('perror');
		  	},
			errorPlacement: function(error, element) {
				var id = $(element).attr('id');
				$('#p'+id).append(error);
				//element.parent().append(error);
			},
			submitHandler: function(form) {
				checkAvailability2(form);
			},
			rules: {
				data_przyjazdu:{
					
				},
				data_wyjazdu:{
					
				},
				name:{
					required: true
				},
				surname:{
					required: true
				},
				email:{
					required: true,
					email: true,
					emailpl: true
				},
				telephone:{
					required: true
				},
				number_car:{
					required: true,
					min: 1
				},
				number_person:{
					required: true,
					min: 1
				},
				confirm:{
					required: true
				},
				amount:{
					required: true,
					min: 1
				}
			},
			messages: {
				data_przyjazdu:{
					required: 'Proszę o prawidłowe wypełnienie daty przyjazdu i wyjazdu',
					remote: 'Nie posiadamy wolnych miejsc w wybranym terminie. Prosimy o kontakt'
				},
				data_wyjazdu:{
					required: 'Proszę o prawidłowe wypełnienie daty przyjazdu i wyjazdu',
					remote: 'Nie posiadamy wolnych miejsc w wybranym terminie. Prosimy o kontakt'
				},
				number_car: {
					remote: 'Nie posiadamy wolnych miejsc dla tej ilości samochodów',
					min: 'Zła liczba samochodów'
				},
				number_person:{
					min: 'Zła liczba osób'
				},
				email:{
					email: 'Nieprawidłow e-mail'
				},
				amount:{
					email: 'Nieprawidłowa cena zmień liczbę samochodów'
				}
			}
	  });
  	  var validator2 = $('#formcontact').validate({
		errorPlacement: function(error, element) {
			error.insertAfter(element).css({display:"none"}).slideDown();
		},
		submitHandler: function(form) {
			sendformcontact(form);
			return false;
		},
	  	rules: {
	  		imie:{
	  			required: true
	  		},
	  		email:{
	  			required: true,
	  			email: true
	  		},
	  		wiadomosc:{
	  			required: true
	  		}
	  	},
		messages: {
			imie:{
				required: 'Proszę wpisać imię i nazwisko!'
			},
			email:{
				required: 'Nieprawidłowy adres e-mail!',
				email: 'Nieprawidłowy adres e-mail!'
			},
			wiadmosc:{
				required: 'Proszę wpisać treść wiadomości!'
			}

		}
	  });
	  
	  	var validator = $("#formreservationstep2").validate({
		submitHandler: function(form) {
			if($("#formreservationstep2 #ptyp_platnosc input:radio:checked").attr('value')==2){
				$('#formreservationstep2').attr('action', 'https://www.platnosci.pl/paygw/UTF/NewPayment');
			}else{
				$('#formreservationstep2').attr('action', '?page=rezerwacje&step=3');
			}		
			insertSig(form);			
			saveSteps(form, 3);
		},
		highlight: function(element, errorClass) {
			 var id = $(element).attr('id');
			 $('#p'+id).addClass('perror');
	  	},		
	  	unhighlight: function(element, errorClass) {
			 var id = $(element).attr('id');
			 $('#p'+id).removeClass('perror');
	  	},
		errorPlacement: function(error, element) {
			var id = $(element).attr('id');
			$('#p'+id).append(error);
		},
		rules: {
			invoice_name_company:{
				required: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				}
			},
			invoice_address:{
				required: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				}
			},
			invoice_code:{
				required: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				},
				postalCode: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				}
				
			},
			invoice_city:{
				required: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				}
			},
			invoice_nip:{
				required: {
					depends: function(element) {
			           if($("#pfaktura input:radio:checked").val()=='1') return true;
			           else return false;
         			}
				}
			}
		},
		messages: {
			
		}
	  });
	  	$.validator.addMethod('postalCode', function (value) { 
	    return /^((\d{2}-\d{3}))$/.test(value); 
		}, 'Zły format kodu.');

		jQuery.validator.addMethod("emailpl", function(value, element) {
          	var valueorg = value; 
          	value = value.replace('ć','c').replace('Ć', 'C').replace('ś', 's').replace('Ś', 'S').replace('ą', 'a').replace('Ą', 'A').replace('ż', 'z').replace('Ż', 'Z').replace('ń', 'n').replace('Ń', 'N').replace('ę', 'e').replace('Ę', 'E');
          	if(valueorg != value)
          	{
          		return this.optional(element) || false;
          	}else{
          		return this.optional(element) || true;
          	}
		}, $.format("Polskie litery w mailu"));

 });

