
function TextHighLiter() {
  this.colors = Array('#FFFF00', '#00FFFF', '#FF00FF', '#7FFF00', '#1E90FF');
  
  this.setBlock = function(oBlock) {
    this.oBlock = oBlock;
    this.oRange = this.oBlock.createTextRange();
    this.sBookMark = this.oRange.getBookmark();
  }
  
  this.setContainer = function(oContainer) {
    this.oContainer = oContainer;
  }
  
  this.setColors = function(colors) {
    this.colors = colors;
  }
  
  this.setTokens = function(tokens) {
    this.tokens = tokens;
  }
  
  this.focus = function(token) {
    this.oRange.moveEnd('textedit');
    if (this.oRange.findText(token)) {
      this.oRange.select();
      this.oRange.scrollIntoView(false);
    } else {
      this.oRange.moveToBookmark(this.sBookMark);
      if (this.oRange.findText(token)) {
        this.oRange.select();
        this.oRange.scrollIntoView(false);
      }
    }
    this.oRange.moveStart('character');
  }
  
  this.HighLite = function() {
    for (var i=0; i<this.tokens.length; i++) {
      this.oRange.moveToElementText(this.oContainer);
      var color = this.colors[i % this.colors.length];
      var token = this.tokens[i];
      while (this.oRange.findText(token)) {
        this.oRange.pasteHTML("<span id=delmespan style='background-color:"+color+"'>"+this.oRange.text+"</span>");
        this.oRange.moveStart('character');
        this.oRange.moveEnd('textedit');
      }
    }
    this.oRange.moveToBookmark(this.sBookMark);
  }
  
  this.DeHighLite = function() {
    var oElement;
    while (oElement = document.getElementById('delmespan')) {
      oElement.removeNode();
    }
  }
  
  this.setBlock(document.body);
}
