$(document).ready(function() {
		
       errorContainer = $('div.mainError');
       var inputText = new Array();
		inputText[0] = "";
		inputText[1] = "Enter your first name";
		inputText[2] = "Enter your family name";
		inputText[3] = "Enter your current occupation";
		inputText[4] = "Enter your address or your company’s address";
		inputText[5] = "Enter your telephone number";
		inputText[6] = "Enter your e-mail address";
		inputText[7] = "Enter your question";
		
         $(".formContact").submit(function(){
         	$(".formContact input, .formContact textarea").each(function(i){
         		id = $(this).attr("accesskey");
				if ($(this).val() == inputText[id]) {
					$(this).val("");
				}
         	})
         }).validate(
          {
          	errorLabelContainer: errorContainer,
          	showErrors: false,
          	focusInvalid: false,
          	ignoreTitle: true,
			showErrors: function(errorMap, errorList) {
			      var errors = this.numberOfInvalids();
			      if (errors) {     
			        var message = 'Fields contain error data. Incorrect fileds were marked with <span class="coloren">red</span> colour. <br/>Please, correct them and send this form again.';
			        
			     countElements = 0;   
				    
			        $("div.mainError2").html(message);
			        $("div.mainError2").show();
			      } else {
			        $("div.mainError2").hide();
			      }
			   this.defaultShowErrors();
				$("div.mainError").hide();
		    },
			highlight: function(element, errorClass) {
			     $(element).parent()
			                    .addClass(errorClass);
		    },
		    unhighlight: function(element, errorClass) {
			     $(element).parent()
			                    .removeClass(errorClass);
		    },
          	rules: {	
        	     name: {
        	     	required: true
        	     },
        	     surname: {
        	     	required: true
        	     },
        	     stanowisko: {
        	     	required: false
        	     },
        	     address: {
        	     	required: false
        	     },
        	     email: {
        	       required: true,
        	       email: true
        	     },
        	     phone: {
        	     	required: false
        	     },
        	     question: {
        	     	required: false
        	     }
           },
           messages: {
        	     name: {
        	       required: "Prosimy podać Imię i Nazwisko"
        	     },
        	     surname: {
        	     	required: "Prosimy podać Ulicę."
        	     },
        	    stanowisko: {
        	     	required: "Prosimy podać Kod pocztowy."
        	     },
        	     address: {
        	     	required: "Prosimy podać Miasto."
        	     },
        	     email: {
        	       required: "Prosimy podać Email",
        	       email: "Prosimy podać prawidłowy Email."
        	     },
        	     phone: {
        	     	required: "Prosimy podać jeden numer kontaktowy."
        	     },
        	     question: {
        	     	required: "Prosimy wybrać województwo."
        	     }
           }
          });
});
