 /**
 * @!!COPYRIGHT
 * Halo (Halofree.com's Ajax, Libraries, and Objects)
 * Copyright (c) 2006, Dustin Hansen. All rights reserved.
 * Code license: http://creativecommons.org/licenses/LGPL/2.1/
 * Version: 0.9.1
 */
if(typeof Halo.words=='undefined'){Halo.words={}}Halo.extend(Halo.words,{VERSION:'0.0.1',NAME:'Halo.words',spellOnly:false,dictionary:"http://en.wiktionary.org/wiki/",URL:document.location.href.replace(/[^\/]*?$/,""),wordList:{},inArray:function(_value,_array){var found=false;if(_array instanceof Object){for(var elem in _array){if(elem==_value){found=true}}}else{for(var i=0;i<_array.length;i++){if(_array[i]==_value){found=true}}}return found},verifyAttempt:function(_specWord){if(($.id('words').value==''||$.id('words').value==default_text)&&!_specWord){$.id('words').focus();FX.highlight({elem:$.id('words'),color:'#FEB'});return false}var theWords=(_specWord&&_specWord.nodeType==1?(Halo.ff?_specWord.textContent:_specWord.innerText):(_specWord?_specWord:$.id('words').value));theWords=theWords.replace(/ ?, ?/g,",");theWords=theWords.replace(/\|/g,",");$.id('words').value=theWords;theWords=theWords.replace(/ /g,"_");var noNew=true;var wordList=theWords.split(",");for(var i=0;i<wordList.length;i++){if(!this.spellOnly&&this.inArray(wordList[i],this.wordList)&&$.id(wordList[i]+"_box")){var nodeClone=$.id(wordList[i]+"_box").cloneNode(true);$.id(wordList[i]+"_box").parentNode.removeChild($.id(wordList[i]+"_box"));$.insertAfter(nodeClone,$.id('spell_actions'));FX.highlight({elem:$.id(wordList[i]+"_box"),color:'#FEB'});delete wordList[i]}else{noNew=false}}theWords=wordList.join(",");theWords=theWords.replace(/,{2,}/g,",");theWords=theWords.replace(/^,|,$/,"");if(noNew){$.id('word_actions').innerHTML=$.id('words').value='';$.id('words').focus()}return(!noNew?theWords:false)},getDefinition:function(_specWord,_checkSpell){var theWords;if(!(theWords=this.verifyAttempt(_specWord))){return false}this.disenableGUI(true);if(_checkSpell&&$.id(_checkSpell+'spelling')){$.id(_checkSpell+'spelling').parentNode.removeChild($.id(_checkSpell+'spelling'))}if(this.spellOnly){this.checkSpelling(theWords);return}new Halo.net.ajax({'method':'GET','url':"/index.php",'timeout':60,'params':"ajax_request=1&word="+encodeURI(theWords),'onError':function(_error){},'onComplete':function(){var wordDefs=parseJSON(this.text);for(var tWord in wordDefs.definitions){var printWord=tWord.replace(/__/g,"'");WORDS.wordList[tWord]=1;var blockHTML='<h3><a href="'+wordDefs.definitions[tWord].source+printWord+'" title="Definition'+' for &quot;'+tWord.replace(/_/g," ")+'&quot; provided by wiktionary.org" ta'+'rget=_new>'+printWord.replace(/_/g," ")+'</a></h3><a href="javascript:void(WORD'+'S.removeWord(\''+tWord+'_box\'))" class="x" title="Remove Word">X</a><dl>';var defFound=0;var tWordDef=wordDefs.definitions[tWord].defines;for(var defTypes in tWordDef){if(tWordDef[defTypes]){if(tWordDef[defTypes].length>0){blockHTML+='<dt>'+defTypes+':</dt><dd>'+tWordDef[defTypes]+'</dd>';defFound=1}}}if(defFound){blockHTML+='</dl>';$.createElement("div",{'class':"wordBlock",'id':tWord+'_box','parent':$.id('word_results'),'after':$.id('spell_actions'),'content':blockHTML})}else{if(WORDS.wordList[tWord]){delete WORDS.wordList[tWord]}$.id('word_actions').innerHTML='"'+$.id('words').value+'" not found.';if(!Halo.util.getCookie("spellCheck")||Halo.util.getCookie("spellCheck")==1){WORDS.checkSpelling(tWord)}else{WORDS.showNotFound(tWord);$.id('words').value='';$.id('words').focus()}}}WORDS.setWordLink();WORDS.disenableGUI(false,(!defFound?true:false))}});return false},checkSpelling:function(_badWord){if(!this.spellOnly){$.id('word_actions').innerHTML=($.id('word_actions').innerHTML.match(/not found/)?'':$.id('word_actions').innerHTML);Halo.DOM.createElement({'elem':'div','parent':$.id('spell_actions'),'id':_badWord+'spelling','content':'"'+_badWord.replace(/_/g," ")+'" not found. Checking spelling...'})}new Halo.net.ajax({'url':'/index.php','method':'GET','args':_badWord,'params':'ajax_request=1&spell_request='+encodeURI(_badWord),'onComplete':function(){if(this.text.match(/^ERROR$/)||this.text==""){if(!WORDS.spellOnly&&WORDS.wordList[this.opts.args]){delete WORDS.wordList[this.opts.args];WORDS.setWordLink()}var theWord=this.opts.args;if(WORDS.spellOnly){$.id('word_actions').innerHTML='"<a href="/'+theWord+'" onclick="WORDS.getDefinition(\''+theWord+'\');return false;">'+theWord+'</a>" is spelled correctly.';FX.highlight({elem:$.id('word_actions'),color:'#FEB'})}else{WORDS.showNotFound(theWord)}}else{if($.id(this.opts.args+'spelling')){$.id(this.opts.args+'spelling').innerHTML='Did you mean: '+this.text+'&nbsp; <a href="javascript:void($.id(\''+this.opts.args+'spelling\').parentNode.removeChild($.id(\''+this.opts.args+'spelling\')))">x</a>'}else{$.id('word_actions').innerHTML='Did you mean: '+this.text}}WORDS.disenableGUI(false,true);$.id('words').value='';$.id('words').focus()}})},showNotFound:function(_theWord){var printWord=_theWord.replace(/_/g," ");$.id('word_actions').innerHTML='"'+printWord+'" is not in our dictionary.<br /> You could <a href="'+WORDS.dictionary+_theWord+'" onclick=\'WORDS.helpOutWiki("'+_theWord+'");return false;\' target="_new">Help out wiktionary</a>, or  <a href="java'+'script:void(WORDS.bugs(\''+printWord+'\'))">Report it</a>';FX.highlight({elem:$.id('word_actions'),color:'#FEB'});if($.id(_theWord+'spelling')){$.id(_theWord+'spelling').parentNode.removeChild($.id(_theWord+'spelling'))}},helpOutWiki:function(_word){if($.id(_word+'spelling')){$.id(_word+'spelling').parentNode.removeChild($.id(_word+'spelling'))}$.id('word_actions').innerHTML="";window.open(WORDS.dictionary+_word);new Halo.net.ajax({'url':'/lib/code/api/wikisends.php?word_sent='+_word})},checkActions:function(_force){var doSpelling=($.id('spellWord')&&$.id('spellWord').checked||_force?'sc':'dw');Halo.util.setCookie("setAction",doSpelling,365);Halo.words.spellOnly=(doSpelling=='sc'?true:false)},disenableGUI:function(_onOff,_noClear){$.id('words').disabled=$.id('get_word').disabled=_onOff;if(!_noClear){$.id('word_actions').innerHTML=(_onOff?(this.spellOnly?"Spell checking:":"Defining:")+" <em>"+$.id('words').value.replace(/\,/g,", ")+"</em>":"")}if(!_onOff&&!_noClear){$.id('words').value='';$.id('words').focus()}},setWordLink:function(){var wordURL='';for(var words in WORDS.wordList){wordURL=words+","+wordURL}wordURL=wordURL.replace(/\,$/,'');$.id('paged_link').setAttribute("href",WORDS.URL+encodeURI(wordURL));$.id('page_link').setAttribute("href",WORDS.URL+encodeURI(wordURL));$.id('page_link').innerHTML="Link to "+(wordURL==''?"Maveno.us":(wordURL.indexOf(",")==-1?"this word":"these words"))},removeWord:function(_id){var theWord=(_id.replace(/_box$/,""));var wordReg="/(,?)"+theWord+"(,?)/e";delete WORDS.wordList[theWord];this.setWordLink();FX.fadeOut({elem:$.id(_id),destroy:true})},createContent:function(){var wordStr=document.location.pathname;if(wordStr.length>1){var initWord=wordStr.substr(1,wordStr.length-1);if(initWord){var initWordList=initWord.split(",");initWordList.reverse();for(var i=0;i<initWordList.length;i++){this.wordList[initWordList[i]]=1}}}WORDS.setWordLink();$.id('words').focus()},openPreferences:function(){if(!$.id('pref_box')){new Halo.net.ajax({'url':"/lib/code/inc/pref-include.php",'method':"GET",'params':"ajax_request=1",'onComplete':function(){document.body.innerHTML+=this.text;Halo.words.showPreferences()}})}else{Halo.words.showPreferences()}},showPreferences:function(){this.setBackdrop($.id('pref_box'),403);var curTheme=Halo.util.getCookie('mavTheme')||"silver";$.id(curTheme+"Theme").checked=true;Halo.util.setOpacity($.id('pref_box'),0);FX.fadeIn({elem:$.id('pref_box'),shades:10,interval:30});if($.id('langSelect').disabled!=true){$.id('langSelect').focus()}},savePreferences:function(){Halo.util.setCookie("spellCheck",($.id('doSpellCheck').checked==true?1:0),'365');Halo.util.setCookie("filterResults",($.id('strictFilter').checked==true?1:0),'365');var newLang=$.id('langSelect').options[$.id('langSelect').options.selectedIndex].value;if(Halo.util.getCookie("lang")&&Halo.util.getCookie("lang")!=newLang){Halo.util.setCookie("lang",newLang,'365');if(confirm("You have changed your language settings.\nWould you like to update the interface now?")){document.location.href=$.id('page_link').href}else{alert("Your settings will be updated once you have refreshed this page.")}}WORDS.checkActions();FX.fadeOut({elem:$.id('pref_box'),shades:10,interval:30});window.setTimeout("WORDS.clearPreferences(1)",320)},clearPreferences:function(_really){if(!_really){FX.fadeOut({elem:$.id('pref_box'),shades:10,interval:30});window.setTimeout("WORDS.clearPreferences(1)",320)}else{$.id('shade_box').style.display=$.id('pref_box').style.display="none"}},openBugReport:function(){if(!$.id('bug_box')){new Halo.net.ajax({'url':"/lib/code/inc/bug-include.php",'method':"GET",'params':"ajax_request=1",'onComplete':function(){document.body.innerHTML+=this.text;Halo.words.showBugReport()}})}else{Halo.words.showBugReport()}},showBugReport:function(){this.setBackdrop($.id('bug_box'),403);Halo.util.setOpacity($.id('bug_box'),0);FX.fadeIn({elem:$.id('bug_box'),shades:10,interval:30});$.id('bug_report').focus()},saveBugreport:function(){new Halo.net.ajax({'url':'/lib/code/api/bugreport.php','method':'POST','params':'bad_value='+encodeURIComponent($.id('bug_report').value)+'&word_list='+encodeURIComponent($.id('words').value),'onComplete':function(){$.id('word_actions').innerHTML="OH MY! Thank you!<br />We will resolve this issue soon...";FX.highlight({elem:$.id('word_actions'),color:'#FEB'});window.setTimeout(function(){$.id('word_actions').innerHTML=""},5000)}});FX.fadeOut({elem:$.id('bug_box'),shades:10,interval:30});window.setTimeout("WORDS.clearBugreport(1)",320)},clearBugreport:function(_really){if(!_really){FX.fadeOut({elem:$.id('bug_box'),shades:10,interval:30});window.setTimeout("WORDS.clearBugreport(1)",320)}else{$.id('shade_box').style.display=$.id('bug_box').style.display="none"}},setBackdrop:function(_elem,_width){this.bWidth=document.body.clientWidth;this.bHeight=(document.documentElement.scrollHeight>document.documentElement.clientHeight?document.documentElement.scrollHeight:document.documentElement.clientHeight);$.id('shade_box').style.width=this.bWidth+"px";$.id('shade_box').style.height=this.bHeight+"px";Halo.util.setOpacity($.id('shade_box'),65);$.id('shade_box').style.display=_elem.style.display="block";_elem.style.top=(document.documentElement.scrollTop+50)+"px";_elem.style.left=((this.bWidth-403)/2)+"px"},setLanguageType:function(){$.id('compLangSelect').disabled=$.id('compLangDefCB').checked;$.id('langSelect').disabled=$.id('langDefCB').checked},bugs:function(_badValue){new Halo.net.ajax({'url':"/lib/code/api/bugreport.php?bad_value="+_badValue,'method':"GET",'onWait':function(){},'onComplete':function(){$.id('word_actions').innerHTML="OH MY! Thank you!<br />We will resolve this issue soon...";FX.highlight({elem:$.id('word_actions'),color:'#FEB'});window.setTimeout(function(){$.id('word_actions').innerHTML=""},5000)}})}});if(typeof WORDS=='undefined'&&Halo.shortcuts){WORDS=Halo.words}function parseJSON(_json){eval("var oJSON = "+_json);return oJSON}function halo_init(){var setAction=Halo.util.getCookie("setAction");$.id('spellWord').checked=Halo.words.spellOnly=(setAction=='sc'?true:false);$.id('words').disabled=$.id('get_word').disabled=false;WORDS.createContent();Halo.util.addEvent(document,'keydown',function(e){var event=e?e:window.event;var srcElem=event.srcElement?event.srcElement:event.target;if(event.keyCode==13&&srcElem&&srcElem.id=="words"){Halo.words.spellOnly=(event.shiftKey?true:false)}},true)}
