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