var __aspxActiveSpellChecker = null;
var __aspxSCFormPostFix = ":SCFPR:";
var __aspxSCOptionsPrefix = "Options:";
var __aspxSCErrorMarker = "^^^DXError^^^";
ASPxClientSpellChecker = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.callbackError = false;
  this.checkingText = null;
  this.anchorElement = null;
  this.editorElement = null;
  this.checkedContainer = null;
  this.checkedText = ""; 
  this.editorHelper = new ASPxEditorHelper();
  this.containerBrowser  = new ASPxContainerBrowser();
  this.formHandler = null;
  this.spellCheckForm = null;
  this.optionsForm = null;
  this.isOptionsForm = false;
  this.preventHideEvents = false;
  this.checkedElementID = "";
  this.showOneWordInTextPreview = false;
  this.BeforeCheck = new ASPxClientEvent();
  this.CheckCompleteFormShowing = new ASPxClientEvent();
  this.AfterCheck = new ASPxClientEvent();
  this.WordChanged = new ASPxClientEvent();
 },
 Check: function() {  
  this.CheckElementById(this.checkedElementID);
 },
 CheckElement: function(element) { 
  if(!_aspxIsExists(element)) return;
  var inputElement = this.FindDxEditorInputElement(element);
  if (inputElement != null)
   element = inputElement;
  if(this.CanCheckControl(element.id))
   this.CheckElementCore(element);
  else
   this.ContinueOrFinishCheck(element);
 },
 CheckElementById: function(id) {
  var element = this.FindDxEditorInputElementById(id);
  if(!_aspxIsExists(element))
   element = _aspxGetElementById(id);
  this.CheckElement(element);
 },
 CheckElementsInContainer: function(containerElement) {
  if(_aspxIsExists(containerElement)) {
   this.checkedContainer = containerElement;
   var editor = this.FindNextEditorInContainer(containerElement, null);
   if(_aspxIsExists(editor))
    this.CheckElement(editor);
   else
    this.ShowFinishMessageBox();
  }  
 },
 CheckElementsInContainerById: function(containerId) {
  var container = _aspxGetElementById(containerId);
  this.CheckElementsInContainer(container);
 },
 CheckText: function(text, anchorElement) { 
  this.CheckCore(text, anchorElement, null, null);
 }, 
 FindDxEditorInputElement: function(obj) {
  if(ASPxIdent.IsASPxClientEdit(obj))
   return obj.GetInputElement();
  else if(_aspxIsExistsElement(obj) && _aspxIsExists(obj.id))
   return _aspxGetChildById(obj, obj.id + "_I"); 
  return null;
 },
 FindDxEditorInputElementById: function(id) {
  var control = aspxGetControlCollection().Get(id);
  if(control != null && ASPxIdent.IsASPxClientEdit(control))
   return control.GetInputElement();
  return null;
 }, 
 GetEditorID: function(element) {
  var id = "";
  if (_aspxIsExists(element)) {
   var editor = this.editorHelper.GetDXEditorByInput(element);
   id = editor ? editor.name : element.id;
  }
  return id; 
 }, 
 GetDialogPopupControl: function(name) {
  return aspxGetControlCollection().Get(this.name + "_" + name);
 },
 GetOptionsHiddenField: function() {
  return document.getElementById(this.name + "_SettingsHiddenField");
 },  
 GetSpellCheckForm: function() {
  if(!this.spellCheckForm)
   this.spellCheckForm = new SpellCheckForm("SpellCheckForm", this);
  return this.spellCheckForm;
 },
 GetOptionsForm: function() {
  if(!this.optionsForm)
   this.optionsForm = new SpellCheckOptionsForm("SpellCheckOptionsForm", this);
  return this.optionsForm;
 }, 
 SetOptionsHiddenField: function(callbackResult) {
  if(callbackResult.indexOf(__aspxSCOptionsPrefix) == 0) {
   var i = callbackResult.indexOf(";");
   this.GetOptionsHiddenField().value = callbackResult.slice(8, i); 
   return callbackResult.slice(i +  1);
  }
  return callbackResult;
 },
 CanCheckControl: function(id) {
  return this.RaiseBeforeCheck(id);
 },   
 ContinueCheckContainer: function(nextEditor) {
  if (_aspxIsExists(this.editorElement))
   this.RaiseAfterCheck(this.GetEditorID(this.editorElement), this.checkingText);
  this.checkedText = null;
  this.CheckElement(nextEditor);
 },
 ContinueOrFinishCheck: function(currentElement) {
  if(_aspxIsExists(this.checkedContainer)){  
   var editor = this.FindNextEditorInContainer(this.checkedContainer, currentElement);
   if(_aspxIsExists(editor)){
    this.ContinueCheckContainer(editor);
    return;
   }
   else 
    this.RaiseAfterCheck(this.GetEditorID(currentElement), this.checkingText);
  }
  var spellCheckForm = this.GetSpellCheckForm();
  if(spellCheckForm.IsVisible() != null)
   spellCheckForm.GetDialogPopup().Hide();
  this.ShowFinishMessageBox();
  __aspxActiveSpellChecker = null;
 },
 CheckElementCore: function(element) { 
  if (ASPxEditorHelper.IsEditableEditNode(element))
   this.CheckCore(element.value, element, element, null);
  else
   this.ContinueOrFinishCheck(element);
 },
 CheckByCallbackResult: function(text, result, anchorElement) {  
  this.CheckCore(text, anchorElement, null, result);
 }, 
 CheckCore: function(text, anchorElement, editorElement, callResult) { 
  __aspxActiveSpellChecker = this;
  this.checkingText = text;
  this.anchorElement = _aspxIsExists(anchorElement) ? anchorElement : document.body;
  this.editorElement = editorElement;
  __aspxCurrentControlNameInDialog = this.name;
  if(this.formHandler == null)
   this.formHandler = new ASPxSpellCheckerFormHandler(this);  
  if(callResult != null)
   this.OnCallback(callResult);
  else if(text != "")
   this.SendCallback(this.CreateCallbackArgumentToCheckText(text));
  else 
   this.ContinueOrFinishCheck(this.editorElement);
 }, 
 ReCheck: function(text) {
  var callbackParam = this.CreateCallbackArgumentToCheckText(text);
  this.checkingText = text;
  this.SendCallback(callbackParam);
 },
 CreateCallbackArgumentToCheckText: function(text) {
  var argument = "Check(" + text.length + "):" + text;
  if(!this.IsDialogContentAvailable(this.GetSpellCheckForm().name))
   argument = argument.concat(":", this.CreateCallbackArgumentToGetSpellCheckFormContent());
  var options = this.CreateCallbackArgumentToSaveOptions();
  if(options != "")
   argument = argument.concat(":", options);
  return argument;
 },
 CreateCallbackArgumentToGetSpellCheckFormContent: function() {
  return "DialogForm:SpellCheckForm"; 
 },
 CreateCallbackArgumentToGetSpellCheckOptionsFormContent: function() {
  return "DialogForm:SpellCheckOptionsForm"; 
 },
 CreateCallbackArgumentToSaveOptions: function() {
  var mask = this.GetOptionsHiddenField().value;
  if(mask && mask != "")
   return "Options:" + mask;
  return "";
 },
 CreateCallbackArgumentToAddWord: function(word) {
  return "Word(" + word.length + "):" + word;
 },
 ShowFinishMessageBox: function() {
  var needShowAlert = this.formHandler == null || !this.formHandler.HasErrors();
  if(!needShowAlert)
   return;
  needShowAlert = this.RaiseCheckCompleteFormShowing();
  if(needShowAlert)
   alert(this.finishSpellChecking); 
 },
 IsDialogContentAvailable: function(name) {
  return this.dialogContentHashTable[name] != null;
 },
 HideDialog: function(result) { 
  if(this.preventHideEvents) return;
  var optionsForm = this.GetOptionsForm();
  if(optionsForm.IsVisible())
   this.OnFinishOptionsEditing(result);
  else
   this.OnFinishSpellChecking(result);
 },
 ShowOptionsForm: function(dialogContent) {
  this.isOptionsForm = true;
  if(this.formHandler != null)
   this.formHandler.ClearErrorSelection();
  var dialog = this.GetOptionsForm();
  if(!this.IsDialogContentAvailable(dialog.name)  && !dialogContent)
   this.SendCallback(this.CreateCallbackArgumentToGetSpellCheckOptionsFormContent());
  else
   this.ShowOptionsFormCore(dialogContent);
 },
 ShowOptionsFormCore: function(dialogContent) { 
  var dialog = this.GetOptionsForm();
  var spellCheckForm = this.GetSpellCheckForm();
  var popupElement = this.anchorElement;
  if(spellCheckForm.IsVisible())
   popupElement = spellCheckForm.GetDialogPopup().GetWindowContentElement(-1);
  dialog.Show(popupElement);  
  dialog.GetDialogPopup().SetPopupElementInternal(-1, popupElement);
  if(dialogContent)
   dialog.SetDialogContent(dialogContent);
 },
 ShowLoadingPanel: function() {
  var offsetElement = null;
  var spellCheckForm = this.GetSpellCheckForm();
  if(spellCheckForm.IsVisible())
   spellCheckForm.ShowLoadingPanelOverDialogPopup();
  else {
   offsetElement = this.checkedContainer ? this.checkedContainer : this.anchorElement;
   this.ShowLoadingPanelCore(document.body, offsetElement);   
  }
 },
 HideLoadingPanelCore: function() {
  var spellCheckForm = this.GetSpellCheckForm(); 
  if(spellCheckForm.IsVisible())
   spellCheckForm.HideLoadingPanelOverDialogPopup();
 },
 ShowLoadingPanelCore: function(parentElement, offsetElement) { 
  this.CreateLoadingPanelWithAbsolutePosition(parentElement, offsetElement);  
 },
 SendCallback: function(argument) {
  this.BeforeSendCallback();
  this.CreateCallback(argument);   
 },
 OnCallback: function(result) {
  this.HideLoadingPanelCore();
  this.ProcessCallbackResult(result);
 },
 ProcessCallbackResult: function(resultObj) {
  if (_aspxIsExists(resultObj.options))
   this.GetOptionsHiddenField().value = resultObj.options;
  if(!this.isOptionsForm) {    
   var errorCount = _aspxIsExists(resultObj.errorCount) ? resultObj.errorCount : 0;   
   if(errorCount > 0) {
    this.formHandler.Initialize(errorCount, resultObj.startErrorWordPositionArray,
           resultObj.wrongWordLengthArray, resultObj.suggestionsArray);
    this.GetSpellCheckForm().Show(this.anchorElement);
    if(_aspxIsExists(resultObj.dialogContent))
     this.GetSpellCheckForm().SetDialogContent(resultObj.dialogContent);
   }
   else
    if(!_aspxIsExists(this.checkedContainer))
     this.OnFinishSpellChecking(false);
  }
  else
   this.ShowOptionsForm(resultObj.dialogContent);
 },
 DoEndCallback: function() {
  this.constructor.prototype.DoEndCallback.call(this);  
  if(this.callbackError){
   this.callbackError = false;
   return;
  }
  if(!this.isOptionsForm) {
   if(this.formHandler.errorCount > 0) {
    this.GetSpellCheckForm().OnEndCallback();
    this.formHandler.ShowSpellCheckerForm();
   } else if(_aspxIsExists(this.checkedContainer)) {
       var editor = this.FindNextEditorInContainer(this.checkedContainer, this.editorElement);
       if(_aspxIsExists(editor))
        this.ContinueCheckContainer(editor);
       else {
        this.OnFinishSpellChecking(false);
        this.ShowFinishMessageBox();
       }
    }
    else
     this.ShowFinishMessageBox();
  }
  else
   this.InitializeOptionsDialogFields();   
 },
 OnCallbackError: function(result, data){
  this.callbackError = true;
  this.constructor.prototype.OnCallbackError.call(this, result, data);
 },
 BeforeSendCallback: function() { 
  if(_aspxIsExists(this.formHandler)) {
   this.formHandler.ClearErrorSelection();
   this.formHandler.ClearListBoxItems();
  }
  this.ShowLoadingPanel();
 },
 AddToDictionary: function() {
  this.formHandler.AddToDictionaryClick();
 },
 AddWord: function(word) {
  this.formHandler.ClearErrorSelection();
  var text = this.checkedText;
  var callbackParam = this.CreateCallbackArgumentToCheckText(text);
  callbackParam = callbackParam.concat(":", this.CreateCallbackArgumentToAddWord(word));
  this.checkingText = text;  
  this.SendCallback(callbackParam);
 }, 
 Change: function() {
  this.formHandler.ChangeClick();  
 },
 ChangeAll: function() {
  this.formHandler.ChangeAllClick();
 },
 Ignore: function() {
  this.formHandler.IgnoreClick();
 }, 
 IgnoreAll: function() { 
  this.formHandler.IgnoreAllClick();
 }, 
 Cancel: function() {
  this.formHandler.Cancel();
 },
 ListBoxItemChanged: function(listBox, e) {
  this.formHandler.ListBoxItemChanged(listBox);
 }, 
 TextBoxKeyPress: function(evt) {
  this.formHandler.TextBoxKeyPress(_aspxGetKeyCode(evt));
 }, 
 TextBoxKeyDown: function(evt) {
  this.formHandler.TextBoxKeyDown(_aspxGetKeyCode(evt));
 },
 SCListBoxItemDoubleClick: function() {
  this.formHandler.SCListBoxItemDoubleClick();
 },
 OnWordChanged: function() {
  if(_aspxIsExists(this.editorElement))
   this.editorHelper.SetText(this.editorElement, this.checkedText);
  this.RaiseWordChanged(this.GetEditorID(this.editorElement), this.checkedText);
 },
 OnFinishSpellCheckingCore: function(change) {
  var checkedText = this.checkingText;
  this.formHandler.ClearErrorSelection();
  if(change) {
   checkedText = this.checkedText;
   if(_aspxIsExists(this.editorElement))
    this.editorHelper.SetText(this.editorElement, checkedText);    
  }
  this.formHandler.ClearInternalFields();
  this.RaiseAfterCheck(this.GetEditorID(this.editorElement), checkedText);
  this.checkingText = null;
  this.anchorElement = null;
  this.editorElement = null;
  this.checkedText = null;
 },
 OnFinishSpellChecking: function(change) {
  this.preventHideEvents = true;
  if(change && _aspxIsExists(this.checkedContainer)){
   var editor = this.FindNextEditorInContainer(this.checkedContainer, this.editorElement);
   if(_aspxIsExists(editor)){
    this.OnFinishSpellCheckingCore(change);
    this.ContinueCheckContainer(editor);
    this.preventHideEvents = false;
    return;
   }
  }
  var spellCheckForm = this.GetSpellCheckForm();
  if(spellCheckForm.IsVisible() != null)
   spellCheckForm.GetDialogPopup().Hide();
  this.OnFinishSpellCheckingCore(change);
  if(change) 
   this.ShowFinishMessageBox();
  __aspxActiveSpellChecker = null;
  this.preventHideEvents = false;
 }, 
 OnFinishOptionsEditing: function(change) {
  this.preventHideEvents = true;
  var optionsForm = this.GetOptionsForm();
  if(optionsForm.IsVisible() != null)
   optionsForm.GetDialogPopup().Hide();
  this.isOptionsForm = false;
  if(change) {
   this.GetOptionsHiddenField().value = this.CreateSettingsMask();
   this.ReCheck(this.checkedText);
  }
  else {  
   this.formHandler.SelectError(this.formHandler.currentError);
   this.formHandler.PrepareFormControlsByError(this.formHandler.currentError);
   this.InitializeOptionsDialogFields();
    }
    this.preventHideEvents = false;
 },
 FindNextEditorInContainer: function(container, currentEditor) {
  var editor = this.containerBrowser.FindNextEditor(container, currentEditor);
  if(_aspxIsExists(editor) && _aspxIsExists(editor.id) && editor.id.indexOf(this.name + "_") == 0)
   editor = null;
  return editor;
 },
 CreateSettingsMask: function() {
  var mask = "";  
  mask += this.MapEditorValueToString(chkbUpperCase);
  mask += this.MapEditorValueToString(chkbMixedCase);
  mask += this.MapEditorValueToString(chkbNumbers);
  mask += this.MapEditorValueToString(chkbEmails);
  mask += this.MapEditorValueToString(chkbUrls);
  mask += this.MapEditorValueToString(chkbTags);
  mask = mask.concat(comboLanguage.GetValue()); 
  return mask;
 },
 MapEditorValueToString: function(editor) {
  return editor.GetChecked() ? "1" : "0";
 },
 InitializeOptionsDialogFields: function() {
  this.ParseSettingsMask(this.GetOptionsHiddenField().value);
 },
 ParseSettingsMask: function(mask) {
  if(!mask || mask == "")
   return;
  chkbUpperCase.SetChecked(mask.charAt(0) == "1"); 
  chkbMixedCase.SetChecked(mask.charAt(1) == "1"); 
  chkbNumbers.SetChecked(mask.charAt(2) == "1"); 
  chkbEmails.SetChecked(mask.charAt(3) == "1"); 
  chkbUrls.SetChecked(mask.charAt(4) == "1");
  chkbTags.SetChecked(mask.charAt(5) == "1");
  comboLanguage.SetValue(mask.slice(6)); 
 }
});
ASPxSpellCheckerFormHandler = _aspxCreateClass(null, {
 constructor: function(spellChecker) {
  this.spellChecker = spellChecker;
  this.scForm = spellChecker.GetSpellCheckForm();
  this.errorCount = -1;
  this.errors = [];
  this.currentError = null;
  this.ignoreAllList = [];
  this.changeAllList = new Object();
  this.delta = 0;
  this.checkedTextFakeElement = null;
  this.previewTextElement = null;
  this.sampleErrorElement = null;
 },
 ClearInternalFields: function() {
  this.errorCount = -1;
  this.errors = [];
  this.currentError = null;
 },
 Initialize: function(errorCount, startErrorWordPositionArray, wrongWordLengthArray, suggestionsArray) {
  this.ClearInternalFields();
  this.wrongWordLengthArray = wrongWordLengthArray;
  this.startErrorWordPositionArray = startErrorWordPositionArray;
  this.suggestionsArray = suggestionsArray;
  this.errorCount = errorCount;
 },
 InitializeErrorArray: function() {
  _aspxArrayClear(this.errors);
  for (var i =0; i < this.errorCount; i++) {
   var error = {};
   error.wordStart = this.startErrorWordPositionArray[i];
   error.wordLength = this.wrongWordLengthArray[i];
   error.suggestions = this.suggestionsArray[i];
   error.suggestionCount = this.suggestionsArray[i].length;    
   error.word = this.GetWordByError(error);
   this.AddErrorToErrorsList(error);
  }
 },
 AddErrorToErrorsList: function(error) {
  if(this.currentError == null)
   this.errors.push(error);
  else {
   if(error.wordStart > this.currentError.wordStart)
    this.errors.push(error);
   else
    this.errorCount --;
  }
 },
 GetSCForm: function() {
  return this.scForm;
 },
 GetSCFormListBox: function (form) {
  if(_aspxIsExistsType(typeof(_dxeSCSuggestionsListBox)) && _aspxIsExists(_dxeSCSuggestionsListBox) && _aspxIsExistsElement(_dxeSCSuggestionsListBox.GetMainElement()))
   return _dxeSCSuggestionsListBox;
  return null;
 }, 
 GetSCFormChangeButton: function(form) { 
  if(_aspxIsExistsType(typeof(_dxeSCBtnChange)) && _aspxIsExists(_dxeSCBtnChange) && _aspxIsExistsElement(_dxeSCBtnChange.GetMainElement()))
   return _dxeSCBtnChange;
  return null;
 },
 GetSCFormChangeAllButton: function(form) {
  if(_aspxIsExistsType(typeof(_dxeSCBtnChangeAll)) && _aspxIsExists(_dxeSCBtnChangeAll) && _aspxIsExistsElement(_dxeSCBtnChangeAll.GetMainElement()))
   return _dxeSCBtnChangeAll;
  return null;
 },
 GetSCFormChangeTextBox: function() { 
  if(_aspxIsExistsType(typeof(_dxeSCTxtChangeTo)) && _aspxIsExists(_dxeSCTxtChangeTo) && _aspxIsExistsElement(_dxeSCTxtChangeTo.GetMainElement()))
   return _dxeSCTxtChangeTo;
  return null;
 },
 GetCheckedTextFakeElement: function() {
  if(!_aspxIsExistsElement(this.checkedTextFakeElement))
   this.checkedTextFakeElement = document.createElement("DIV");
  return this.checkedTextFakeElement;
 },
 GetSampleErrorElement: function() {
  return document.getElementById(this.spellChecker.name + "_SpellCheckSpan");  
 },
 GetCachedSampleErrorElement: function() {
  if(!_aspxIsExistsElement(this.sampleErrorElement))
   this.sampleErrorElement = this.GetSampleErrorElement();
  return this.sampleErrorElement;
 },   
 GetPreviewTextElement: function() {
  if(!_aspxIsExistsElement(this.previewTextElement))
   this.previewTextElement = document.getElementById(this.spellChecker.name + "_" + this.GetSCForm().name +"_SCCheckedDiv"); 
  return this.previewTextElement;
 },
 ClearListBoxItems: function() {
  var listBox = this.GetSCFormListBox(this.GetSCForm());
  if(_aspxIsExists(listBox)) listBox.ClearItems();
 },
 CanPerformChangeAction: function() {
  return this.currentError.suggestionCount > 0;
 }, 
 HasErrors: function() {
  return this.errors.length > 0  || this.currentError != null;
 },
 ProcessNewError: function() {
  this.ClearErrorSelection();
  this.AdjustFormButtons();
  this.SelectError(this.currentError);
  this.PrepareFormControlsByError(this.currentError);
 },
 PrepareFormControlsByError: function(error) { 
  this.PopulateSuggestionsListBox(error);
  this.PrepareTextBox(error);
  this.SelectFirstSuggestion(); 
 },
 SetChangeButtonsEnabled: function(enabled) {
  var btnChange = this.GetSCFormChangeButton(this.GetSCForm());
  var btnChangeAll = this.GetSCFormChangeAllButton(this.GetSCForm());
  btnChange.SetEnabled(enabled);
  btnChangeAll.SetEnabled(enabled); 
 },
 SelectError: function(error) {
  var startIndex = this.GetWordStartIndex(error);
  var finishIndex = this.GetWordFinishIndex(error);   
  var text = this.spellChecker.checkedText;
  text = _aspxInsert(text, __aspxSCErrorMarker, finishIndex);
  text = _aspxInsert(text, __aspxSCErrorMarker, startIndex);
  if(this.spellChecker.editorElement != null)
   text = ASPxSpellCheckerFormHandler.PreparePreviewText(text);
  else
   text = ASPxSpellCheckerHtmlFilter.PreparePreviewHTML(text);
  startIndex = text.indexOf(__aspxSCErrorMarker);
  finishIndex = text.lastIndexOf(__aspxSCErrorMarker) + __aspxSCErrorMarker.length;
  var leftText = text.slice(0, startIndex);
  var rightText = text.slice(finishIndex);
  var element = this.GetPreviewTextElement();
  var errorSpan = this.GetCachedSampleErrorElement().cloneNode(true);
  errorSpan.innerHTML = error.word;
  element.appendChild(errorSpan);
  element.innerHTML = leftText + element.innerHTML + rightText;
  this.UpdatePreviewElementScroll();
 },
 UpdatePreviewElementScroll: function() {
  var previewElement = this.GetPreviewTextElement();
  var sampleErrorElement = this.GetSampleErrorElement();
  var previewElementClientHeight = _aspxGetClearClientHeight(previewElement);
  var sampleErrorElementScrollTop = sampleErrorElement.offsetTop + sampleErrorElement.offsetHeight;
  var delta = sampleErrorElementScrollTop - previewElement.scrollTop;
  if (delta >= previewElementClientHeight || delta <=0)
   previewElement.scrollTop = sampleErrorElement.offsetTop - 10; 
 },
 PopulateSuggestionsListBox: function(error) {
  var listBox = this.GetSCFormListBox(this.GetSCForm());
  if(!listBox)
   return;
  listBox.BeginUpdate();
  listBox.ClearItems();
  if(error.suggestions.length > 0) {
   for(var i = 0; i < error.suggestions.length; i++)
    listBox.AddItem(error.suggestions[i]);
  }
  else {
   listBox.AddItem(this.spellChecker.noSuggestionsText);
  }
  listBox.EndUpdate();
 },
 SelectFirstSuggestion: function() {
  var listBox = this.GetSCFormListBox(this.GetSCForm());
  if(listBox.GetItemCount() > 0)
   listBox.SetSelectedIndex(0); 
 },
 ShowSpellCheckerFormCore: function() {
  this.GetPreviewTextElement().scrollTop = 0;
  this.StartProcessError();
 },
 ShowSpellCheckerForm: function() {
  this.BeforeShowSpellCheckerForm();
  if(this.errorCount > 0)
   this.ShowSpellCheckerFormCore();
  else
   this.FinishSpellChecking();
 },
 AddToDictionaryClick: function() {
  this.spellChecker.AddWord(this.currentError.word);
 },
 CloseSpellCheckForm: function() {
  this.GetSCForm().OnComplete(0, 0);
 }, 
 FindWord: function(wordArray, word) { 
  for(var i = 0; i < wordArray.length; i++)
   if(word == wordArray[i])
    return true;
  return false;
 },
 FindWordInChangeAllList: function(word) {
  return this.changeAllList[word] != null;
 },
 FinishSpellChecking: function() {
  this.spellChecker.OnFinishSpellChecking(true);
 },   
 StartProcessError: function() {
  this.currentError = this.GetNextError();
  if(this.currentError)
   this.ProcessNewError(); 
  else
   this.FinishSpellChecking();
 },
 BeforeShowSpellCheckerForm: function() {
  this.delta = 0;
  this.spellChecker.checkedText = this.spellChecker.checkingText;
  this.InitializeErrorArray();
 },
 ChangeClick: function() {
  var suggestion = this.GetSuggestion();
  this.ChangeCore(suggestion);  
  this.spellChecker.OnWordChanged();
  this.StartProcessError();
 },
 IgnoreClick: function() {
  this.StartProcessError();
 },
 IgnoreAllClick: function() {  
  this.ignoreAllList.push(this.currentError.word);
  this.StartProcessError();
 }, 
 ChangeAllClick: function() {
  this.changeAllList[this.currentError.word] = this.GetSuggestion();
  this.ChangeClick();
 },    
 ListBoxItemChanged: function(listBox) { 
  var suggestion = listBox.GetSelectedItem().text;
  var textBox = this.GetSCFormChangeTextBox();
  textBox.SetValue(suggestion);
 },
 SCListBoxItemDoubleClick: function() {
  if(this.currentError.suggestionCount > 0)
   this.ChangeClick();
 }, 
 TextBoxKeyPress: function(keyCode) {
  if (keyCode > 0 && keyCode != ASPxKey.Enter && keyCode != ASPxKey.Esc)
   this.SetChangeButtonsEnabled(true);
 }, 
 TextBoxKeyDown: function(keyCode) {
  if(keyCode == ASPxKey.Backspace || keyCode == ASPxKey.Delete)
   this.SetChangeButtonsEnabled(true); 
 },
 ChangeCore: function(suggestion) { 
  this.DoChangeWord(suggestion);
  if(suggestion)
   this.delta += suggestion.length - this.currentError.wordLength;
  else
   this.delta -= this.currentError.wordLength;
 }, 
 GetWord: function(startIndex, endIndex) {
  var text = this.spellChecker.checkedText;
  return text.substring(startIndex, endIndex);
 },
 GetText: function(tdElement) {
  var text = "";
  var textNodes = new Array();
  _aspxGetChildTextNodeCollection(tdElement, textNodes);
  for(var i = 0; i < textNodes.length; i++)
   text += textNodes[i].nodeValue;
  return text;
 }, 
 GetWordByError: function(error) {
  var startIndex = this.GetWordStartIndex(error);
  var finishIndex = this.GetWordFinishIndex(error);
  return this.GetWord(startIndex, finishIndex);
 }, 
 GetWordStartIndex: function(error) {
  return error.wordStart + this.delta;
 }, 
 GetWordFinishIndex: function(error) {
  return error.wordStart + error.wordLength + this.delta;
 },
 DoChangeWord: function(suggestion) {
  var startIndex = this.GetWordStartIndex(this.currentError);
  var finishIndex = this.GetWordFinishIndex(this.currentError);
  var text = this.spellChecker.checkedText;
  this.spellChecker.checkedText = _aspxInsertEx(text, suggestion, startIndex, finishIndex);
 },
 GetNextError: function() { 
  while(this.errors.length > 0) { 
   var error = this.errors.shift();
   var word = error.word;
   if(this.FindWordInChangeAllList(word)) { 
    this.currentError = error;
    this.ClearErrorSelection();
    this.ChangeCore(this.changeAllList[word]);
    continue;
   }
   if(!this.FindWord(this.ignoreAllList, word))
    return error;
  }
  return null;
 }, 
 GetSuggestion: function() {
  return this.GetSCFormChangeTextBox().GetText();
 },  
 AdjustFormButtons: function() {
  this.SetChangeButtonsEnabled(this.CanPerformChangeAction());
 },
 ClearErrorSelection: function() {
  var element = this.GetPreviewTextElement();   
  if(_aspxIsExists(element)) element.innerHTML = "";
 },
 PrepareTextBox: function(error) {
  var textBox = this.GetSCFormChangeTextBox();  
  if(error.suggestions.length == 0) {
   textBox.SetValue(error.word);
   textBox.Focus();
   textBox.SelectAll();
  }
  else {
   textBox.SetValue(error.suggestions[0]);
   textBox.Focus();
  }
 } 
});
ASPxSpellCheckerFormHandler.PreparePreviewText = function(text) {
 var regExp = new RegExp("\\r\\n|\\n|\\n\\v", "g");
 text = _aspxApplyReplacement(text, [ [ /</g, '&lt;' ], [ />/g, '&gt;' ] ]);
 text = text.replace(regExp, "<br/>");
 return text;
}
var __aspxSCTextFormattingElementTagNames = [ "B", "I", "U", "S" ,"STRONG", "SMALL", "BIG", "BASEFONT", "TT", "STRIKE"];
var __aspxSCTextFormattingElementTagNameHashTable = _aspxCreateHashTableFromArray(__aspxSCTextFormattingElementTagNames);
var __aspxSCBlockElementTagNames = [ "H1", "H2", "H3", "H4" ,"H5", "H6", "CENTER" ];
var __aspxSCBlockElementTagNamesHashTable = _aspxCreateHashTableFromArray(__aspxSCBlockElementTagNames);
var __aspxSCForbiddenElementTagNames = [ "OBJECT", "APPLET", "IMG", "MAP" ,"IFRAME", "BODY", "HEAD", "SCRIPT", "LINK" ];
var __aspxSCForbiddenElementTagNamesHashTable = _aspxCreateHashTableFromArray(__aspxSCForbiddenElementTagNames);
ASPxSpellCheckerHtmlFilter = {};
ASPxSpellCheckerHtmlFilter.PreparePreviewHTML = function(html) {
 var fakeElement = document.createElement("DIV");
 _aspxSetInnerHtml(fakeElement, html);
 ASPxSpellCheckerHtmlFilter.FilterElements(fakeElement);
 return fakeElement.innerHTML;
}
ASPxSpellCheckerHtmlFilter.FilterElements = function(parentNode) {
 for (var i = parentNode.childNodes.length - 1; i >= 0 ; i--)
  ASPxSpellCheckerHtmlFilter.FilterElements(parentNode.childNodes[i]);
 ASPxSpellCheckerHtmlFilter.CleanElement(parentNode);
}
ASPxSpellCheckerHtmlFilter.CleanElement = function(element) {
 if (element.nodeType == 1) {
  var tagName = element.tagName;
  if (ASPxSpellCheckerHtmlFilter.IsTextFormattingElementTagName(tagName))
   _aspxRemoveOuterTags(element);
  else if (ASPxSpellCheckerHtmlFilter.IsBlockElementTagName(tagName))
   _aspxReplaceTagName(element, "P");
  else if (ASPxSpellCheckerHtmlFilter.IsForbiddenElementTagName(tagName))
   _aspxRemoveElement(element);
  else {
   _aspxRemoveAllAttributes(element);
   _aspxRemoveAllStyles(element);
   if (ASPxSpellCheckerHtmlFilter.IsLinkElementTagName(tagName))
    _aspxSetAttribute(element, "href", "javascript:void('0')");
  }
 }
}
ASPxSpellCheckerHtmlFilter.IsTextFormattingElementTagName = function(tagName) {
 return _aspxIsExists(__aspxSCTextFormattingElementTagNameHashTable[tagName]);
}
ASPxSpellCheckerHtmlFilter.IsBlockElementTagName = function(tagName) {
 return _aspxIsExists(__aspxSCBlockElementTagNamesHashTable[tagName]);
}
ASPxSpellCheckerHtmlFilter.IsForbiddenElementTagName = function(tagName) {
 return _aspxIsExists(__aspxSCForbiddenElementTagNamesHashTable[tagName]);
}
ASPxSpellCheckerHtmlFilter.IsLinkElementTagName = function(tagName) {
 return tagName == "A";
}
ASPxContainerBrowser = _aspxCreateClass(null, {
 constructor: function() {
  this.currentEditor = null;
  this.nextEditor = null;
  this.isCurrentEditorFound = false;
 },
 BeforeFindNextEditor: function(currentEditor) { 
  this.nextEditor = null;
  this.isCurrentEditorFound = false;  
  this.currentEditor = currentEditor;
 },
 FindNextEditor: function(container, currentEditor) { 
  this.BeforeFindNextEditor(currentEditor);
  this.FindNextEditorCore(container);
  return this.nextEditor;
 },
 FindNextEditorCore: function(container) { 
  if(this.nextEditor != null)
   return;
  for(var i = 0; i < container.childNodes.length; i++) {
   var curNode = container.childNodes[i];
   if(ASPxEditorHelper.IsEditableEditNode(curNode))
    this.ProcessEditableEditNode(curNode);
   else
    this.FindNextEditorCore(curNode);
  }
 },
 ProcessEditableEditNode: function(editNode) {
  if(this.nextEditor != null)
   return;
  if(editNode == this.currentEditor) { 
   this.isCurrentEditorFound = true;
   return;
  }
  if(this.isCurrentEditorFound || !this.currentEditor) {
   this.nextEditor = editNode;
   return;
  }
 } 
});
ASPxSpellCheckerBaseEditorHelper = _aspxCreateClass(null, {
 constructor: function() {},
 GetText: function(editor) {
  return editor.value; 
 },
 SetText: function(editor, value) {
  editor.value = value;
 },
 IsEditable: function(editor) {
  return !editor.disabled && !editor.readOnly;
 }
});
ASPxSpellCheckerASPxEditorHelper = _aspxCreateClass(ASPxSpellCheckerBaseEditorHelper, {
 constructor: function() { 
  this.constructor.prototype.constructor.call(this);
 },
 GetText: function(editor) {
  return editor.GetValue(); 
 },
 SetText: function(editor, value) {
  if (_aspxIsExists(editor.SetText))
   editor.SetText(value);
  else
  editor.SetValue(value);
 },
 IsEditable: function(editor) {
  return editor.GetEnabled() && 
   ASPxSpellCheckerBaseEditorHelper.prototype.IsEditable(editor.GetInputElement());
 }
});
ASPxEditorHelper = _aspxCreateClass(null, {
 constructor: function() {
  this.standardEditorHelper = new ASPxSpellCheckerBaseEditorHelper();
  this.DXEditorHelper = new ASPxSpellCheckerASPxEditorHelper();
 },
 GetDXEditorByInput: function(inputElement) {
  var collection = aspxGetControlCollection();
  for(var name in collection.elements) {
   var element = collection.elements[name];
   if(ASPxIdent.IsASPxClientEdit(element) && element.GetInputElement() == inputElement)
    return element;
  }
  return null;
 },
 SetText: function(inputElement, value) {
  if(this.IsDXEditor(inputElement)) {
   this.GetDXEditorHelper().SetText(this.GetDXEditorByInput(inputElement), value);
   this.GetDXEditorByInput(inputElement).RaiseTextChanged();
  }
  else
   this.GetStandardEditorHelper().SetText(inputElement, value);
 },
 GetText: function(inputElement) {
  if(this.IsDXEditor(inputElement))
   return this.GetDXEditorHelper().GetText(this.GetDXEditorByInput(inputElement));
  else
   return this.GetStandardEditorHelper().GetText(inputElement);
 },
 IsDXEditor: function(inputElement) {
  return this.GetDXEditorByInput(inputElement) != null; 
 },
 IsEditable: function(inputElement) {
  if(this.IsDXEditor(inputElement))
   return this.GetDXEditorHelper().IsEditable(this.GetDXEditorByInput(inputElement));
  else
   return this.GetStandardEditorHelper().IsEditable(inputElement);
 },
 GetStandardEditorHelper: function() {
  return this.standardEditorHelper;
 },
 GetDXEditorHelper: function() {
  return this.DXEditorHelper;
 }
});
ASPxEditorHelper.IsEditableEditNode = function(element) {
 if(!_aspxIsExists(element.tagName))
  return false;
 var tagName = element.tagName;
 if((tagName == "INPUT" && element.type == "text") || tagName == "TEXTAREA")  
  return ASPxEditorHelper.CanEditNode(element);
 return false;
}
ASPxEditorHelper.CanEditNode = function(element) {
 return !element.readOnly && !element.disabled;
}
function aspxSCIgnore(s, e) {
 __aspxActiveSpellChecker.Ignore();
}
function aspxSCIgnoreAll(s, e) {
 __aspxActiveSpellChecker.IgnoreAll();
}
function aspxSCAddToDictionary(s, e) {
 __aspxActiveSpellChecker.AddToDictionary();
}
function aspxSCChange(s, e) {
 __aspxActiveSpellChecker.Change();
}
function aspxSCChangeAll(s, e) {
 __aspxActiveSpellChecker.ChangeAll();
}
function aspxSCShowOptionsForm(s, e) {
 __aspxActiveSpellChecker.ShowOptionsForm();
}
function aspxSCListBoxItemChanged(s, e) {
 __aspxActiveSpellChecker.ListBoxItemChanged(s, e);
}
function aspxSCTextBoxKeyPress(s, e) {
 if (__aspxActiveSpellChecker != null)
  __aspxActiveSpellChecker.TextBoxKeyPress(e.htmlEvent);
}
function aspxSCTextBoxKeyDown(s, e) { 
 if (__aspxActiveSpellChecker != null)
  __aspxActiveSpellChecker.TextBoxKeyDown(e.htmlEvent);
}
function aspxSCListBoxItemDoubleClick(s, e) { 
 if (__aspxActiveSpellChecker != null)
  __aspxActiveSpellChecker.SCListBoxItemDoubleClick();
}
ASPxClientSpellChecker.prototype.RaiseBeforeCheck = function(controlId) {
 if(!this.BeforeCheck.IsEmpty()) {
  var args = new ASPxClientSpellCheckerBeforeCheckEventArgs(controlId);
  this.BeforeCheck.FireEvent(this, args);
  return !args.cancel;
 } 
 return true;
}
ASPxClientSpellCheckerBeforeCheckEventArgs = _aspxCreateClass(ASPxClientCancelEventArgs, {
 constructor: function(controlId){
  this.constructor.prototype.constructor.call(this);
  this.controlId = controlId;
 }
});
ASPxClientSpellChecker.prototype.RaiseCheckCompleteFormShowing = function() {
 if(!this.CheckCompleteFormShowing.IsEmpty()) {
  var args = new ASPxClientCancelEventArgs();
  this.CheckCompleteFormShowing.FireEvent(this, args);
  return !args.cancel;
 }
 return true;
}
ASPxClientSpellChecker.prototype.RaiseAfterCheck = function(controlId, checkedText) {
 if(!this.AfterCheck.IsEmpty()) {
  var args = new ASPxClientSpellCheckerAfterCheckEventArgs(controlId, checkedText);
  this.AfterCheck.FireEvent(this, args);
 }
}
ASPxClientSpellChecker.prototype.RaiseWordChanged = function(controlId, checkedText) {
 if(!this.WordChanged.IsEmpty()) {
  var args = new ASPxClientSpellCheckerAfterCheckEventArgs(controlId, checkedText);
  this.WordChanged.FireEvent(this, args);
 }
}
ASPxClientSpellCheckerAfterCheckEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
 constructor: function(controlId, checkedText){
  this.constructor.prototype.constructor.call(this, null);
  this.controlId = controlId;
  this.checkedText = checkedText;
 }
});

