var IE = document.all?true:false

jQuery(document).ready(function($) {

	

	
	

 /********************************************
	walidacja formularza
********************************************/ 
(function(){
	
	    $.fn.validate = {
	        init: function(o) {
	            if ($(o).hasClass('required-field')) {  this.required(o) };
	            if (o.name == 'email') { this.email(o) };
	            if (o.name == 'phone') { this.phone(o) };
	        },
	        required: function(o) {
	            if (o.value == '') {
	              error(o,'Informacja jest wymagana');
	            } else {
	              correct(o);
	            };
	        },
	        email: function(o) {
	            var email  = /^([a-zA-Z0-9_\.\,\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	             if (o.value.match(email)) {
	                  correct(o);
	              } else {
	                 	correct(o);
	                  error(o,'Niepoprawny e-mail');
	              };
	        },
	        phone: function(o) {
	            var phone  = /\d/g;
	            var letters = /[a-zA-Z]+/g;
	            if (o.value.match(phone) && !o.value.match(letters)) {
	                  correct(o);
	              } else {
	  	            error(o,'Niepoprawny numer telefonu');
	              };
	        }
	     };

	     function error(o,msg) {
	              $(o).parent().addClass('parent-msg').append('<span class="msg">' +msg+ '</span>');
	     		};
	      function correct(o) {
	              $(o).parent().children('.msg').remove();
	     		};	
	     		
	      $("input.validated").blur(function() {
	              $(this).validate.init(this);
	      		});
})();

});

	function check() {
	    if ( $('.parent-msg').children().is('.msg') || $('.required-field').val() == 0 ) {
	        return false
	    } else {
	        return true
	    };
	}; 





 	
				
				
				
				
				
				
											
