(function($) {

 // get selection: fine in FF and Webkit, partly working in IE6+ (selecting from right-to-left is broken), broken in Opera
 // set selection: ???
 $.fn.textselection = function(start, end) {
 
         if (start !== undefined) {
                 return this.each(function() {
                         if(document.selection){
                         
                         	alert('Yes 1');
                                 var selRange = document.body.createTextRange();

                         } else if( this.setSelectionRange ){
                         
                         alert('Yes 2');
                                 this.setSelectionRange(start, end);
                         } else if( this.selectionStart ){
                         
                         alert('Yes 3');
                                 this.selectionStart = start;
                                 this.selectionEnd = end;
                         }
                 });
         }
         var field = this[0];
         if ( field.createTextRange ) {
                 var range = document.selection.createRange(),
                         orig = field.value,
                         teststring = "<->",
                         textLength = range.text.length;
                 range.text = teststring;
                 var caretAt = field.value.indexOf(teststring);
                 field.value = orig;
                 this.textselection(caretAt, caretAt + textLength);
                 return {
                         start: caretAt,
                         end: caretAt + textLength
                 }
         } else if( field.selectionStart !== undefined ){
                 return {
                         start: field.selectionStart,
                         end: field.selectionEnd
                 }
         }
 };

})(jQuery);