var m_spellTags=0;function Dictionary(){this.correctWords=new SuggestionList();this.suggestions=new SuggestionList();this.toFillCache=new Array();this.markupFun=null;this.idIndex=0;return this;}
Dictionary.prototype.setMarkup=function(markupFun){this.markupFun=markupFun;return(this.markupFun!=null);}
Dictionary.prototype.getSuggestions=function(word){return this.suggestions.lookup(word);}
Dictionary.prototype.refillDeltaCache=function(phraseBucket){for(i=0;i<this.toFillCache.length;i++){this.toFillCache.shift();}
this.toFillCache=new Array();for(i=0;i<phraseBucket.length;i++){var aPhrase=phraseBucket[i];aPhrase=aPhrase.split("\n").join(" ");var wordList=aPhrase.split(" ");var j;for(j=0;j<wordList.length;j++){var aWord=wordList[j];if(/^[\s\t]*$/.test(aWord))continue;if(this.correctWords.lookup(aWord)==''&&this.suggestions.lookup(aWord)==''){this.toFillCache.push(aWord);}}}}
Dictionary.prototype.checkParts=function(phraseBucket){var i;var returnBucket=new Array();this.refillDeltaCache(phraseBucket);this.idIndex=0;if(this.toFillCache.length!=0){var proxy=new SpellProxy();var response=proxy.checkWords(this.toFillCache);for(i=0;i<response.length;i+=2){this.suggestions.insert(response[i],response[i+1])}
for(i=0;i<this.toFillCache.length;i++){if(this.suggestions.lookup(this.toFillCache[i])==''){this.correctWords.insertKvp(this.toFillCache[i],'CORRECT');}}}
for(i=0;i<phraseBucket.length;i++){if(phraseBucket[i]!=''){returnBucket.push(this.checkAPhrase(phraseBucket[i]));}
else{returnBucket.push('');}}
return returnBucket;}
Dictionary.prototype.checkAPhrase=function(phrase){if(phrase==''){return;}
phrase=phrase.split("\t").join(" ");phrase=phrase.split("\n").join(" ");var words=phrase.split(" ");var i;var outPhrase='';for(i=0;i<words.length;i++){if(words[i]!=''){outPhrase=outPhrase+' '+this.checkAWord(words[i])+' ';}}
return outPhrase;}
Dictionary.prototype.checkAWord=function(word){var suggestion=word;if(word==''){return;}
if(this.correctWords.lookup(word)=='CORRECT'){suggestion=word;}
else{if(this.suggestions.lookup(removePunct(word))!=''){var id="HJhrefID"+this.idIndex;'inNode',this.idIndex++;suggestion=this.markupFun(word,id);}}
m_spellTags=this.idIndex;return suggestion;}
function HtmlTextHandler(){this.inNode=null;this.outNode=null;this.textBucket=new Array();this.replaceBucket=null;this.nextPhraseIndex=0;this.nodesToReplace=new Array();this.idIndex=0;return this;}
HtmlTextHandler.prototype.setInNode=function(node){this.inNode=node;return(node!=null);}
HtmlTextHandler.prototype.setOutNode=function(node){this.outNode=node;if(node==null){this.outNode=document.createElement('DIV');}
return(node!=null);}
HtmlTextHandler.prototype.addToTextBucket=function(obj,textNode){var text=textNode.nodeValue;if(/^[\s\n]*$/.test(text)){return;}
var toPush=textNode.nodeValue;toPush=toPush.replace("&nbsp;"," ");obj.textBucket.push(textNode.nodeValue);return;}
HtmlTextHandler.prototype.walkDOM=function(node,textCallBack){var aChild=node.firstChild;var child_no=1;while(aChild){if(aChild.nodeType==3){textCallBack(this,aChild);}
else if(aChild.nodeType==1){if(aChild.nodeName=='A'){aChild.href='#';}
this.walkDOM(aChild,textCallBack);}
aChild=aChild.nextSibling;child_no++;}
return;}
HtmlTextHandler.prototype.getHTML=function(){return this.outNode.innerHTML;}
HtmlTextHandler.prototype.getTextParts=function(){var i;for(i=0;i<this.textBucket.length;i++){this.textBucket.shift(0);}
this.textBucket=new Array();this.nextPhraseIndex=0;for(i=0;i<this.nodesToReplace.length;i++){this.nodesToReplace.shift(0);}
this.nodesToReplace=new Array();this.walkDOM(this.inNode,this.addToTextBucket);return this.textBucket;}
HtmlTextHandler.prototype.assembleHTML=function(newtextBucket){this.nextPhraseIndex=0;this.replaceBucket=newtextBucket;this.outNode=this.inNode.cloneNode(true);this.walkDOM(this.outNode,this.replacePhrase);this.replaceTextNodes();return this.outNode.innerHTML;}
HtmlTextHandler.prototype.replacePhrase=function(obj,textNode){var text=textNode.nodeValue;if(/^[\s\n]*$/.test(text)){return;}
obj.nodesToReplace.push(textNode);return;}
HtmlTextHandler.prototype.replaceTextNodes=function(){var i;for(i=0;i<this.nodesToReplace.length;i++){var thisNode=this.nodesToReplace[i];var text=thisNode.nodeValue;if(/^[\s\n]*$/.test(text)){continue;}
newNode=document.createElement('span');newNode.innerHTML=this.replaceBucket[this.nextPhraseIndex];newNode.isSpellNode=true;newNode.id='spellnode'+this.nextPhraseIndex;thisNode.parentNode.replaceChild(newNode,thisNode);this.nextPhraseIndex++;}}
HtmlTextHandler.prototype.removeSpellTags=function(node){var i;var aChild=node.firstChild;var child_no=1;while(aChild){if(aChild.nodeType==1){if(/^HJhrefID/.test(aChild.id)){aChild.innerHTML=aChild.innerText;}
this.removeSpellTags(aChild);}
aChild=aChild.nextSibling;child_no++;}
return;}
function SpellChecker(){this.htmlTextHandler=new HtmlTextHandler();this.dictionary=new Dictionary();this.nodeIn=null;this.nodeOut=null;this.markupFun=null;}
SpellChecker.prototype.setInLayerID=function(id){this.nodeIn=document.getElementById(id);this.htmlTextHandler.setInNode(this.nodeIn);return(this.nodeIn!=null);}
SpellChecker.prototype.setOutLayerID=function(id){this.nodeOut=document.getElementById(id);this.htmlTextHandler.setOutNode(this.nodeOut);return(this.nodeOut!=null);}
SpellChecker.prototype.setMarkup=function(markupFun){this.markupFun=markupFun;this.dictionary.setMarkup(markupFun);return(this.markupFun!=null);}
SpellChecker.prototype.removeSpellTags=function(node){this.htmlTextHandler.removeSpellTags(node);}
SpellChecker.prototype.checkHTML=function(){var textParts=this.htmlTextHandler.getTextParts();var i=0;var checkedParts=this.dictionary.checkParts(textParts);this.htmlTextHandler.assembleHTML(checkedParts);return(this.htmlTextHandler.getHTML());}
SpellChecker.prototype.getSuggestions=function(word){return this.dictionary.getSuggestions(word);}
function SpellProxy(){try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(E){this.xmlhttp=false;}}
try{if(!this.xmlhttp&&typeof(XMLHttpRequest)!='undefined'){this.xmlhttp=new XMLHttpRequest();}}
catch(e){alert('no xmlhttp');}
this.response='';return this;}
function removePunct(word){var punct=new Array("\"",".",",",";","(",")","$","!","/","`",":","?","[","]");var i;for(i=0;i<punct.length;i++){var thisPunct=punct[i];while(word.indexOf(thisPunct)!=-1){word=word.replace(thisPunct," ");}}
while(/^\'/.test(word))word=word.replace("'"," ");return word;}
SpellProxy.prototype.checkWords=function(wordList){var i;var request='';for(i=0;i<wordList.length;i++){var aWord=wordList[i];aWord=removePunct(aWord);if(/[a-zA-Z]/.test(aWord)){request=request+aWord+String.fromCharCode(1);}}
request='WORD_LIST='+request;var spellUrl=getSpellURL();this.xmlhttp.open("POST",spellUrl,false);this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.xmlhttp.send(request);this.response=this.xmlhttp.responseText;var sugPairs=this.response.split(String.fromCharCode(3));var retVal=new Array();for(i=0;i<sugPairs.length;i++){var curSug=sugPairs[i];var sugParts=curSug.split(String.fromCharCode(1));if(sugParts.length==2){var curWord=sugParts[0];var curSugs=sugParts[1];var sugList=curSugs.split(String.fromCharCode(2));if(sugList.length==1&&sugList[0]=='')
{sugList[0]='(no suggestions)';}
retVal.push(curWord);retVal.push(sugList);}}
return retVal;}
function SuggestionList(){this.keys=new Array();this.values=new Array();}
SuggestionList.prototype.insertKvp=function(key,value){key=key.replace(/\s+/,'');value=value.replace(/\s+/,'');this.keys.push(key);this.values.push(value);}
SuggestionList.prototype.insert=function(key,value){key=key.replace(/\s+/,'');this.keys.push(key);this.values.push(value);}
SuggestionList.prototype.lookup=function(key){var i;var value='';key=key.replace(/\s+/,'');for(i=0;i<this.keys.length;i++){if(this.keys[i].toLowerCase()==key.toLowerCase()){value=this.values[i];break;}}
return value;}
function markup(str,id)
{str=str.replace(/\s+/,'');var retVal='';retVal+='<span id ="'+id+'" style="background-color:#FFFF00;color:#000000;">';retVal+=str;retVal+='</span>';return retVal;}
function hideSugMenu()
{var menu=document.getElementById('suggestionMenu');if(menu.style)
{menu=menu.style;}
menu.visibility="hidden";}
var menuBG="#C3D9FF";var menuItemStyle='style="background-color:'+menuBG+';font-family:Arial,Helvetica,Sans;font-size:11px;color:#000000;padding:5px;padding-right:25px;padding-left:10px;" ';var menuEditItemStyle='style="background-color:'+menuBG+';margin-top:1px;font-family:Arial,Helvetica,Sans;font-size:11px;color:#000000;padding:5px;padding-right:25px;border-top:1px solid #9DAECD;padding-left:10px;" ';function isMozillaAlone()
{var ua=navigator.userAgent;return(ua.indexOf('Mozilla')!=-1&&ua.indexOf('Firefox')==-1);}
window.showSugMenu=function(word,e,wordId,rteID)
{try{var menu=document.getElementById('suggestionMenu');if(menu.style)
{menu=menu.style;}
var suglist=speller.getSuggestions(removePunct(word));var menuHTML='';var i;if(isMozillaAlone()==false)
{menuHTML+='<table width="100%">';}
else
{menuHTML+='<span style="font-size:12px;">';}
for(i=0;i<suglist.length;i++)
{if(isMozillaAlone()==true)
{menuHTML+=mozillaMenuItem(suglist[i],wordId,menuItemStyle,rteID);}
else
{menuHTML+=menuItem(suglist[i],wordId,menuItemStyle,rteID);}}
if(isMozillaAlone()==false)
{menuHTML+='<tr><td onClick="javascript:ignoreSuggestion(\''+word;menuHTML+='\', \''+wordId+'\', \''+rteID+'\')" onMouseOver="javascript:hlMenuItem(this)"';menuHTML+=menuEditItemStyle;menuHTML+=' onMouseOut="javascript:dlMenuItem(this)"';menuHTML+='> <span style="cursor:default;"><i>Ignore</i></span></td></tr>';menuHTML+='<tr><td onClick="javascript:ignoreAll(';menuHTML+='\''+wordId+'\', \''+rteID+'\')" onMouseOver="javascript:hlMenuItem(this)"';menuHTML+=menuItemStyle;menuHTML+=' onMouseOut="javascript:dlMenuItem(this)"';menuHTML+='> <span style="cursor:default;"><i>Ignore All</i></span></td></tr>';menuHTML+='</table>';}
else
{menuHTML+='<div style="padding:4px;padding-left:10px;border-top:1px solid grey;">';menuHTML+='<a style="text-decoration:none;" href="javascript:ignoreSuggestion(\''+word+'\',\''+wordId+'\',\''+rteID+'\')">';menuHTML+='<i>Ignore</i></a></div>';menuHTML+='<div style="padding:4px;padding-left:10px;">';menuHTML+='<a style="text-decoration:none;" href="javascript:ignoreAll(\''+wordId+'\',\''+rteID+'\')">';menuHTML+='<i>Ignore All</i></a></div>';menuHTML+='</span>';}
document.getElementById('suggestionMenu').innerHTML=menuHTML;moveObject('suggestionMenu',e,rteID,wordId);}catch(error){alert('show sug menu : '+error.description);}}
function hlMenuItem(obj)
{try{if(!obj)
{return;}
if(obj.style)
{obj=obj.style;}
obj.backgroundColor="#5570CC";obj.color="#FFFFFF";}catch(e){}
return;}
function dlMenuItem(obj)
{try{if(!obj)
{return;}
if(obj.style)
{obj=obj.style;}
obj.backgroundColor=menuBG;obj.color='#000000';}catch(e){}
return;}
function menuItem(word,wordId,style,rteID)
{var retval='';var wordParts=word.split("'");var originalWord=word;if(wordParts.length==2)
{word=wordParts[0]+"\\"+"'"+wordParts[1];}
retval+='<tr><td onClick="javascript:correctSuggestion(\'';retval+=word+'\', \''+wordId+'\', \''+rteID+'\')" ';retval+=style;retval+='onMouseOver="javascript:hlMenuItem(this)" onMouseOut="javascript:dlMenuItem(this)">';retval+='<span style="cursor:default;">';retval+=originalWord;retval+='</span>';retval+='</td></tr>';return retval;}
function mozillaMenuItem(word,wordId,style,rteID)
{var retval='';var wordParts=word.split("'");var originalWord=word;if(wordParts.length==2)
{word=wordParts[0]+"\\"+"'"+wordParts[1];}
retval+='<div style="padding:4px;padding-left:10px;">';retval+='<a style="text-decoration:none;" href="javascript:correctSuggestion(\''+word+'\',\''+wordId+'\',\''+rteID+'\')">';retval+=originalWord;retval+='</a></div>';return retval;}
function editWord(wordId,rteID)
{var input;if(input=prompt('Enter a correct spelling : '))
{if(/^[\s\t]*$/.test(input)==false)
{correctSuggestion(input,wordId,rteID);}}}
function ignoreSuggestion(sug,wordId,rteID)
{speller.dictionary.correctWords.insertKvp(sug,'CORRECT');correctSuggestion(sug,wordId,rteID);}
function ignoreAll(wordId,rteID)
{hideSugMenu();var doc=document.getElementById(rteID).contentWindow.document;var word=doc.getElementById(wordId).innerHTML;clearSuggestion(word,doc.body,rteID);}
function clearSuggestion(word,node,rteID)
{var doc=document.getElementById(rteID).contentWindow.document;var markups=doc.getElementsByTagName('span');var toChange=new Array();for(var i=0;i<markups.length;i++)
{var curSug=markups[i];if(/^HJhrefID/.test(curSug.id))
{if(curSug.innerHTML==word)
{toChange.push(curSug.id);}}}
speller.dictionary.correctWords.insertKvp(word,'CORRECT');for(var i=0;i<toChange.length;i++)
{correctSuggestion(word,toChange[i],rteID);}
return;}
window.clearSug=function(wordId,rteID)
{hideSugMenu();var doc=getObject(rteID).contentWindow.document;var spanObj=doc.getElementById(wordId);var word=spanObj.innerText;var textObj=doc.createTextNode(word);var parent=spanObj.parentNode;parent.replaceChild(textObj,spanObj);}
function correctSuggestion(sug,wordId,rteID)
{if(sug=='(no suggestions)')
{return;}
hideSugMenu();var doc=getObject(rteID).contentWindow.document;var spanObj=doc.getElementById(wordId);var textObj=doc.createTextNode(sug);var parent=spanObj.parentNode;parent.replaceChild(textObj,spanObj);}
function getObject(obj)
{if(document.getElementById)
{obj=document.getElementById(obj);}
else if(document.all)
{obj=document.all.item(obj);}
else
{obj=null;}
return obj;}
function moveObject(objID,e,rteID,spanID)
{var frameLeft=YAHOO.util.Dom.getX(rteID);var frameX=e.clientX;var menuX=frameX+frameLeft;if(rteID!='jdesc'&&menuX>550)
{menuX=525;}
var frameTop=YAHOO.util.Dom.getY(rteID);var frameY=e.clientY;var menuY=frameY+frameTop+12;if(rteID!='jdesc'&&menuY>280)
{menuY=225;}
displayObject(objID,true);YAHOO.util.Dom.setX(objID,menuX);YAHOO.util.Dom.setY(objID,menuY);return;}
function displayObject(obj,show)
{obj=getObject(obj);if(obj==null)
{return;}
obj.style.display=show?'block':'none';obj.style.visibility=show?'visible':'hidden';}