
function Selection(textareaElement){this.element=textareaElement;}
Selection.prototype.create=function(){if(document.selection!=null&&this.element.selectionStart==null){return this._ieGetSelection();}else{return this._mozillaGetSelection();}}
Selection.prototype._mozillaGetSelection=function(){return{start:this.element.selectionStart,end:this.element.selectionEnd};}
Selection.prototype._ieGetSelection=function(){this.element.focus();var range=document.selection.createRange();var bookmark=range.getBookmark();var contents=this.element.value;var originalContents=contents;var marker=this._createSelectionMarker();while(contents.indexOf(marker)!=-1){marker=this._createSelectionMarker();}
var parent=range.parentElement();if(parent==null||parent.type!="textarea"){return{start:0,end:0};}
range.text=marker+range.text+marker;contents=this.element.value;var result={};result.start=contents.indexOf(marker);contents=contents.replace(marker,"");result.end=contents.indexOf(marker);this.element.value=originalContents;range.moveToBookmark(bookmark);range.select();return result;}
Selection.prototype._createSelectionMarker=function(){return"##SELECTION_MARKER_"+Math.random()+"##";}