function CheckIfAllEmpty()
{
	return $('#login').val().length == 0 && $('#password').val().length == 0 && $('#author').val().length == 0 && $('#email').val().length == 0;
}

$(document).ready(function(){
				var validator = $("#commentform").validate({
					rules: {
						login: {
							required: function(element) {
				        		if($('#author').val().length == 0 && $('#email').val().length == 0)
								{
									return $('#login').val().length == 0 || $('#password').val().length == 0;
								}
								else if(CheckIfAllEmpty())
								{
									return true;
								}
								
								return false;
				      		}
						},
						password: {
							required: function(element) {
								if($('#author').val().length == 0 && $('#email').val().length == 0)
								{
									return $('#login').val().length == 0 || $('#password').val().length == 0;
								}
								else if(CheckIfAllEmpty())
								{
									return true;
								}
								
								return false;
				      		}
						},
						
						author: {						
							required: function(element) {
								if($('#login').val().length == 0 && $('#password').val().length == 0)
								{
									return $('#author').val().length == 0 || $('#email').val().length == 0;
								}
								else if(CheckIfAllEmpty())
								{
									return true;
								}
								return false;
				      		}
						},
						email: {							
							required: function(element) {
								if($('#login').val().length == 0 && $('#password').val().length == 0)
								{
									return $('#author').val().length == 0 || $('#email').val().length == 0;
								}
								else if(CheckIfAllEmpty())
								{
									return true;
								}
								return false;
				      		},
							email: true
						},
						comment: {
							required: true
						}
					}, 
					errorElement: "span",
					messages: {
						comment: {
							required: "Wypełnij pole komentarza"
						},
						login: {
							required: "Wypełnij pole login"
						},
						password: {
							required: "Wypełnij pole hasło"
						},
						author: {
							required: "Wypełnij pole podpis"
						},
						email: {
							required: "Wypełnij pole e-mail",
							email: "Zły format e-mail"
						}						
					},
					errorPlacement: function(error, element) {
						    error.insertAfter(element);
						}					
				});
			});
