function BBCode(_1){
this.construct(_1);
}
BBCode.prototype={VK_TAB:9,VK_ENTER:13,VK_PAGE_UP:33,BRK_OP:"[",BRK_CL:"]",textarea:null,stext:"",quoter:null,collapseAfterInsert:false,replaceOnInsert:false,construct:function(_2){
this.textarea=_2;
this.tags=new Object();
this.addTag("_quoter",function(){
return "[quote=\""+th.quoter+"\"]";
},"[/quote]\n",null,null,function(){
th.collapseAfterInsert=true;
return th._prepareMultiline(th.quoterText);
});
var th=this;
addEvent(_2,"onkeydown",function(e){
return th.onKeyPress(e,window.HTMLElement?"down":"press");
});
addEvent(_2,"onkeypress",function(e){
return th.onKeyPress(e,"press");
});
},onclickPoster:function(_6){
var _7=this.getSelection()[0];
if(_7){
this.quoter=_6;
this.quoterText=_7;
this.insertTag("_quoter");
}else{
this.insertAtCursor("[b]"+_6+"[/b]\n");
}
return false;
},onclickQuoteSel:function(){
var _8=this.getSelection()[0];
if(_8){
this.insertAtCursor("[quote]"+_8+"[/quote]\n");
}else{
alert("Please select text.");
}
return false;
},emoticon:function(em){
if(em){
this.insertAtCursor(" "+em+" ");
}else{
return false;
}
return false;
},refreshSelection:function(_a){
if(_a){
this.stext=this.getSelection()[0];
}else{
this.stext="";
}
},getSelection:function(){
var w=window;
var _c="",range;
if(w.getSelection){
_c=w.getSelection();
}else{
if(w.document.getSelection){
_c=w.document.getSelection();
}else{
if(w.document.selection&&w.document.selection.createRange){
range=w.document.selection.createRange();
_c=range.text;
}else{
return [null,null];
}
}
}
if(_c==""){
_c=this.stext;
}
_c=""+_c;
_c=_c.replace("/^s+|s+$/g","");
return [_c,range];
},insertAtCursor:function(_d){
var t=this.textarea;
t.focus();
if(document.selection&&document.selection.createRange){
var r=document.selection.createRange();
if(!this.replaceOnInsert){
r.collapse();
}
r.text=_d;
}else{
if(t.setSelectionRange){
var _10=this.replaceOnInsert?t.selectionStart:t.selectionEnd;
var end=t.selectionEnd;
var _12=t.value.substr(0,_10);
var _13=t.value.substr(end);
t.value=_12+_d+_13;
t.setSelectionRange(_10+_d.length,_10+_d.length);
}else{
t.value+=_d;
}
}
setTimeout(function(){
t.focus();
},100);
},surround:function(_14,_15,_16){
var t=this.textarea;
t.focus();
if(!_16){
_16=function(t){
return t;
};
}
var rt=this.getSelection();
var _1a=rt[0];
var _1b=rt[1];
if(_1a==null){
return false;
}
var _1c=_1a!=null&&_1a!="";
if(_1b){
var _1d=_1a!=null&&_1a!="";
var _1e=_14+_16(_1a)+(_15?_15:"");
_1b.text=_1e;
_1b.collapse();
if(_1a!=""){
var _1f=0;
for(var i=0;i<_1e.length;i++){
if(_1e.charAt(i)=="\r"){
_1f++;
}
}
_1b.moveStart("character",-_15.length-_1a.length-_14.length+_1f);
_1b.moveEnd("character",-0);
}else{
_1b.moveEnd("character",-_15.length);
}
if(!this.collapseAfterInsert){
_1b.select();
}
}else{
if(t.setSelectionRange){
var _21=t.selectionStart;
var end=t.selectionEnd;
var _23=t.value.substr(0,_21);
var _24=t.value.substr(end);
var sel=_16(t.value.substr(_21,end-_21));
var _26=_14+sel+_15;
t.value=_23+_26+_24;
if(sel!=""){
t.setSelectionRange(_21,_21+_26.length);
_1d=true;
}else{
t.setSelectionRange(_21+_14.length,_21+_14.length);
_1d=false;
}
if(this.collapseAfterInsert){
t.setSelectionRange(_21+_26.length,_21+_26.length);
}
}else{
t.value+=_14+_1a+_15;
}
}
this.collapseAfterInsert=false;
return _1d;
},_cancelEvent:function(e){
if(e.preventDefault){
e.preventDefault();
}
if(e.stopPropagation){
e.stopPropagation();
}
return e.returnValue=false;
},onKeyPress:function(e,_29){
var key=String.fromCharCode(e.keyCode?e.keyCode:e.charCode);
for(var id in this.tags){
var tag=this.tags[id];
if(tag.ctrlKey&&!e[tag.ctrlKey+"Key"]){
continue;
}
if(!tag.key||key.toUpperCase()!=tag.key.toUpperCase()){
continue;
}
if(e.type=="keydown"){
this.insertTag(id);
}
return this._cancelEvent(e);
}
if(_29=="press"&&e.keyCode==this.VK_TAB&&!e.shiftKey&&!e.ctrlKey&&!e.altKey){
this.surround("\t","");
return this._cancelEvent(e);
}
if(e.keyCode==this.VK_TAB&&!e.shiftKey&&e.ctrlKey&&!e.altKey){
this.textarea.form.post.focus();
return this._cancelEvent(e);
}
var _2d=this.textarea.form;
var _2e=null;
if(e.keyCode==this.VK_PAGE_UP&&e.shiftKey&&!e.ctrlKey&&e.altKey){
_2e=_2d.add_attachment_box;
}
if(e.keyCode==this.VK_ENTER&&!e.shiftKey&&!e.ctrlKey&&e.altKey){
_2e=_2d.preview;
}
if(e.keyCode==this.VK_ENTER&&!e.shiftKey&&e.ctrlKey&&!e.altKey){
_2e=_2d.post;
}
if(_2e){
_2e.click();
return this._cancelEvent(e);
}
return true;
},addTag:function(id,_30,_31,key,_33,_34){
if(!_33){
_33="ctrl";
}
var tag=new Object();
tag.id=id;
tag.open=_30;
tag.close=_31;
tag.key=key;
tag.ctrlKey=_33;
tag.multiline=_34;
tag.elt=this.textarea.form[id];
this.tags[id]=tag;
var elt=tag.elt;
if(elt){
var th=this;
if(elt.type&&elt.type.toUpperCase()=="BUTTON"){
addEvent(elt,"onclick",function(){
th.insertTag(id);
return false;
});
}
if(elt.tagName&&elt.tagName.toUpperCase()=="SELECT"){
addEvent(elt,"onchange",function(){
th.insertTag(id);
return false;
});
}
}else{
if(id&&id.indexOf("_")!=0){
return alert("addTag('"+id+"'): no such element in the form");
}
}
},insertTag:function(id){
var tag=this.tags[id];
if(!tag){
return alert("Unknown tag ID: "+id);
}
var op=tag.open;
if(typeof (tag.open)=="function"){
op=tag.open(tag.elt);
}
var cl=tag.close!=null?tag.close:"/"+op;
if(op.charAt(0)!=this.BRK_OP){
op=this.BRK_OP+op+this.BRK_CL;
}
if(cl&&cl.charAt(0)!=this.BRK_OP){
cl=this.BRK_OP+cl+this.BRK_CL;
}
this.surround(op,cl,!tag.multiline?null:tag.multiline===true?this._prepareMultiline:tag.multiline);
},_prepareMultiline:function(_3c){
_3c=_3c.replace(/\s+$/,"");
_3c=_3c.replace(/^([ \t]*\r?\n)+/,"");
if(_3c.indexOf("\n")>=0){
_3c="\n"+_3c+"\n";
}
return _3c;
}};
function checkForm(_3d){
var _3e=false;
if(_3d.message.value.length<2){
_3e="Please enter the message.";
}
if(_3e){
setTimeout(function(){
alert(_3e);
},100);
return false;
}
return true;
}
function addEvent(elt,_40,_41,_42){
_40=_40.replace(/^(on)?/,"on");
var _43=elt[_40];
var tmp="__tmp";
elt[_40]=function(e){
if(!e){
e=window.event;
}
var _46;
if(!_42){
elt[tmp]=_41;
_46=elt[tmp](e);
elt[tmp]=null;
if(_46===false){
return _46;
}
}
if(_43){
elt[tmp]=_43;
_46=elt[tmp](e);
elt[tmp]=null;
}
if(_42&&_46!==false){
elt[tmp]=_41;
_46=elt[tmp](e);
elt[tmp]=null;
}
return _46;
};
return _41;
}
if(window.HTMLElement&&window.HTMLElement.prototype.__defineSetter__){
HTMLElement.prototype.__defineSetter__("innerText",function(_47){
this.innerHTML=_47.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
});
HTMLElement.prototype.__defineGetter__("innerText",function(){
var r=this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();
});
}
function copyText(_49){
if(!document.body.createTextRange){
return false;
}
BodyRange=document.body.createTextRange();
if(!BodyRange.moveToElementText){
return false;
}
BodyRange.moveToElementText(_49);
if(!BodyRange.execCommand){
return false;
}
BodyRange.execCommand("Copy");
return true;
}
function AddSelectedText(_4a,_4b){
if(document.post.message.caretPos){
document.post.message.caretPos.text=_4a+document.post.message.caretPos.text+_4b;
}else{
document.post.message.value+=_4a+_4b;
}
document.post.message.focus();
}
function InsertBBCode(_4c){
AddSelectedText("["+_4c+"]","[/"+_4c+"]");
}
function storeCaret(_4d){
if(_4d.createTextRange){
_4d.caretPos=document.selection.createRange().duplicate();
}
}

