var IPS_Lite_Editor=new Array();function ips_text_editor_lite(a){this.editor_id=a;this.control_obj=document.getElementById(a+"-controls");this.initialized=false;this.buttons=new Array();this.fonts=new Array();this.state=new Array();this.text_obj=document.getElementById(this.editor_id+"_textarea");this.open_brace="[";this.close_brace="]";this.editor_document=this.text_obj;this.editor_window=this.editor_document;this._ie_cache=null;this.is_ie=is_ie;this.is_moz=is_moz;this.is_opera=is_opera;this.has_focus=false;this.emoticon_window_id=null;this.init=function(){var c=new Array();if(!this.control_obj){return}var b=this.control_obj.getElementsByTagName("DIV");for(var d=0;d<b.length;d++){if((b[d].className=="rte-normal"||b[d].className=="rte-menu-button"||b[d].className=="rte-normal-menubutton")&&b[d].id){c[c.length]=b[d].id}}for(var d=0;d<c.length;d++){var e=document.getElementById(c[d]);if(e.className=="rte-normal"){this.init_editor_button(e)}else{if(e.className=="rte-menu-button"||e.className=="rte-normal-menubutton"){this.init_editor_popup_button(e)}}}this.text_obj.onfocus=ips_editor_events.prototype.editor_window_onfocus;this.text_obj.onblur=ips_editor_events.prototype.editor_window_onblur;if(this.editor_document.addEventListener){this.editor_document.addEventListener("keypress",ips_editor_events.prototype.editor_document_onkeypress,false)}};this.editor_check_focus=function(){if(!this.text_obj.has_focus){if(this.is_opera){this.text_obj.focus()}try{this.text_obj.focus()}catch(b){return false}}return true};this.init_editor_button=function(b){b.cmd=b.id.replace(new RegExp("^"+this.editor_id+"_cmd_(.+?)$"),"$1");b.editor_id=this.editor_id;this.buttons[b.cmd]=b;b.state=false;b.mode="normal";b.real_type="button";b.onclick=ips_editor_events.prototype.button_onmouse_event;b.onmousedown=ips_editor_events.prototype.button_onmouse_event;b.onmouseover=ips_editor_events.prototype.button_onmouse_event;b.onmouseout=ips_editor_events.prototype.button_onmouse_event};this.set_button_context=function(d,c,b){if(typeof b=="undefined"){b="button"}switch(d.state){case true:switch(c){case"mouseout":this.editor_set_ctl_style(d,"button","selected");break;case"mouseover":case"mousedown":case"mouseup":this.editor_set_ctl_style(d,b,"down");break}break;default:switch(c){case"mouseout":this.editor_set_ctl_style(d,b,"normal");break;case"mousedown":this.editor_set_ctl_style(d,b,"down");break;case"mouseover":case"mouseup":this.editor_set_ctl_style(d,b,"hover");break}break}};this.editor_set_ctl_style=function(f,c,g){if(f.mode!=g){var b="";if(c=="menu"){b="-menu"}else{if(c=="menubutton"){b="-menubutton"}}b+=f.colorname?"-color":"";b+=f.emo_id?"-emo":"";f.mode=g;try{switch(g){case"normal":f.className="rte-normal"+b;break;case"hover":f.className="rte-hover"+b;break;case"selected":case"down":f.className="rte-selected"+b;break}}catch(d){}}};this.format_text=function(d,f,c){d=ipsclass.cancel_bubble(d,true);if(f.match(/resize_/)){this.resize_editorbox(f.replace(/.+?resize_(up|down)/,"$1"))}if(f.match(/emoticon/)){this.show_all_emoticons()}this.editor_check_focus();if(this[f]){var b=this[f](d)}else{try{var b=this.apply_formatting(f,false,(typeof c=="undefined"?true:c))}catch(d){var b=false}}this.editor_check_focus();return b};this.createlink=function(){var b=prompt(ipb_global_lang.editor_enter_url,"http://");if(!b||b==null||b=="http://"){return false}var c=this.get_selection();c=c?c:prompt(ipb_global_lang.editor_enter_title);if(!c||c==null){return false}this.wrap_tags("url",b,c)};this.insertimage=function(){var c=this.get_selection();var b=prompt(ipb_global_lang.editor_enter_image,c?c:"http://");if(!b||b==null||b=="http://"){return false}this.wrap_tags("img",false,b)};this.ipb_quote=function(){var b=this.get_selection();this.wrap_tags("quote",false,b)};this.ipb_code=function(){var b=this.get_selection();this.wrap_tags("code",false,b)};this.apply_formatting=function(e,b,c){switch(e){case"bold":case"italic":case"underline":this.wrap_tags(e.substr(0,1),false);return;case"justifyleft":case"justifycenter":case"justifyright":this.wrap_tags(e.substr(7),false);return;case"indent":this.wrap_tags(e,false);return;case"createlink":var d=this.get_selection();if(d){this.wrap_tags("url",c)}else{this.wrap_tags("url",c,c)}return;case"fontname":this.wrap_tags("font",c);return;case"fontsize":this.wrap_tags("size",c);return;case"forecolor":this.wrap_tags("color",c);return;case"backcolor":this.wrap_tags("background",c);return;case"insertimage":this.wrap_tags("img",false,c);return;case"strikethrough":this.wrap_tags("strike",false);return;case"superscript":this.wrap_tags("sup",false);return;case"subscript":this.wrap_tags("sub",false);return;case"removeformat":return}};this.wrap_tags=function(i,d,h){var b=i;if(typeof h=="undefined"){h=this.get_selection();h=(h===false)?"":new String(h)}if(d===true){var c=prompt(ips_language_array.js_rte_optionals?ips_language_array.js_rte_optionals:"Enter the optional arguments for this tag","");if(c){var f=this.open_brace+i+'="'+c+'"'+this.close_brace}else{return false}}else{if(d!==false){var f=this.open_brace+i+'="'+d+'"'+this.close_brace}else{var f=this.open_brace+i+this.close_brace}}var e=this.open_brace+"/"+b+this.close_brace;var g=f+h+e;this.insert_text(g);return false};this.wrap_tags_lite=function(c,b){selected_text=this.get_selection();selected_text=(selected_text===false)?"":new String(selected_text);this.insert_text(c+selected_text+b);return false};this.editor_get_contents=function(){return this.editor_document.value};this.get_selection=function(){if(typeof(this.editor_document.selectionStart)!="undefined"){return this.editor_document.value.substr(this.editor_document.selectionStart,this.editor_document.selectionEnd-this.editor_document.selectionStart)}else{if((document.selection&&document.selection.createRange)||this._ie_cache){return this._ie_cache?this._ie_cache.text:document.selection.createRange().text}else{if(window.getSelection){return window.getSelection()+""}else{return false}}}};this.insert_text=function(e){if(this.editor_check_focus()==false){return false}if(typeof(this.editor_document.selectionStart)!="undefined"){var c=this.editor_document.selectionStart+0;var b=this.editor_document.scrollTop;this.editor_document.value=this.editor_document.value.substr(0,this.editor_document.selectionStart)+e+this.editor_document.value.substr(this.editor_document.selectionEnd);if(!e.match(new RegExp("\\"+this.open_brace+"(\\S+?)\\"+this.close_brace+"\\"+this.open_brace+"/(\\S+?)\\"+this.close_brace))){this.editor_document.selectionStart=c;this.editor_document.selectionEnd=c+e.length;this.editor_document.scrollTop=b}}else{if((document.selection&&document.selection.createRange)||this._ie_cache){var d=this._ie_cache?this._ie_cache:document.selection.createRange();d.text=e.replace(/\r?\n/g,"\r\n");d.select()}else{this.editor_document.value+=e}}this._ie_cache=null};this.show_all_emoticons=function(){if(typeof(this.emoticon_window_id)!=null){this.emoticon_window_id=window.open(ipb_var_base_url+"act=legends&CODE=emoticons&_lite=1&editor_id="+a,"Legends","width=250,height=500,resizable=yes,scrollbars=yes")}else{this.emoticon_window_id.focus()}return false};this.insert_emoticon=function(d,e,b,c){b=ipsclass.un_htmlspecialchars(b);this.wrap_tags_lite(" "+b," ");if(this.is_ie){if(IPS_Lite_Editor[this.editor_id].emoticon_window_id!=""&&typeof(IPS_Lite_Editor[this.editor_id].emoticon_window_id)!="undefined"){IPS_Lite_Editor[this.editor_id].emoticon_window_id.focus()}}};this.resize_editorbox=function(e){var c=100;var d=parseInt(this.text_obj.style.height);var b=0;d=d?d:200;if(d>=50){if(e=="up"){b=d-c}else{b=d+c}if(b>149){this.text_obj.style.height=b+"px"}}}}function ips_editor_events(){}ips_editor_events.prototype.button_onmouse_event=function(a){if(is_ie){a=ipsclass.cancel_bubble(a,true)}if(a.type=="click"){IPS_Lite_Editor[this.editor_id].format_text(a,this.cmd,false,true)}IPS_Lite_Editor[this.editor_id].set_button_context(this,a.type)};ips_editor_events.prototype.editor_window_onfocus=function(a){this.has_focus=true};ips_editor_events.prototype.editor_window_onblur=function(a){this.has_focus=false};ips_editor_events.prototype.editor_document_onkeypress=function(a){if(a.ctrlKey){switch(String.fromCharCode(a.charCode).toLowerCase()){case"b":cmd="bold";break;case"i":cmd="italic";break;case"u":cmd="underline";break;default:return}a.preventDefault();IPS_Lite_Editor[this.editor_id].apply_formatting(cmd,false,null);return false}};

