Index: /trunk/roundcubemail/CHANGELOG
===================================================================
--- /trunk/roundcubemail/CHANGELOG	(revision 3845)
+++ /trunk/roundcubemail/CHANGELOG	(revision 3846)
@@ -2,4 +2,5 @@
 ===========================
 
+- Fix JS errors on compose mode switch (#1486870)
 - Fix message structure parsing when it lacks optional fields (#1486881)
 - Include all recipients in sendmail log
Index: /trunk/roundcubemail/program/js/app.js
===================================================================
--- /trunk/roundcubemail/program/js/app.js	(revision 3845)
+++ /trunk/roundcubemail/program/js/app.js	(revision 3846)
@@ -2816,11 +2816,12 @@
     }
     else {
-      var thisMCE = tinyMCE.get(props.id),
-        existingHtml = thisMCE.getContent();
-
-      if (existingHtml) {
+      var thisMCE = tinyMCE.get(props.id), existingHtml;
+      if (thisMCE.plugins.spellchecker && thisMCE.plugins.spellchecker.active)
+        thisMCE.execCommand('mceSpellCheck', false);
+      
+      if (existingHtml = thisMCE.getContent()) {
         if (!confirm(this.get_label('editorwarning'))) {
           return false;
-	    }
+        }
         this.html2plain(existingHtml, props.id);
       }
Index: /trunk/roundcubemail/program/js/editor.js
===================================================================
--- /trunk/roundcubemail/program/js/editor.js	(revision 3845)
+++ /trunk/roundcubemail/program/js/editor.js	(revision 3846)
@@ -68,17 +68,10 @@
   if (elem && elem.type=='select-one')
     rcmail.change_identity(elem);
-  // set tabIndex
-  rcmail_editor_tabindex();
-  // set focus to element that was focused before
-  if (elem = rcmail.env.compose_focus_elem) {
-    if (elem.id == rcmail.env.composebody && (editor = tinyMCE.get(rcmail.env.composebody)))
-      editor.getWin().focus();
-    else
-      elem.focus();
-  }
+  // set tabIndex and set focus to element that was focused before
+  rcmail_editor_tabindex(rcmail.env.compose_focus_elem && rcmail.env.compose_focus_elem.id == rcmail.env.composebody);
 }
 
 // set tabIndex on tinyMCE editor
-function rcmail_editor_tabindex()
+function rcmail_editor_tabindex(focus)
 {
   if (rcmail.env.task == 'mail') {
@@ -89,4 +82,6 @@
       if (textarea && node)
         node.tabIndex = textarea.tabIndex;
+      if (focus)
+        editor.getWin().focus();
     }
   }
@@ -107,5 +102,5 @@
   if (ishtml) {
     // #1486593
-    setTimeout("rcmail_editor_tabindex();", 500);
+    setTimeout("rcmail_editor_tabindex(true);", 500);
     if (flagElement && (flag = rcube_find_object(flagElement)))
       flag.value = '1';
@@ -113,7 +108,9 @@
   else {
     if (!res && select.tagName == 'SELECT')
-	  select.value = 'html';
+      select.value = 'html';
     if (flagElement && (flag = rcube_find_object(flagElement)))
       flag.value = '0';
+
+    rcube_find_object(rcmail.env.composebody).focus();
   }
 }
Index: /trunk/roundcubemail/skins/default/googiespell.css
===================================================================
--- /trunk/roundcubemail/skins/default/googiespell.css	(revision 3845)
+++ /trunk/roundcubemail/skins/default/googiespell.css	(revision 3846)
@@ -18,4 +18,5 @@
   font-size: 9pt;
   font-family: monospace;
+  border: 1px solid #666;
 }
 
