function BrowserInfo() {
  var agt = navigator.userAgent.toLowerCase();
  this.version = parseFloat(navigator.appVersion);
  this.isIE = (agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1);
  this.isIE4up = this.isIE && (this.version >= 4);
  if (this.isIE) {
    if (this.isIE4up) {
      if (agt.indexOf("msie 6") != -1) this.version = 6;
      else if (agt.indexOf("msie 5.5") != -1) this.version = 5.5;
      else if (agt.indexOf("msie 5") != -1) this.version = 5;
    } else
      this.version = 3;
  }
  this.isIE5up = this.isIE && (this.version >= 5);
  this.isIE5_5up = this.isIE && (this.version >= 5.5);
  this.isIE6up = this.isIE && (this.version >= 6);
  this.isNN = (agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) &&
              (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) &&
              (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1);
  this.isNN4up = this.isNN && (this.version >= 4);
  this.isNN6up = this.isNN && (this.version >= 5);
  this.isOnline = true;
  if (this.isIE4up)
    this.isOnline = navigator.onLine;
  this.name = "Unknown";
  if (this.isIE)
    this.name = "Internet Explorer";
  else if (agt.indexOf("netscape6/") != -1) {
    this.name = "Netscape";
    this.version = parseFloat(agt.substr(agt.indexOf("netscape6/") + 10));
    if (!this.version) this.version = 6;
  } else if (agt.indexOf('gecko') != -1)
    this.name = "Mozilla";
  else if (this.isNN)
    this.name = "Netscape Navigator";
  else if (agt.indexOf("aol") != -1) {
    this.name = "AOL Browser";
    if (this.version < 4) this.version = 3;
  }
  else if (agt.indexOf("opera") != -1) {
    this.name = "Opera";
    this.version = parseFloat(agt.substr(agt.indexOf("opera") + 6));
  }
  else if (agt.indexOf("webtv") != -1)
    this.name = "WebTV";
  else if ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1))
    this.name = "AOL TV Navigator";
  else if (agt.indexOf("hotjava") != -1)
    this.name = "HotJava";
  this.fullName = this.name + ' ' + this.version;
  if (this.version == Math.floor(this.version))
    this.fullName += '.0';
}

var currentBrowser = new BrowserInfo();

function preventSelection(element){
  var preventSelection = false;

  function addHandler(element, event, handler){
    if (element.attachEvent) 
      element.attachEvent('on' + event, handler);
    else 
      if (element.addEventListener) 
        element.addEventListener(event, handler, false);
  }
  function removeSelection(){
    if (window.getSelection) { window.getSelection().removeAllRanges(); }
    else if (document.selection && document.selection.clear)
      document.selection.clear();
  }
  function killCtrlA(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;

    if (sender.tagName.match(/INPUT|TEXTAREA/i))
      return;

    var key = event.keyCode || event.which;
    if (event.ctrlKey && key == 'A'.charCodeAt(0))  // 'A'.charCodeAt(0) можно заменить на 65
    {
      removeSelection();

      if (event.preventDefault) 
        event.preventDefault();
      else
        event.returnValue = false;
    }
  }

  // не даем выделять текст мышкой
  addHandler(element, 'mousemove', function(){
    if(preventSelection)
      removeSelection();
  });
  addHandler(element, 'mousedown', function(event){
    var event = event || window.event;
    var sender = event.target || event.srcElement;
    preventSelection = !sender.tagName.match(/INPUT|TEXTAREA/i);
  });

  // борем dblclick
  // если вешать функцию не на событие dblclick, можно избежать
  // временное выделение текста в некоторых браузерах
  addHandler(element, 'mouseup', function(){
    if (preventSelection)
      removeSelection();
    preventSelection = false;
  });

  // борем ctrl+A
  // скорей всего это и не надо, к тому же есть подозрение
  // что в случае все же такой необходимости функцию нужно 
  // вешать один раз и на document, а не на элемент
  addHandler(element, 'keydown', killCtrlA);
  addHandler(element, 'keyup', killCtrlA);
}







function rf() { return false; }
document.oncontextmenu=rf;
switch (currentBrowser.name)
{
 case "Internet Explorer": {document.onselectstart=rf;break;}
 case "Netscape Navigator": {document.captureEvents(Event.MOUSEDOWN); document.onmousedown=rf; self.blur();break;}
 case "Opera": { preventSelection(document); break;}
}


