
var Biuletyn = {
		confirmDelete: function(container_id, application_id){
		if ($('input[name=object_id]').val() == application_id){
			$('input[name=object_id]').val(0);
			$('#'+container_id).hide();
			return false;
		}else{
			$('input[name=object_id]').val(application_id);
			$('#'+container_id).show();
			return false;
		}
	}
}



$(document).ready(function(){
	
	$(function() {
		$.datepicker.setDefaults($.datepicker.regional['pl']);
		$("#data").datepicker({dateFormat: 'yy-mm-dd'});
	});

	
	jQuery.validator.addMethod("szkolenie_arr", 
			function(value, element) {
				if ($('input[name="szkolenie[]"]:checked').length > 0 && $('input[name="szkolenie[]"]:checked').length < 3) return true;
				return false;
			}, jQuery.format("")
		);
	
	var validator = $('form#contactForm').validate({
		errorClass: "invalid",
		rules: {
			imie: {
				required: true,
				rangelength: [3, 255]
			},
			nazwisko: {
				required: true,
				rangelength: [3, 255]
			},
			email: {
				required: true,
				email: true
			},
			telefon: {
				required: true				
			},
			
			'szkolenie[]': {
				required: true,
				maxlength:2
			},
			
			przetwarzanie_danych:{
				required: true
			},
			zgoda_kierownictwa:{
				required: true
			},
			zasady_uczestnictwa:{
				required: true
			}

			
		},
		messages: {
			imie: {
				required: "Wpisz imię",
				rangelength: "Podaj tytuł - Wpisz min 3 znaki"
			},
			nazwisko: {
				required: "Podaj imię",
				rangelength: "Podaj imię - Wpisz min 3 znaki"
			},
			email: {
				required: "Podaj adres email",
				email: "Wpisz prawidłowy adres email"
			},
			telefon: {
				required: "Podaj numer telefonu",
				email: "Wpisz prawidłowy numer telefonu"
			},
			przetwarzanie_danych: {
				required: "Zaznacz"
			},
			zgoda_kierownictwa: {
				required: "Zaznacz"
			},
			zasady_uczestnictwa: {
				required: "Zaznacz"
			}
		},
		
		invalidHandler: function(error, element) {
				if (validator.numberOfInvalids() != 0){
					PrbMessages.init();
					PrbMessages.appendError("Formularz zawiera błędy. Uzupełnij wszystkie oznaczone pola.");
					PrbMessages.show();
				}
				if (validator.numberOfInvalids() == 0){
					PrbMessages.init();
					PrbMessages.hide();
				}
				
				
		},
		errorPlacement: function(error, element) {
			var errElem;			
			if (element.attr('class') == 'checkbox invalid' && element.is('input')){
				errElem =  element.parent();
				//element.removeClass('error');
			}
			else if (element.attr('class') == 'checkboxSzkolenia invalid' && element.is('input')){
				errElem =  element.parent().parent();
				//element.removeClass('error');
			}
			else errElem = element;
			
			if(error.html() != ''){
				errElem.addClass('errorLabel');
			}else errElem.removeClass('errorLabel');
		},

		
		success: "success"
		});

	});
