// Fix Opera's built-in UserAgent spoofing
if (navigator.userAgent.indexOf('Opera') == -1) {
  var idx = navigator.userAgent.indexOf('Gecko');
  if (idx != -1 && !navigator.product) {
    // fix Opera bug #166001
    opera.postError('gecko ua fixed');
    // cloak as Mozilla
    navigator.product='Gecko';
    navigator.productSub=navigator.userAgent.substr(idx+6,8);
  }
  if (navigator.userAgent.indexOf('MSIE') != -1 && navigator.appName != 'Microsoft Internet Explorer') {
    // fix Opera bug #166000
    opera.postError('msie ua fixed');
    // cloak as IE
    navigator.appName='Microsoft Internet Explorer';
  }
}


// Hide the window.opera object - by putting it in a BeforeScript
// handler, it should allow other userjs functions to continue to
// access the opera object. Obviously, any userjs event handlers
// you register can no longer access the opera object.
// Only do this when fully cloaking as a non-Opera browser.
if (navigator.userAgent.indexOf('Opera') == -1) {
  opera.addEventListener('BeforeScript', function(ev) {
    if (window.opera && window.opera.postError) {
      window.opera.postError('window.opera hidden');
      delete window.opera;
    }
  }, false);
}


// Hide document.all support.
// Don't do this when pretending to be IE.
if (navigator.userAgent.indexOf('MSIE') == -1) {
  opera.addEventListener('BeforeScript', function (ev) {
    var before = ev.element.text;
    ev.element.text = ev.element.text.replace(/\bdocument\.all([^\.\[\w])/g,'false$1');
    if (ev.element.text != before) {
      this.postError('document.all detected and disabled');
    }
  },false);
}

