def file_xml(request, repo, path):
     if request.method == 'POST':
         errors = None
+        warnings = None
         form = forms.BookForm(request.POST)
         if form.is_valid():
             print 'Saving whole text.', request.user.username
-            def save_action():
-                print 'In branch: ' + repo.repo[None].branch()
-                repo._add_file(path, form.cleaned_data['content'])                
-                repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'),\
-                     user=request.user.username)
             try:
-                # wczytaj dokument z ciągu znaków -> weryfikacja
-                document = parser.WLDocument.from_string(form.cleaned_data['content'])
+                # encode it back to UTF-8, so we can put it into repo
+                encoded_data = form.cleaned_data['content'].encode('utf-8')
+
+                def save_action():                    
+                    repo._add_file(path, encoded_data)
+                    repo._commit(message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'),\
+                         user=request.user.username)
+
+                try:
+                    # wczytaj dokument z ciągu znaków -> weryfikacja
+                    document = parser.WLDocument.from_string(form.cleaned_data['content'])
+                except (ParseError, ValidationError), e:
+                    warnings = [u'Niepoprawny dokument XML: ' + unicode(e.message)]
 
                 #  save to user's branch
                 repo.in_branch(save_action, models.user_branch(request.user) );
-            except (ParseError, ValidationError), e:
-                errors = [e.message]              
+            except UnicodeDecodeError, e:
+                errors = [u'Błąd kodowania danych przed zapisem: ' + unicode(e.message)]
+            except RepositoryException, e:
+                errors = [u'Błąd repozytorium: ' + unicode(e.message)]            
 
         if not errors:
             errors = dict( (field[0], field[1].as_text()) for field in form.errors.iteritems() )
 
-        return HttpResponse(json.dumps({'result': errors and 'error' or 'ok', 'errors': errors}));
+        return HttpResponse( json.dumps({'result': errors and 'error' or 'ok',
+            'errors': errors, 'warnings': warnings}) );
 
     form = forms.BookForm()
     data = repo.get_file(path, models.user_branch(request.user))
 
         var params = $.evalJSON(button.attr('ui:action-params'));
 
         var callback = function() {
-           editor.callScriptlet(button.attr('ui:action'), self, params);
+            editor.callScriptlet(button.attr('ui:action'), self, params);
         };
 
         // connect button
         'commit_message': msg
     })
 
+    self.showPopup('save-waiting', '', -1);
+
     $.ajax({
         url: saveInfo.url,
         dataType: 'json',
         success: function(data, textStatus) {
-            if (data.result != 'ok')
-                self.showPopup('save-error', data.errors[0]);
+            if (data.result != 'ok') {
+                self.showPopup('save-error', (data.errors && data.errors[0]) || 'Nieznany błąd X_X.');
+            }
             else {
                 self.refreshPanels(changed_panel);
                 $('#toolbar-button-save').attr('disabled', 'disabled');
                 if(self.autosaveTimer)
                     clearTimeout(self.autosaveTimer);
 
-                self.showPopup('save-successful');
+                if (data.warnings == null)
+                    self.showPopup('save-successful');
+                else
+                    self.showPopup('save-warn', data.warnings[0]);
             }
+            
+            self.advancePopupQueue();
         },
         error: function(rq, tstat, err) {
-            self.showPopup('save-error');
+            self.showPopup('save-error', '- bład wewnętrzny serwera.');
+            self.advancePopupQueue();
         },
         type: 'POST',
         data: postData
        }); */
 }
 
-Editor.prototype.showPopup = function(name, text) 
+Editor.prototype.showPopup = function(name, text, timeout)
 {
+    timeout = timeout || 4000;
     var self = this;
-    self.popupQueue.push( [name, text] )
+    self.popupQueue.push( [name, text, timeout] )
 
     if( self.popupQueue.length > 1) 
         return;
     $('*.data', box).html(text);
     box.fadeIn();
  
-    self._nextPopup = function() {
-        var elem = self.popupQueue.pop()
-        if(elem) {
-            var box = $('#message-box > #' + elem[0]);
+    if(timeout > 0)
+        setTimeout( $.fbind(self, self.advancePopupQueue), timeout);
+};
 
-            box.fadeOut(300, function() {
-                $('*.data', box).html();
-    
-                if( self.popupQueue.length > 0) {
-                    box = $('#message-box > #' + self.popupQueue[0][0]);
-                    $('*.data', box).html(self.popupQueue[0][1]);
-                    box.fadeIn();
-                    setTimeout(self._nextPopup, 5000);
-                }
-            });
-        }
+Editor.prototype.advancePopupQueue = function() {
+    var self = this;
+    var elem = this.popupQueue.shift();
+    if(elem) {
+        var box = $('#message-box > #' + elem[0]);
+
+        box.fadeOut(200, function()
+        {
+            $('*.data', box).html();
+
+            if( self.popupQueue.length > 0) {
+                var ibox = $('#message-box > #' + self.popupQueue[0][0]);
+                $('*.data', ibox).html(self.popupQueue[0][1]);
+                ibox.fadeIn();
+                if(self.popupQueue[0][2] > 0)
+                    setTimeout( $.fbind(self, self.advancePopupQueue), self.popupQueue[0][2]);
+            }
+        });
     }
+};
 
-    setTimeout(self._nextPopup, 5000);
-}
 
 Editor.prototype.registerScriptlet = function(scriptlet_id, scriptlet_func)
 {
   
 $(function() {
     $.fbind = function (self, func) {
-        return function() { return func.apply(self, arguments); };
+        return function() { 
+            return func.apply(self, arguments);
+        };
     };
     
     editor = new Editor();