﻿function GoogieSpellMultiple(F,C){this.img_dir=F;this.server_url=C;this.dependent=false;this.g_elms=[];this.spell_container=null;this.extra_menu_items=[];this.use_close_btn=false;var D=function(L,H){for(var K=0;K<this.g_elms.length;K++){var I=this.g_elms[K];for(var J=0;J<I.error_links.length;J++){var G=I.error_links[J];if(G.innerHTML==L.old_value){I.correctError(G.g_id,G,L)}}}};var E=function(H,G){if(H.is_corrected){return true}return false};var B=function(H,G){if(G.results[H.g_id]["attrs"]["duplicate"]=="true"||H.is_corrected){return false}return true};var A=function(H,G){if(H.is_corrected){return false}return true};this.appendNewMenuItem("Change all",AJS.$b(D,this),E);this.appendNewMenuItem("Ignore",AJS.$b(this.ignore,this),A);this.appendNewMenuItem("Ignore all",AJS.$b(this.ignoreAll,this),B);this.state="created";this.no_more_errors_callback=null;this.elm_evaluator=function(){return true};this.getValue=function(G){return G.value};this.setValue=function(G,H){G.value=H};this.getWysiwyg=function(G){return false};this.cnt_no_errors=null;this.cnt_ta_spellchecked=0;this.cnt_done_checking=null}GoogieSpellMultiple.prototype.getState=function(){return this.state};GoogieSpellMultiple.prototype.noMoreErrorsCallback=function(A){this.no_more_errors_callback=A};GoogieSpellMultiple.prototype.noErrorsFound=function(){return this.cnt_no_errors!=null&&this.cnt_no_errors==this.g_elms.length};GoogieSpellMultiple.prototype.isReqDone=function(){return this.cnt_done_checking==null||this.cnt_done_checking==this.g_elms.length};GoogieSpellMultiple.prototype.isSpellChecking=function(){return this.state=="checking_spell"};GoogieSpellMultiple.prototype.setDependent=function(){this.dependent=true};GoogieSpellMultiple.prototype.setCustomAjaxError=function(A){this.custom_ajax_error=A};GoogieSpellMultiple.prototype.setElementEvaulator=function(A){this.elm_evaluator=A};GoogieSpellMultiple.prototype.setSpellContainer=function(A){this.spell_container=AJS.getElement(A)};GoogieSpellMultiple.prototype.useCloseButtons=function(){this.use_close_btn=true};GoogieSpellMultiple.prototype.setGetValue=function(A){this.getValue=A};GoogieSpellMultiple.prototype.setSetValue=function(A){this.setValue=A};GoogieSpellMultiple.prototype.setGetWysiwyg=function(A){this.getWysiwyg=A};GoogieSpellMultiple.prototype.appendNewMenuItem=function(B,C,A){this.extra_menu_items.push([B,C,A])};GoogieSpellMultiple.prototype.countNoErrorsUp=function(){if(!this.cnt_no_errors){this.cnt_no_errors=1}else{this.cnt_no_errors++}};GoogieSpellMultiple.prototype.countSpellCheckingFinished=function(){if(!this.cnt_done_checking){this.cnt_done_checking=1}else{this.cnt_done_checking++}};GoogieSpellMultiple.prototype.resetCounters=function(){this.cnt_done_checking=null;this.cnt_no_errors=null;this.cnt_ta_spellchecked=0};GoogieSpellMultiple.prototype.spellCheckObserver=function(C,A){if(C=="checking_spell"){this.resetCounters();this.cnt_done_checking=0;this.state="checking_spell";for(var B=0;B<this.g_elms.length;B++){var D=this.g_elms[B];if(D.state=="spell_check"){D.setReportStateChange(false);D.spellCheck(!this.elm_evaluator(D));D.setReportStateChange(true)}}}else{if(C=="spell_check"){this.state="spell_check";for(var B=0;B<this.g_elms.length;B++){var D=this.g_elms[B];if(D.spell_span!=null&&D.state!="spell_check"&&D.state!="no_error_found"&&D.state!="checking_spell"){D.setReportStateChange(false);D.resumeEditing();D.setReportStateChange(true)}}}else{if(C=="resume_editing"){this.state="resume_editing";this.countSpellCheckingFinished();this.spellcheckingFinished();var D=this.g_elms[0];D.setReportStateChange(false);D.resumeEditingState();D.setReportStateChange(true)}}}};GoogieSpellMultiple.prototype.spellcheckingFinished=function(){if(this.cnt_done_checking==this.g_elms.length){for(var A=0;A<this.g_elms.length;A++){var B=this.g_elms[A];if(B.setFocus()){break}}}};GoogieSpellMultiple.prototype.spellCheckState=function(){for(var A=0;A<this.g_elms.length;A++){var B=this.g_elms[A];B.setReportStateChange(false);B.resumeEditing();B.setReportStateChange(true)}};GoogieSpellMultiple.prototype.showMenuObserver=function(C,B){for(var A=0;A<C.g_elms.length;A++){var D=C.g_elms[A];if(D!=B){D.hideLangWindow();D.hideErrorWindow()}}};GoogieSpellMultiple.prototype.ignore=function(B,A){AJS.swapDOM(B,AJS.TN(B.innerHTML));if(!B.is_corrected){A.errorFixed()}B.is_corrected=true};GoogieSpellMultiple.prototype.ignoreAll=function(F){for(var D=0;D<this.g_elms.length;D++){var B=this.g_elms[D];for(var C=0;C<B.error_links.length;C++){var A=B.error_links[C];if(A.innerHTML==F.innerHTML){try{AJS.swapDOM(A,AJS.TN(A.innerHTML))}catch(E){}if(A.is_corrected==false){B.errorFixed();A.is_corrected=true}}}}};GoogieSpellMultiple.prototype._taSpellChecked=function(){this.cnt_ta_spellchecked++;if(this.no_more_errors_callback){if(this.cnt_ta_spellchecked+this.cnt_no_errors==this.g_elms.length){this.no_more_errors_callback()}}};GoogieSpellMultiple.prototype.decorateTextareas=function(){var E=this;for(var C=0;C<arguments.length;C++){var H=AJS.$(arguments[C]);if(H!=null){var D=new GoogieSpell(this.img_dir,this.server_url);D.use_focus=true;if(this.g_elms.length!=0){D.main_controller=false}D.edit_layer_dbl_click=false;D.report_ta_not_found=true;if(this.dependent){D.spelling_state_observer=function(J,I){E.spellCheckObserver(J,I)};D.custom_no_spelling_error=function(I){I.state="spell_check";E.countNoErrorsUp();if(E.cnt_no_errors==E.g_elms.length){E.g_elms[0].flashNoSpellingErrorState(AJS.$b(E.spellCheckState,E))}E.countSpellCheckingFinished();E.spellcheckingFinished()}}if(this.custom_ajax_error){D.custom_ajax_error=this.custom_ajax_error}D.show_menu_observer=function(I){E.showMenuObserver(E,I)};var G=function(I){if(I.attrs["duplicate"]=="true"){return true}return false};var B=function(M,L,I){var K=function(){M.correctError(I.g_id,I,{innerHTML:""},true)};AJS.ACN(L,M.createButton("Remove duplicate","",K));AJS.ACN(L,M.createListSeparator());for(var J=0;J<E.extra_menu_items.length;J++){var N=E.extra_menu_items[J];if(!N[2]||N[2](I,M)){AJS.ACN(L,M.createButton(N[0],"",AJS.$p(N[1],I,M)))}}AJS.ACN(L,M.createCloseButton(M.hideErrorWindow));return true};var A=function(K,I){var J=K.results[I.g_id];if(J.attrs["autoChange"]==1){K.correctError(I.g_id,I,{innerHTML:J.suggestions[0]},false)}};D.custom_item_evaulator=A;D.appendCustomMenuBuilder(G,B);if(this.spell_container){D.setDecoration(false);D.setSpellContainer(this.spell_container);D.custom_spellcheck_starter=function(){E.spellCheckObserver("checking_spell")}}var F=function(){E._taSpellChecked()};D.all_errors_fixed_observer=F;D.extra_menu_items=this.extra_menu_items;D.use_close_btn=this.use_close_btn;D.getValue=this.getValue;D.setValue=this.setValue;D.getWysiwyg=this.getWysiwyg;D.decorateTextarea(H);this.g_elms.push(D)}}this.state="spell_check"};
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();