function getSelectionManipulator(component) {
  component.focus();

  if (component.createTextRange) {
    selectionManipulator = {
      textRange: document.selection.createRange().duplicate(),
      getText: function() {
	return selectionManipulator.textRange.text;
      },
      replaceSelection: function(value) {
	selectionManipulator.textRange.text = value;
      }

    }
  } else {
    selectionManipulator = {
      startPos: component.selectionStart,
      endPos: component.selectionEnd,
      getText: function() {
	return component.value.substring(
	  selectionManipulator.startPos,
	  selectionManipulator.endPos);
      },
      replaceSelection: function(value) {
	component.value = component.value.substring(
	    0,
	    selectionManipulator.startPos) 
	  + value 
	  + component.value.substring(
	    selectionManipulator.endPos,
	    component.value.length);
      }
    }
  }

  selectionManipulator.surroundSelection = 
    function(prepend, append) 
  {
      selectionManipulator.replaceSelection(
	prepend 
	+ selectionManipulator.getText() 
	+ append);
  };

  selectionManipulator.isAllSpace =
    /^\s*$/.test(selectionManipulator.getText());

  selectionManipulator.selectionLength =
    selectionManipulator.endPos - selectionManipulator.startPos;

  if (component.setSelectionRange) {
    selectionManipulator.setCaretPosition = function(pos) {
      component.setSelectionRange(pos, pos);
    }
  } else {
    selectionManipulator.setCaretPosition = function(pos) {
      var range = component.createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }

  return selectionManipulator;
}



