content_html = '';

function tags_init() {
  return;
  var content = $('tag_content');
  content_html = content.innerHTML;
  content.addEventListener('mouseup', function() {
    var sel = getSel().toString();
    if (sel.length < 4) {
      return;
    }
    var pattern = new RegExp('(' + sel.pregQuote().replace(/\\r\\n/g, '<br />\\r\\n') + ')', ['g']);
    alert(pattern);
    if (content_html.match(pattern).length > 1) {
      alert('your tag is not a unique string... the text you select must be unique within the post');
      return;
    }
    setTimeout(function() {
      content.innerHTML = content_html.replace(pattern, '<span style="background-color: #eee; border: 1px solid #bbb">$1</span>');
    }, 0);
  }, false);
}

String.prototype.pregQuote = function() {
  var strs = ['.','!','?','<','>','(',')','[',']','{','}','|','\\','/','+','^','*','$','\'','"'];
  var text = this.replace(new RegExp('(\\' + strs.join('|\\') + ')', ['g']), '\\$1')
  return text.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
}

function getSel() {
  if (window.getSelection) {
    return window.getSelection();
  }
  else if (document.getSelection) {
    return document.getSelection();
  }
  else if (document.selection) {
    return document.selection.createRange().text;
  }
  else return;
}