var isNav = (navigator.appName.indexOf("Netscape") !=-1);
var isIE = (navigator.appName.indexOf("Microsoft") !=-1);

  function handleKey(e) {
    if (window.event) {
       e = window.event;
    }
    var key=0;
    if (e.which) {
       key = e.which;
    } else {
       key = e.keyCode;
    }
    var src = null;
    if (e.target) {
       src = e.target;
    } else {
       src = e.srcElement;
    }
    var err = "";
    if ( e.altKey && key == '37' ){
       err = 'Alt + Left Arrow is not allowed.';
    }else if ( e.altKey && key == '39' ){
       err = 'Alt + Right Arrow is not allowed.';
    }else if ( key == '8' && (!src.type || src.type == 'button' || src.type == 'select-multiple') ){
       err = 'Backspace is not allowed unless you are in a text field.';
    }else if ( key == '116' && isIE ){
       e.keyCode = 505;
       err = 'F5 is not allowed.';
    }else if ( e.ctrlKey && key == (isNav ? '114' : '82') ){
       err = 'Ctrl + R is not allowed.';
    }
    if ( err.length > 0 ){
       if ( isIE ){
          e.returnValue=false;
       }
       alert(err);
       return false;
    }else{
       return true;
    }
  }

  function windowClick(e) {
     window.routeEvent(e);
     return true;
  }

  function documentClick(e) {
   
    btnPressed = (isIE) ? event.button : e.which;
    if ( (isIE && btnPressed == 2) || (isNav && btnPressed == 3) ) {
      window.alert("Right mouse button has been disabled."); 
      if (isIE) { 
         event.cancelBubble = true; 
      } else { 
         return false; 
      }
    } 
  }

  function setWindowCapture() {
     window.captureEvents(Event.MOUSEUP);
  }

  function releaseWindowCapture() {
     window.releaseEvents(Event.MOUSEUP);
  }
  
  function setDocCapture() {
     document.captureEvents(Event.MOUSEUP | Event.KEYPRESS );
  }
  
  function releaseDocCapture() {
     document.releaseEvents(Event.MOUSEUP | Event.KEYPRESS );
  }

  window.onclick=windowClick;
  if ( isIE ){
     document.onkeydown = handleKey;
     document.onmousedown=documentClick;
     document.onmouseup=documentClick;
  }else{
     document.onclick=documentClick;
     document.onkeypress = handleKey;
  } 

