/* Copyright © Yogotopia.com. All Rights Reserved. */
var spellchk_curr_lang=null;var spellchk_default_lang="en";function spell_check(){var lang;var cookie_value=ART.read_cookie('language');if(cookie_value!=null)spellchk_curr_lang=cookie_value;else spellchk_curr_lang=spellchk_default_lang;this.org_lang_to_word={"de":"Deutsch","en":"English","es":"Espa&#241;ol","fr":"Fran&#231;ais","it":"Italiano","nl":"Nederlands","pl":"Polski","pt":"Portugu&#234;s"};this.lang_to_word=this.org_lang_to_word;this.langlist_codes=ART.keys(this.lang_to_word);this.show_change_lang_pic=true;this.change_lang_pic_placement="left";this.report_state_change=true;this.ta_scroll_top=0;this.el_scroll_top=0;this.lang_chck_spell="check spelling";this.lang_revert="back to";this.lang_close="close";this.lang_rsm_edt="resume editing";this.lang_no_error_found="no errors found";this.lang_no_suggestions="no suggestions";this.show_spell_img=true;this.decoration=true;this.use_close_btn=true;this.edit_layer_dbl_click=true;this.report_ta_not_found=true;this.custom_ajax_error=null;this.custom_no_spelling_error=null;this.custom_menu_builder=[];this.custom_item_evaulator=null;this.extra_menu_items=[];this.custom_spellcheck_starter=null;this.main_controller=true;this.lang_state_observer=null;this.spelling_state_observer=null;this.show_menu_observer=null;this.all_errors_fixed_observer=null;this.use_focus=false;this.focus_link_t=null;this.focus_link_b=null;this.cnt_errors=0;this.cnt_errors_fixed=0;var fn=function(e){var elm=ART.get_event_element(e);if(elm.spellchk_action_btn!="1"&&this.isLangWindowShown())this.hideLangWindow();if(elm.spellchk_action_btn!="1"&&this.is_error_window_shown())this.hide_error_window();};ART.AEV(document,"click",ART.bind(fn,this));}spell_check.prototype.deco_textarea=function(id,where_to_insert){if(typeof(id)=="string")this.text_area=ART.GE(id);else this.text_area=id;var r_width,r_height;if(this.text_area!=null){if(!ART.is_defined(this.spell_container)&&this.decoration){var rte=ART.SPAN({'id':'rte','class':'rte'});var chkspell=ART.SPAN({'id':'chkspell','class':'chkspell'});var rich_txt_edit=ART.DIV({'id':'rich_txt_edit','class':'rich_txt_edit'},rte,chkspell);this.spell_container=chkspell;if(where_to_insert)ART.ACN(ART.GE(where_to_insert),rich_txt_edit);else ART.IB(rich_txt_edit,this.text_area);}this.check_spelling_state();}else if(this.report_ta_not_found)alert("text area not found");};spell_check.prototype.set_langs=function(lang_dict){this.lang_to_word=lang_dict;this.langlist_codes=ART.keys(lang_dict);};spell_check.prototype.no_close_btn=function(){this.use_close_btn=false;};spell_check.prototype.append_menu_item=function(name,call_back_fn,checker){this.extra_menu_items.push([name,call_back_fn,checker]);};spell_check.prototype.append_menu_builder=function(eval,builder){this.custom_menu_builder.push([eval,builder]);};spell_check.prototype.set_focus=function(){try{this.focus_link_b.focus();this.focus_link_t.focus();return true;}catch(e){return false;}};spell_check.prototype.set_state_changed=function(current_state){this.state=current_state;if(this.spelling_state_observer!=null&&this.report_state_change)this.spelling_state_observer(current_state,this);};spell_check.prototype.set_report_state_change=function(bool){this.report_state_change=bool;};spell_check.escape_special=function(val){return val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");};spell_check.prototype.check_spelling=function(ignore){var me=this;this.cnt_errors_fixed=0;this.cnt_errors=0;this.set_state_changed("checking_spell");if(this.main_controller)this.append_indicator(this.spell_span);this.error_links=[];this.ta_scroll_top=this.text_area.scrollTop;try{this.hideLangWindow();}catch(e){}this.create_edit_layer(this.text_area.offsetWidth,this.text_area.offsetHeight);this.create_error_window();ART.get_body().appendChild(this.error_window);try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");}catch(e){}if(this.main_controller)this.spell_span.onclick=null;this.orginal_text=this.text_area.value;if(this.text_area.value==''||ignore){if(!me.custom_no_spelling_error)me.flash_no_error_state();else me.custom_no_spelling_error(me);me.removeIndicator();return;}ART.processing('on');var req_text=spell_check.escape_special(this.orginal_text.split('> ------ Previous Message ------')[0]);var file='/executions/spellcheck.cfm';var str='lang='+spellchk_curr_lang+'&text='+ART.format_msg(req_text);var req=zXmlHttp.createRequest();req.open("POST",file,true);req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");req.onreadystatechange=function(){if(req.readyState==4){ART.processing('off');if(req.status==200){var r_text=req.responseText;me.results=me.parse_result(r_text);if(r_text.match(/<c.*>/)!=null){me.show_errors_in_iframe();me.resumeEditingState();}else{if(!me.custom_no_spelling_error)me.flash_no_error_state();else me.custom_no_spelling_error(me);}me.removeIndicator();}else{ERRORS.show('-1000');if(me.main_controller){ART.remove_element(me.spell_span);me.removeIndicator();}me.check_spelling_state();}}};req.send(str);};spell_check.prototype.parse_result=function(r_text){var re_split_attr_c=/\w+="(\d+|true)"/g;var re_split_text=/\t/g;var matched_c=r_text.match(/<c[^>]*>[^<]*<\/c>/g);var results=new Array();if(matched_c==null)return results;for(var i=0;i<matched_c.length;i++){var item=new Array();this.error_found();item['attrs']=new Array();var split_c=matched_c[i].match(re_split_attr_c);for(var j=0;j<split_c.length;j++){var c_attr=split_c[j].split(/=/);var val=c_attr[1].replace(/"/g,'');if(val!="true")item['attrs'][c_attr[0]]=parseInt(val);else{item['attrs'][c_attr[0]]=val;}}item['suggestions']=new Array();var only_text=matched_c[i].replace(/<[^>]*>/g,"");var split_t=only_text.split(re_split_text);for(var k=0;k<split_t.length;k++){if(split_t[k]!="")item['suggestions'].push(split_t[k]);}results.push(item);}return results;};spell_check.prototype.error_fixed=function(){this.cnt_errors_fixed++;if(this.all_errors_fixed_observer)if(this.cnt_errors_fixed==this.cnt_errors){this.hide_error_window();this.all_errors_fixed_observer();}};spell_check.prototype.error_found=function(){this.cnt_errors++;};spell_check.prototype.create_error_window=function(){this.error_window=ART.DIV();this.error_window.className="spellcheck_box";this.error_window.spellchk_action_btn="1";};spell_check.prototype.is_error_window_shown=function(){return this.error_window!=null&&this.error_window.style.visibility=="visible";};spell_check.prototype.hide_error_window=function(){try{this.error_window.style.visibility="hidden";if(this.error_window_iframe)this.error_window_iframe.style.visibility="hidden";}catch(e){}};spell_check.prototype.update_orgin_text=function(offset,old_value,new_value,id){var part_1=this.orginal_text.substring(0,offset);var part_2=this.orginal_text.substring(offset+old_value.length);this.orginal_text=part_1+new_value+part_2;this.text_area.value=this.orginal_text;var add_2_offset=new_value.length-old_value.length;for(var j=0;j<this.results.length;j++){if(j!=id&&j>id){this.results[j]['attrs']['o']+=add_2_offset;}}};spell_check.prototype.save_old_value=function(elm,old_value){elm.is_changed=true;elm.old_value=old_value;};spell_check.prototype.create_list_divider=function(){var e_col=ART.TD(" ");e_col.spellchk_action_btn="1";e_col.style.cursor="default";e_col.style.fontSize="3px";e_col.style.borderTop="1px solid #CCCCCC";e_col.style.paddingTop="3px";return ART.TR(e_col);};spell_check.prototype.correct_error=function(id,elm,l_elm,rm_pre_space){var old_value=elm.innerHTML;var new_value=l_elm.innerHTML;var offset=this.results[id]['attrs']['o'];if(rm_pre_space){var pre_length=elm.previousSibling.innerHTML;elm.previousSibling.innerHTML=pre_length.slice(0,pre_length.length-1);old_value=" "+old_value;offset--;}this.hide_error_window();this.update_orgin_text(offset,old_value,new_value,id);elm.innerHTML=new_value;elm.style.color="#000000";elm.style.backgroundColor="#FFFFFF";elm.is_corrected=true;this.results[id]['attrs']['l']=new_value.length;if(!ART.is_defined(elm.old_value))this.save_old_value(elm,old_value);this.error_fixed();};spell_check.prototype.show_error_window=function(elm,id){if(this.show_menu_observer)this.show_menu_observer(this);var me=this;var abs_pos=ART.absolute_pos(elm);abs_pos.y-=this.edit_layer.scrollTop;this.error_window.style.visibility="visible";ART.set_top(this.error_window,(abs_pos.y+20));ART.set_left(this.error_window,(abs_pos.x));this.error_window.innerHTML="";var table=ART.TABLE({'class':'spellchk_list'});table.spellchk_action_btn="1";var list=ART.TBODY();var changed=false;if(this.custom_menu_builder!=[]){for(var k=0;k<this.custom_menu_builder.length;k++){var eb=this.custom_menu_builder[k];if(eb[0]((this.results[id]))){changed=eb[1](this,list,elm);break;}}}if(!changed){var suggestions=this.results[id]['suggestions'];var offset=this.results[id]['attrs']['o'];var len=this.results[id]['attrs']['l'];if(suggestions.length==0){var row=ART.TR();var item=ART.TD({'style':'cursor: default;'});var dummy=ART.SPAN();dummy.innerHTML=this.lang_no_suggestions;ART.ACN(item,ART.TN(dummy.innerHTML));item.spellchk_action_btn="1";row.appendChild(item);list.appendChild(row);}for(i=0;i<suggestions.length;i++){var row=ART.TR();var item=ART.TD();var dummy=ART.SPAN();dummy.innerHTML=suggestions[i];item.appendChild(ART.TN(dummy.innerHTML));var fn=function(e){var l_elm=ART.get_event_element(e);this.correct_error(id,elm,l_elm);};ART.AEV(item,"click",ART.bind(fn,this));item.onmouseover=spell_check.item_onmouseover;item.onmouseout=spell_check.item_onmouseout;row.appendChild(item);list.appendChild(row);}if(elm.is_changed&&elm.innerHTML!=elm.old_value){var old_value=elm.old_value;var revert_row=ART.TR();var revert=ART.TD();revert.onmouseover=spell_check.item_onmouseover;revert.onmouseout=spell_check.item_onmouseout;var rev_span=ART.SPAN({'class':'spellchk_list_revert'});rev_span.innerHTML=this.lang_revert+" "+old_value;revert.appendChild(rev_span);var fn=function(e){this.update_orgin_text(offset,elm.innerHTML,old_value,id);elm.is_corrected=true;elm.style.color="#b91414";elm.innerHTML=old_value;this.hide_error_window();};ART.AEV(revert,"click",ART.bind(fn,this));revert_row.appendChild(revert);list.appendChild(revert_row);}if(this.extra_menu_items.length>0)ART.ACN(list,this.create_list_divider());var loop=function(i){if(i<me.extra_menu_items.length){var e_elm=me.extra_menu_items[i];if(!e_elm[2]||e_elm[2](elm,me)){var e_row=ART.TR();var e_col=ART.TD(e_elm[0]);e_col.onmouseover=spell_check.item_onmouseover;e_col.onmouseout=spell_check.item_onmouseout;var fn=function(){return e_elm[1](elm,me);};ART.AEV(e_col,"click",fn);ART.ACN(e_row,e_col);ART.ACN(list,e_row);}loop(i+1);}};loop(0);loop=null;}table.appendChild(list);this.error_window.appendChild(table);if(gBrowser.browser=='Explorer'&&!this.error_window_iframe){var iframe=ART.IFRAME({'style':'position: absolute; z-index: 0;'});ART.ACN(ART.get_body(),iframe);this.error_window_iframe=iframe;}if(gBrowser.browser=='Explorer'){var iframe=this.error_window_iframe;ART.set_top(iframe,this.error_window.offsetTop);ART.set_left(iframe,this.error_window.offsetLeft);ART.set_width(iframe,this.error_window.offsetWidth);ART.set_height(iframe,this.error_window.offsetHeight);iframe.style.visibility="visible";}var link=this.createFocusLink('link');list.appendChild(ART.TR(ART.TD({'style':'text-align: right; font-size: 1px; height: 1px; margin: 0; padding: 0;'},link)));link.focus();};spell_check.prototype.create_edit_layer=function(width,height){this.edit_layer=ART.DIV({'class':'spellchk_edit_layer'});this.edit_layer.className=this.text_area.className;this.edit_layer.style.border="1px solid #999999";this.edit_layer.style.backgroundColor="#FFFFFF";this.edit_layer.style.padding="3px";this.edit_layer.style.margin="0px";ART.set_width(this.edit_layer,(width-8));if(ART.node_name(this.text_area)!="input"||this.text_area.value==""){this.edit_layer.style.overflow="auto";ART.set_height(this.edit_layer,(height-6));}else{this.edit_layer.style.overflow="hidden";}if(this.edit_layer_dbl_click){var me=this;var fn=function(e){if(ART.get_event_element(e).className!="spellchk_link"&&!me.is_error_window_shown()){me.resumeEditing();var fn1=function(){me.text_area.focus();fn1=null;};ART.call_later(fn1,10);}return false;};this.edit_layer.ondblclick=fn;fn=null;}};spell_check.prototype.resumeEditing=function(){this.set_state_changed("spell_check");this.switch_lan_pic.style.display="inline";this.el_scroll_top=this.edit_layer.scrollTop;this.hide_error_window();try{this.edit_layer.parentNode.removeChild(this.edit_layer);if(this.use_focus){ART.remove_element(this.focus_link_t);ART.remove_element(this.focus_link_b);}}catch(e){}ART.show_element(this.text_area);if(this.main_controller)this.spell_span.className="spellchk_no_style";this.text_area.scrollTop=this.el_scroll_top;elm.onmouseout=null;this.check_spelling_state(false);};spell_check.prototype.create_error_link=function(text,id){var elm=ART.SPAN({'class':'spellchk_link'});var me=this;var d=function(e){me.show_error_window(elm,id);d=null;return false;};ART.AEV(elm,"click",d);elm.spellchk_action_btn="1";elm.g_id=id;elm.is_corrected=false;elm.oncontextmenu=d;elm.innerHTML=text;return elm;};spell_check.create_part=function(txt_part){if(txt_part==" ")return ART.TN(" ");var result=ART.SPAN();var is_first=true;var is_safari=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1);var part=ART.SPAN();txt_part=spell_check.escape_special(txt_part);txt_part=txt_part.replace(/\n/g,"<br>");txt_part=txt_part.replace(/    /g," &nbsp;");txt_part=txt_part.replace(/^ /g,"&nbsp;");txt_part=txt_part.replace(/ $/g,"&nbsp;");part.innerHTML=txt_part;return part;};spell_check.prototype.show_errors_in_iframe=function(){var output=ART.DIV();output.style.textAlign="left";var pointer=0;var results=this.results;if(results.length>0){for(var i=0;i<results.length;i++){var offset=results[i]['attrs']['o'];var len=results[i]['attrs']['l'];var part_1_text=this.orginal_text.substring(pointer,offset);var part_1=spell_check.create_part(part_1_text);output.appendChild(part_1);pointer+=offset-pointer;var err_link=this.create_error_link(this.orginal_text.substr(offset,len),i);this.error_links.push(err_link);output.appendChild(err_link);pointer+=len;}var part_2_text=this.orginal_text.substr(pointer,this.orginal_text.length);var part_2=spell_check.create_part(part_2_text);output.appendChild(part_2);}else output.innerHTML=this.orginal_text;var me=this;if(this.custom_item_evaulator)ART.map(this.error_links,function(elm){me.custom_item_evaulator(me,elm)});ART.ACN(this.edit_layer,output);this.text_area_bottom=this.text_area.offsetTop+this.text_area.offsetHeight;ART.hide_element(this.text_area);ART.IB(this.edit_layer,this.text_area);if(this.use_focus){this.focus_link_t=this.createFocusLink('focus_t');this.focus_link_b=this.createFocusLink('focus_b');ART.IB(this.focus_link_t,this.edit_layer);ART.IA(this.focus_link_b,this.edit_layer);}this.edit_layer.scrollTop=this.ta_scroll_top;};spell_check.prototype.createLangWindow=function(){this.language_window=ART.DIV({'class':'spellcheck_box'});ART.set_width(this.language_window,100);this.language_window.spellchk_action_btn="1";var table=ART.TABLE({'class':'spellchk_list'});ART.set_width(table,"100%");var list=ART.TBODY();this.lang_elms=new Array();for(i=0;i<this.langlist_codes.length;i++){var row=ART.TR();var item=ART.TD();item.spellchkId=this.langlist_codes[i];this.lang_elms.push(item);var lang_span=ART.SPAN();lang_span.innerHTML=this.lang_to_word[this.langlist_codes[i]];item.appendChild(ART.TN(lang_span.innerHTML));var fn=function(e){var elm=ART.get_event_element(e);this.deHighlightCurSel();this.setCurrentLanguage(elm.spellchkId);if(this.lang_state_observer!=null){this.lang_state_observer();}this.highlightCurSel();this.hideLangWindow();};ART.AEV(item,"click",ART.bind(fn,this));item.onmouseover=function(e){var i_it=ART.get_event_element(e);if(i_it.className!="spellchk_list_selected")i_it.className="spellchk_list_onhover";};item.onmouseout=function(e){var i_it=ART.get_event_element(e);if(i_it.className!="spellchk_list_selected")i_it.className="spellchk_list_onout";};row.appendChild(item);list.appendChild(row);}this.highlightCurSel();table.appendChild(list);this.language_window.appendChild(table);};spell_check.prototype.setCurrentLanguage=function(lan_code){spellchk_curr_lang=lan_code;var now=new Date();now.setTime(now.getTime()+365*24*60*60*1000);ART.create_cookie('language',lan_code,now);};spell_check.prototype.isLangWindowShown=function(){return this.language_window!=null&&this.language_window.style.visibility=="visible";};spell_check.prototype.hideLangWindow=function(){try{this.language_window.style.visibility="hidden";this.switch_lan_pic.className="spellchk_lang_3d_on";}catch(e){}};spell_check.prototype.deHighlightCurSel=function(){this.lang_cur_elm.className="spellchk_list_onout";};spell_check.prototype.highlightCurSel=function(){if(spellchk_curr_lang==null)spellchk_curr_lang=spellchk_default_lang;for(var i=0;i<this.lang_elms.length;i++){if(this.lang_elms[i].spellchkId==spellchk_curr_lang){this.lang_elms[i].className="spellchk_list_selected";this.lang_cur_elm=this.lang_elms[i];}else{this.lang_elms[i].className="spellchk_list_onout";}}};spell_check.prototype.show_lang_window=function(elm,ofst_top,ofst_left){if(this.show_menu_observer)this.show_menu_observer(this);if(!ART.is_defined(ofst_top))ofst_top=20;if(!ART.is_defined(ofst_left))ofst_left=100;this.createLangWindow();ART.get_body().appendChild(this.language_window);var abs_pos=ART.absolute_pos(elm);ART.show_element(this.language_window);ART.set_top(this.language_window,(abs_pos.y+ofst_top));ART.set_left(this.language_window,(abs_pos.x+ofst_left-this.language_window.offsetWidth));this.highlightCurSel();this.language_window.style.visibility="visible";};spell_check.prototype.create_change_lang_pic=function(){var img=ART.IMG({'src':'http://images.spicypage.com/leftmenu_down_14x9.gif','alt':'Change language'});img.spellchk_action_btn="1";var switch_lan=ART.SPAN({'class':'spellchk_lang_3d_on','style':'padding-left: 6px;'},img);var fn=function(e){var elm=ART.get_event_element(e);if(ART.node_name(elm)=='img')elm=elm.parentNode;if(elm.className=="spellchk_lang_3d_click"){elm.className="spellchk_lang_3d_on";this.hideLangWindow();}else{elm.className="spellchk_lang_3d_click";this.show_lang_window(switch_lan);}};ART.AEV(switch_lan,"click",ART.bind(fn,this));return switch_lan;};spell_check.prototype.createSpellDiv=function(){var chk_spell=ART.SPAN({'class':'spellchk_check_spelling_link'});chk_spell.innerHTML=this.lang_chck_spell;var spell_img=null;return ART.SPAN(spell_img," ",chk_spell);};spell_check.prototype.flash_no_error_state=function(on_finish){var no_spell_errors;if(on_finish){var fn=function(){on_finish();this.check_spelling_state();};no_spell_errors=fn;}else no_spell_errors=this.check_spelling_state;this.set_state_changed("no_error_found");if(this.main_controller){ART.hide_element(this.switch_lan_pic);var dummy=ART.IMG({'src':'http://images.spicypage.com/x.gif','style':'height: 12px; width: 1px;'});var rsm=ART.SPAN();rsm.innerHTML=this.lang_no_error_found;ART.RCN(this.spell_span,ART.SPAN(dummy,rsm));this.spell_span.className="spellchk_check_spelling_ok";this.spell_span.style.textDecoration="none";this.spell_span.style.cursor="default";ART.call_later(ART.bind(no_spell_errors,this),1200,[false]);}};spell_check.prototype.resumeEditingState=function(){this.set_state_changed("resume_editing");if(this.main_controller){ART.hide_element(this.switch_lan_pic);var dummy=ART.IMG({'src':'http://images.spicypage.com/x.gif','style':'height:12px; width:1px;'});var rsm=ART.SPAN({'class':'spellchk_resume_editing'});rsm.innerHTML=this.lang_rsm_edt;ART.RCN(this.spell_span,ART.SPAN(dummy,rsm));var fn=function(e){this.resumeEditing();};this.spell_span.onclick=ART.bind(fn,this);this.spell_span.className="spellchk_resume_editing";}try{this.edit_layer.scrollTop=this.ta_scroll_top;}catch(e){}};spell_check.prototype.check_spelling_state=function(fire){if(!ART.is_defined(fire)||fire)this.set_state_changed("spell_check");if(this.show_change_lang_pic)this.switch_lan_pic=this.create_change_lang_pic();else this.switch_lan_pic=ART.SPAN();var span_chck=this.createSpellDiv();var fn=function(){this.check_spelling();};if(this.custom_spellcheck_starter)span_chck.onclick=this.custom_spellcheck_starter;else{span_chck.onclick=ART.bind(fn,this);}this.spell_span=span_chck;if(this.main_controller){if(this.change_lang_pic_placement=="left")ART.RCN(this.spell_container,span_chck," ",this.switch_lan_pic);else ART.RCN(this.spell_container,this.switch_lan_pic," ",span_chck);}};spell_check.item_onmouseover=function(e){var elm=ART.get_event_element(e);if(elm.className!="spellchk_list_revert"&&elm.className!="spellchk_list_close")elm.className="spellchk_list_onhover";else elm.parentNode.className="spellchk_list_onhover";};spell_check.item_onmouseout=function(e){var elm=ART.get_event_element(e);if(elm.className!="spellchk_list_revert"&&elm.className!="spellchk_list_close")elm.className="spellchk_list_onout";else elm.parentNode.className="spellchk_list_onout";};spell_check.prototype.removeIndicator=function(elm){try{ART.remove_element(this.indicator);}catch(e){}};spell_check.prototype.append_indicator=function(elm){var _loading=ART.DIV({'class':'loading inline'},'checking...');var _elm_html=elm.innerHTML;try{elm.innerHTML='';ART.ACN(elm,_loading);}catch(e){}};spell_check.prototype.createFocusLink=function(name){return ART.A({'href':'javascript:;',name:name});};
