(function(e){var t={__calcBookmark:function(e){return e.charCodeAt(0)-1+(e.charCodeAt(3)-1)*65536+(e.charCodeAt(2)-1)},__getSelectPos:function(e,t){if(!e)return;if(typeof e.selectionStart!="undefined")return t?e.selectionEnd:e.selectionStart;if(!e.createTextRange)return;e.focus();var n=document.selection.createRange().duplicate();if(!t)n.collapse(true);n.setEndPoint("StartToEnd",n);var r=document.body.createTextRange();r.moveToElementText(e);var r=this.__calcBookmark(n.getBookmark())-this.__calcBookmark(r.getBookmark());return r},getSelectStart:function(e){return this.__getSelectPos(e)},getSelectEnd:function(e){return this.__getSelectPos(e,true)},getSelectRange:function(e){return[this.getSelectStart(e),this.getSelectEnd(e)]},setSelectRange:function(e,t){if(!e)return;if(t[0]>t[1])return;e.focus();if(e.setSelectionRange){e.setSelectionRange(t[0],t[1])}else if(e.createTextRange){var n=e.createTextRange();n.collapse(true);n.moveEnd("character",t[1]);n.moveStart("character",t[0]);n.select()}},textPos:function(e,t){if(!e)return;if(!e.createTextRange)return t;var n=e.value;for(var r=0;r<=t;r++)if(n.charAt(r)=="\n")t++;return t},cartPos:function(e,t){if(!e)return;if(!e.createTextRange)return t;var n=e.value;var r=0;for(var a=0;a<=t;a++)if(n.charAt(a)=="\n")r++;return t-r},selectEx:function(e,t,n,r){if(!e)return;t=""+t;n=""+n;var a=this.getSelectRange(e);var c=e.value;var i=[this.textPos(e,a[0]),this.textPos(e,a[1])];var o=c.substr(0,i[0]);var l=c.substring(i[1],c.length);var s=o.lastIndexOf(t);if(s<0)return;var u=l.indexOf(n);if(u<0)return;u+=i[1];if(r)u+=n.length;else s+=t.length;this.setSelectRange(e,[this.cartPos(e,s),this.cartPos(e,u)])},setSelectText:function(e,t,n,r){if(!e)return;e.focus();if(document.selection){var a=document.selection.createRange();a.text=t;a.select()}else if(typeof e.selectionStart!="undefined"){var c=e.value;var i=e.selectionStart;var o=e.scrollTop;e.value=c.substr(0,i)+t+c.substring(e.selectionEnd,c.length);e.selectionStart=i+t.length;e.selectionEnd=i+t.length;e.scrollTop=o}if(n==null)return;var l=this.getSelectRange(e);if(l[0]==l[1])l[0]=l[1]-t.length;if(n==null||n>=t.length||n<0)n=0;if(r!=null&&r<t.length){if(r<0)r=t.length+r;if(r<n)r=t.length}else{r=t.length}l[1]=l[0]+r;l[0]=l[0]+n;this.setSelectRange(e,l)}};e.TextAreaEditor=t})(window);