function ValidateEmailAndPhone()
{
	alert('test');
	return $("#phone").val().length == 0 || $("#phone").val().length == 0
}

$(document).ready(function(){
			
				var emailFormatError  = "Zły format email";
				var phoneFormatError = "Zły format numeru telefonu";
				var urlAndFilesMissingError = "Załącz pracę lub podaj link do strony";
				var emailAndPhoneMissingError = "Wypełnij pole email lub telefon";
				var licenseError = "Muisz zaakceptować warunki";
				var rulesError = "Musisz zaakceptować regulamin strony";
				var tagsError = 'Wypełnij pole "Tagi".';
				var authorSignatureError = 'Wypełnij pole "Podpis autora prac".';
				var descriptionError = 'Wypałnij pole "Opis Twojej pracy".';
			
				$.validator.addMethod("phoneFormat", function(value, element) { 
					return this.optional(element) || /^[0-9\[\]\+\-\(\)\s{}]+$/.test(value); 
				}, phoneFormatError);			

				//Zakladam, ze gdy mamy wiecej niz 1 input to plik zostal dodany.
				$.validator.addMethod("requiredFile", function(value, element) { 
					return (
						$('#submitForm input[type=file]:first').attr('value').length > 0 ||					
						$("#siteurl").val().length > 0
					);
				}, urlAndFilesMissingError);
				
				$.validator.addClassRules({
					upload : {
						requiredFile: true
						}
				});
				
				$(document).ready(function(){
					$("#phone").change(function(){
						$("#submitForm").validate().element("#email" );
					});
					
					$("#email").change(function(){
						$("#submitForm").validate().element("#phone" );
					});
					
					$("#tags").change(function(){
						$("#submitForm").validate().element("#tags" );
					});
					
					$("#authorSignature").change(function(){
						$("#submitForm").validate().element("#authorSignature" );
					});
					
					$("#siteurl").change(function(){
						$("#submitForm").validate().element("input[type=file]:first" );
					});
					
					$("#content").change(function(){
						$("#submitForm").validate().element("#content");
					});
					
					$("input[type=file]:first").change(function(){
						$("#submitForm").validate().element("#siteurl" );
					});
					
					$("input[type=file]").blur(function(){
						$("#submitForm").validate().element("input[type=file]");
					});
				});
				
				var validator = $("#submitForm").validate({
					rules: {
						email: {
							email: true,
						    required: function(element) {
					        	return $("#phone").val().length == 0;
					      	}							
						},
						phone: {
						    required: function(element) {
				        		return $("#email").val().length == 0;
				      		},
							phoneFormat: true							
						},
						siteurl: {
							required: function(element) {
					        	return $('#submitForm input[type=file]:first').attr('value').length == 0;
					      	}
						}, 
						tags: {
							required: function(element){
								return $("#tags").val().length == 0;
							}
						},
						description: {
							required: function(element){
								return $("#description").val().length == 0;
							}
						},
						authorSignature: {
							required: function(element){
								return $("#authorSignature").val().length == 0;
							}
						},
						"files[]": {
							accept: false
						}
					},
					messages: {
						email: {
							required: emailAndPhoneMissingError, 
							email: emailFormatError
						},
												
						phone: {
							required: emailAndPhoneMissingError
						},
						
						license: {
							required: licenseError
						},
						rules: {
							required: rulesError
						},
						
						tags: {
							required: tagsError
						},
						description: {
							required: descriptionError
						},
						authorSignature: {
							required: authorSignatureError
						},
						siteurl: {
							required: urlAndFilesMissingError
						}
						
					},
					errorElement: "span",
					
					errorPlacement: function(error, element) {
						if (element.attr("name") == "license"){
						    error.insertAfter("#licenseLabel");
						}
						else if(element.attr("name") == "rules")
						{
							error.insertAfter("#rulesLabel");
						}
						else{
							error.insertAfter(element);
						}
					}
					
				});
				
				
		  	});
