(function(D){var A="length",E="selectionEnd",C="selectionStart",F="text",B="value";D.fn.getSelection=function(){var I=this[0],G,J,H;if(typeof (G=I[C])!=="undefined"){return{start:I[C],end:I[E],length:I[E]-I[C],text:I[B].substr(I[C],I[E]-I[C])}}if(document.selection&&(G=function(){I.focus();return document.selection.createRange()}())){J=I.createTextRange();H=J.duplicate();J.moveToBookmark(G.getBookmark());H.setEndPoint("EndToStart",J);return{start:H[F][A],end:H[F][A]+G[F][A],length:G[F][A],text:G[F]}}return{start:0,end:I[B][A],length:0}};D.fn.replaceSelection=function(G,H){var J=this[0],I=this.eq(0).getSelection(),K;if(!H){H=G;G=I[F]}I[F]=I[F].replace(G,H);J.focus();if(typeof (J[C])!=="undefined"){J[B]=J[B].substr(0,J[C])+I[F]+J[B].substr(J[E],J[B][A]);J[C]=I.start;J[E]=I.start+I[F].length;return this}if(document.selection){K=document.selection.createRange();K[F]=I[F];K.moveStart("character",-I[F].length);K.moveEnd("character",0);K.select();return this}J[B]+=I.replace(G,H);return this}}(jQuery));
