var activeEditor;var textContent=null;var matches;var matchSet;var activeMatch;var activeMatchIndex=0;var activeMatchOcc;function openSpellingCheck(A){textContent=A.getContentData();activeEditor=A;text=textContent.replace(/<.*?>/g," ");text=text.replace(/&.*?;/g," ");var B="event=checkSpelling&text="+encode(text);YAHOO.util.Connect.asyncRequest("POST","/services/SpellChecker",{success:checkSpellingHandler,failure:function(C){}},B)}function checkSpellingHandler(F){var D=F.responseXML;matches=new Array();matchSet=new Object();var I=D.getElementsByTagName("mistake");for(var H=0;H<I.length;H++){var K=decode(I[H].getAttribute("word"));matches.push(K);var J=new Array();if(I[H].firstChild){J=I[H].firstChild.data.split(",");for(var G=0;G<J.length;G++){J[G]=decode(J[G])}}matchSet[K]=J}var A=new Array();for(var H=0;H<matches.length;H++){var K=matches[H];if(A[K]){continue}A[K]=true;var C=new RegExp("(\\b)"+K+"(\\b)","g");var B="@"+K+"@";textContent=textContent.replace(C,B);for(var G=0;G<20&&textContent.match(B);G++){var E="<span id='match"+H+"' class='occ"+G+"' style='color:#ff0000;font-weight:bold;'>"+K+"</span>";textContent=textContent.replace(B,E)}}mistakesLeft=matches.length;activeEditor.setMistakes(matches.length,mistakesLeft);activeEditor.setContent(textContent);YAHOO.util.Event.addListener(activeEditor.getFrameElement().contentWindow,"contextmenu",matchSuggest);YAHOO.util.Event.addListener(activeEditor.getFrameElement().contentWindow,"mousedown",matchSuggest)}function closeSpellingCheck(B){if(textContent==null){return }closeMenu();if(textContent!=null){var A=new RegExp("<span id='?match.*?>(.*?)</span>","ig");textContent=textContent.replace(A,"$1");B.setContent(textContent)}YAHOO.util.Event.removeListener(B.getFrameElement().contentWindow,"contextmenu");YAHOO.util.Event.removeListener(B.getFrameElement().contentWindow,"mousedown");textContent=null}function matchSuggest(K){var G=YAHOO.util.Event.getTarget(K);var B=activeEditor.getFrameElement();activeMatch=G.firstChild.data;if(G.id.match(/match\d*/)){activeMatchIndex=G.id.replace(/match/,"");activeMatchOcc=G.className.replace(/occ/,"");var L=YAHOO.util.Dom.getXY(G);var C=YAHOO.util.Dom.getXY(B);var I=C[0]+L[0];var H=C[1]+L[1]+20;var A=B.contentWindow;if(webBrowser.isIE||webBrowser.isOpera){H-=(A.document.documentElement.scrollTop+A.document.body.scrollTop-20)}else{H-=A.scrollY}var M=document.getElementById("matchList");M.style.display="";YAHOO.util.Dom.setXY(M,new Array(I,H));var F=matchSet[activeMatch];if(F){if(webBrowser.isNS&&webBrowser.realVersion<1.5){var J="<div id='newText' class='menuItem'><a class='plain' href='javascript:menuCall(\"newText\"); void 0;'>(Change word)</a></div>";for(var D=0;D<F.length;D++){J+="<div id='item"+D+"' class='menuItem'><a class='menuItemA' href='javascript:menuCall(\"item"+D+"\"); void 0'>"+F[D]+"</a></div>"}}else{var J="<div id='newText' class='menuItem'><a class='menuItemA' href='#' onclick='menuCall(\"newText\"); return false;' onmouseover='menuSelect(this.parentNode.id)' onmouseout='menuDeselect(this.parentNode.id)'>(Change word)</a></div>";for(var D=0;D<F.length;D++){J+="<div id='item"+D+"' class='menuItem'><a class='menuItemA' href='#' onclick='menuCall(this.parentNode.id); return false' onmouseover='menuSelect(this.parentNode.id)' onmouseout='menuDeselect(this.parentNode.id)'>"+F[D]+"</a></div>"}}M.innerHTML=J}}else{closeMenu()}var E=B.contentWindow;if(E.event){E.event.returnValue=false;E.event.cancelBubble=true}else{K.preventDefault();K.stopPropagation()}}function menuSelect(B){var A=document.getElementById(B);A.className="menuItemSelected";A.firstChild.className="menuItemSelectedA"}function menuDeselect(B){var A=document.getElementById(B);A.className="menuItem";A.firstChild.className="menuItemA"}function closeMenu(){var A=document.getElementById("matchList");A.style.display="none"}function menuCall(D){closeMenu();var B;if(D=="newText"){B=prompt("New text:","");if(!B){return false}}else{var A=parseInt(D.replace(/item/,""));B=matchSet[activeMatch][A]}matchSet[B]=matchSet[activeMatch];B="<span id='match"+activeMatchIndex+"' class='occ"+activeMatchOcc+"' style='color:#0000dd;font-weight:bold;'>"+B+"</span>";var C=new RegExp("<span id=[\"']match"+activeMatchIndex+"[\"'] class=[\"']occ"+activeMatchOcc+"\"?'? .*?>"+activeMatch+"</span>","i");textContent=textContent.replace(C,B);activeEditor.setContent(textContent);mistakesLeft--;activeEditor.setMistakes(matches.length,mistakesLeft);return false}function nextMistake(){}function previousMistake(){}var pageChanged=false;function markPageChanged(){pageChanged=true}function resetChangableFields(){pageChanged=false}function registerChangableFields(C){if(!C){C=document.form}var A=C.elements;for(var B=0;B<A.length;B++){var D=A[B];YAHOO.util.Event.addListener(D,"change",function(){pageChanged=true})}}function onbeforeunloadInternalPage(){if(pageChanged){return confirm("If you leave without saving, your changes will be lost.\nAre you sure you want to leave this page?")}else{return true}}window.onbeforeunload=function(){if(pageChanged){return"If you leave without saving, your changes will be lost."}};
