--- C:\www\home\spellclient.int\www\CKEditor.3.1.x\_source\plugins\scayt\plugin.js	Wed Dec 16 13:28:28 2009 UTC
+++ C:\www\home\spellclient.int\www\CKEditor\_source\plugins\scayt\plugin.js	Wed Dec 16 13:17:10 2009 UTC
@@ -12,6 +12,20 @@
 {
 	var commandName 	= 'scaytcheck',
 		openPage		= '';
+	// Checks if a value exists in an array
+	function in_array(needle, haystack)
+    {
+	    var found = false, key;
+	    for (key in haystack)
+        {
+	        if ((haystack[key] === needle) || ( haystack[key] == needle))
+            {
+	            found = true;
+	            break;
+	        }
+	    }
+	    return found;
+	}
 
 	var onEngineLoad = function()
 	{
@@ -24,11 +38,10 @@
 			oParams.srcNodeRef = editor.document.getWindow().$.frameElement; 		// Get the iframe.
 			// syntax : AppName.AppVersion@AppRevision
 			oParams.assocApp  = "CKEDITOR." + CKEDITOR.version + "@" + CKEDITOR.revision;
-
-			oParams.customerid = editor.config.scayt_customerid  || "1:11111111111111111111111111111111111111";
-			oParams.customDictionaryName = editor.config.scayt_customDictionaryName;
+			oParams.customerid = editor.config.scayt_customerid  || "";
+			oParams.customDictionaryIds = editor.config.scayt_customDictionaryIds;
 			oParams.userDictionaryName = editor.config.scayt_userDictionaryName;
-			oParams.defLang = editor.scayt_defLang;
+			oParams.sLang = editor.config.scayt_sLang || "en_US";
 
 			if ( CKEDITOR._scaytParams )
 			{
@@ -51,8 +64,18 @@
 
 			plugin.instances[ editor.name ] = scayt_control;
 
+			//window.scayt.uiTags
+			var menuGroup = 'scaytButton';
+			var uiTabs = window.scayt.uiTags;
+			var fTabs  = [];
+			
+			for (var i = 0,l=4; i<l; i++)
+				fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
+			
+			plugin.uiTabs = fTabs;
+			
 			try {
-				scayt_control.setDisabled( scayt_control.paused === false );				// I really don't know why it causes JS error in IE
+				scayt_control.setDisabled( scayt_control.paused === false );
 			} catch (e) {}
 			editor.fire( 'showScaytState' );
 		};
@@ -90,6 +113,11 @@
 				}
 			});
 
+
+		editor.on( 'destroy', function()
+        {
+            plugin.getScayt( editor ).destroy();
+        });
 		// Listen to data manipulation to reflect scayt markup.
 		editor.on( 'afterSetData', function()
 			{
@@ -116,6 +144,27 @@
 				}
 			}, this, null, 50 );
 
+        editor.on( 'insertHtml', function()
+        {
+            
+            var scayt_instance = plugin.getScayt( editor );
+            if ( plugin.isScaytEnabled( editor ) )
+            {
+                // Unlock the selection before reload, SCAYT will take
+                // care selection update.
+                if ( CKEDITOR.env.ie )
+                    editor.getSelection().unlock( true );
+
+                // Swallow any SCAYT engine errors.
+                try{
+                    scayt_instance.refresh();
+                }catch( er )
+                {}
+            }
+        }, this, null, 50 );
+
+
+
 		editor.on( 'scaytDialog', function( ev )	// Communication with dialog.
 			{
 				ev.data.djConfig = window.djConfig;
@@ -300,19 +349,33 @@
 
 			// Add Options dialog.
 			CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
+			// read ui tags
+			var confuiTabs = editor.config.scayt_uiTabs || "1,1,1";
+			var uiTabs =[];
+			// string tp array convert
+			confuiTabs = confuiTabs.split(",");
+			// check array length ! allwaays must be 3 filled with 1 or 0
+			for (var i=0,l=3; i<l; i++){
+				var flag = parseInt(confuiTabs[i] || "1" ,10);
+				uiTabs.push(  flag  );
+			}
+			
 
 			var menuGroup = 'scaytButton';
 			editor.addMenuGroup( menuGroup );
-			editor.addMenuItems(
-				{
-					scaytToggle :
+			// combine menu items to render 
+			var uiMuneItems = {};
+			
+			// allways added
+			uiMuneItems.scaytToggle =
 					{
 						label : editor.lang.scayt.enable,
 						command : commandName,
 						group : menuGroup
-					},
+				};
 
-					scaytOptions :
+			if (uiTabs[0] == 1)
+				uiMuneItems.scaytOptions =
 					{
 						label : editor.lang.scayt.options,
 						group : menuGroup,
@@ -321,9 +384,10 @@
 							openPage = 'options';
 							editor.openDialog( commandName );
 						}
-					},
+				};
 
-					scaytLangs :
+			if (uiTabs[1] == 1)
+				uiMuneItems.scaytLangs =
 					{
 						label : editor.lang.scayt.langs,
 						group : menuGroup,
@@ -332,9 +396,20 @@
 							openPage = 'langs';
 							editor.openDialog( commandName );
 						}
-					},
-
-					scaytAbout :
+				};
+			if (uiTabs[2] == 1)
+				uiMuneItems.scaytDict =
+				{
+					label : editor.lang.scayt.dictionariesTab,
+					group : menuGroup,
+					onClick : function()
+					{
+						openPage = 'dictionaries';
+						editor.openDialog( commandName );
+					}
+				};
+			// allways added
+			uiMuneItems.scaytAbout =
 					{
 						label : editor.lang.scayt.about,
 						group : menuGroup,
@@ -344,7 +419,12 @@
 							editor.openDialog( commandName );
 						}
 					}
-				});
+			;
+			
+			uiTabs[3] = 1; // about us tab is allways on
+			plugin.uiTabs = uiTabs;
+			
+			editor.addMenuItems( uiMuneItems );
 
 				editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
 					{
@@ -358,6 +438,7 @@
 								this.setState( command.state );
 							},
 							this);
+							
 					},
 					onMenu : function()
 					{
@@ -367,9 +448,10 @@
 
 							return {
 								scaytToggle : CKEDITOR.TRISTATE_OFF,
-								scaytOptions : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
-								scaytLangs : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
-								scaytAbout : isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
+									scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
+									scaytLangs   : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
+									scaytDict    : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
+									scaytAbout   : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
 							};
 						}
 					});
@@ -379,6 +461,7 @@
 			{
 				editor.contextMenu.addListener( function( element )
 					{
+						
 						if ( !( plugin.isScaytEnabled( editor ) && element ) )
 							return null;
 
@@ -394,6 +477,7 @@
 						if (!items_suggestion || !items_suggestion.length )
 							return null;
 						// Remove unused commands and menuitems
+
 						for ( i in moreSuggestions )
 						{
 							delete editor._.menuItems[ i ];
@@ -407,7 +491,13 @@
 						moreSuggestions = {};		// Reset items.
 						mainSuggestions = {};
 
-						var moreSuggestionsUnable = false;
+						var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || "on";
+						var moreSuggestionsUnableAdded = false;
+						var maxSuggestions = ( editor.config.scayt_maxSuggestions <= 0)
+											  ? items_suggestion.length 
+											  : editor.config.scayt_maxSuggestions;
+						var contextCommands = editor.config.scayt_contextCommands || "all";
+						contextCommands = contextCommands.split("|");
 
 						for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
 						{
@@ -422,22 +512,28 @@
 									};
 								})( element.$, items_suggestion[i] );
 
-							if ( i < editor.config.scayt_maxSuggestions )
+							if ( i < maxSuggestions )
 							{
 								addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
 									commandName, exec, 'scayt_suggest', i + 1 );
 								_r[ commandName ] = CKEDITOR.TRISTATE_OFF;
 								mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
 							}
-							else
+							else if ( moreSuggestionsUnable == "on" )
 							{
+
 								addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
 									commandName, exec, 'scayt_moresuggest', i + 1 );
 								moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
-								moreSuggestionsUnable = true;
+								moreSuggestionsUnableAdded = true;
+
+
+
+
 							}
 						}
-						if ( moreSuggestionsUnable )
+
+						if ( moreSuggestionsUnableAdded ){
 							// Rgister the More suggestions group;
 							editor.addMenuItem( 'scayt_moresuggest',
 								{
@@ -449,41 +545,44 @@
 										return moreSuggestions;
 									}
 								});
+                            mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
 
+						}
 
-						var ignore_command =
-						{
-							exec: function()
+
+						
+						if ( in_array( "all",contextCommands )  || in_array("ignore",contextCommands)  )
 							{
+							var ignore_command = {
+								exec: function(){
 								scayt_control.ignore( element.$ );
 							}
 						};
-						var ignore_all_command =
-						{
-							exec: function()
+							addButtonCommand(editor, 'ignore', editor.lang.scayt.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1);
+							mainSuggestions['scayt_ignore'] = CKEDITOR.TRISTATE_OFF;
+						}
+						
+						if ( in_array( "all",contextCommands )  || in_array("ignoreall",contextCommands)  )
 							{
+							var ignore_all_command = {
+								exec: function(){
 								scayt_control.ignoreAll( element.$ );
 							}
 						};
-						var addword_command =
-						{
-							exec: function()
+							addButtonCommand(editor, 'ignore_all', editor.lang.scayt.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
+							mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;
+						}
+						
+						if ( in_array( "all",contextCommands )  || in_array("add",contextCommands)  )
 							{
+							var addword_command = {
+								exec: function(){
 								window.scayt.addWordToUserDictionary( element.$ );
 							}
 						};
-
-						addButtonCommand( editor, 'ignore', editor.lang.scayt.ignore,
-							'scayt_ignore', ignore_command, 'scayt_control', 1);
-						addButtonCommand( editor, 'ignore_all', editor.lang.scayt.ignoreAll,
-							'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
-						addButtonCommand( editor, 'add_word', editor.lang.scayt.addWord,
-							'scayt_add_word', addword_command, 'scayt_control', 3);
-
-						mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
-						mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
-						mainSuggestions[ 'scayt_ignore_all' ] = CKEDITOR.TRISTATE_OFF;
+							addButtonCommand(editor, 'add_word', editor.lang.scayt.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
 						mainSuggestions[ 'scayt_add_word' ] = CKEDITOR.TRISTATE_OFF;
+						}
 
 						if ( scayt_control.fireOnContextMenu )
 							scayt_control.fireOnContextMenu( editor );
@@ -507,6 +606,5 @@
 		}
 	});
 })();
-
-CKEDITOR.config.scayt_maxSuggestions =  5;
-CKEDITOR.config.scayt_autoStartup = false;
+CKEDITOR.config.scayt_maxSuggestions =  CKEDITOR.config.scayt_maxSuggestions || 5;
+CKEDITOR.config.scayt_autoStartup = (typeof CKEDITOR.config.scayt_autoStartup !== 'undefined') ? CKEDITOR.config.scayt_autoStartup : false;
