// Autor: Javier Minsky, Gabriel Weinstein
// Fecha de Creación: 10/01/2006
// Objetivo: No permite la utilizacion ciertas funciones dentro de la pagina, por ej. F11, click derecho


keys = new Array();
keys["f112"] = 'f1';
keys["f113"] = 'f2';
keys["f114"] = 'f3';
keys["f115"] = 'f4';
keys["f116"] = 'f5';
keys["f117"] = 'f6';
keys["f118"] = 'f7';
keys["f119"] = 'f8';
keys["f120"] = 'f9';
keys["f121"] = 'f10';
keys["f122"] = 'f11';
keys["f123"] = 'f12';

var asciiBackspace  = 8;
var asciiALT        = 18;
var asciiEnd        = 35;
var asciiHome       = 36;
var asciiLeftArrow  = 37;
var asciiUpArrow    = 38;
var asciiRightArrow = 39;
var asciiDownArrow  = 40;
var asciiMS         = 92;
var asciiView       = 93;

var asciiBack        = 166;
var asciiFwd        = 167;
var asciiWWW        = 172;

var asciiUpperA        = 65;
var asciiLowerA        = 97;
var asciiUpperC        = 67;
var asciiLowerC        = 99;
var asciiUpperV        = 86;
var asciiLowerV        = 118;
var asciiUpperX        = 88;
var asciiLowerX        = 120;
var asciiUpperY        = 89;
var asciiLowerY        = 121;
var asciiUpperZ        = 90;
var asciiLowerZ        = 122;

var asciiUpperQ        = 81;
var asciiLowerQ        = 113;
var asciiNumber2    = 50;
var asciiPAD2        = 98;

isNN = document.layers ? 1 : 0;
if(isNN){ 
    document.captureEvents(Event.MOUSEDOWN);
    document.captureEvents(Event.KEYPRESS);
}

document.oncontextmenu = noContext;
document.onkeypress    = noContextKey;
document.onmousedown   = noClick;
document.onmouseup     = noClick;

function goToDown(){
    if (typeof window.event != 'undefined'){
        window.document.onkeydown = function()
        {
            // Capture and remap F-key
            if(window.event && keys["f"+window.event.keyCode]){
                saveCode=window.event.keyCode;
                window.event.keyCode = 505;        //assing the keycode 505
            }
            if(window.event && window.event.keyCode == 505)
                return false; // Must return false or the browser will execute old code

            if (event.altKey)
                if (event.altLeft)
                    return false;
                else
                    return true;

            if (event.ctrlKey)
                if (!teclaPermitidaCTRL(event.keyCode))
                    return false;
            
            var EventStatus = event.srcElement.tagName.toUpperCase();
            if (EventStatus == 'INPUT' || EventStatus == 'TEXTAREA')
                return event.keyCode;
            else{
                if (event.keyCode == asciiBackspace)    return false;
                if (event.keyCode == asciiMS)            return false;
                if (event.keyCode == asciiView)            return false;

                //teclas atras, home y adelante del teclado
                if (event.keyCode == asciiBack)            return false;
                if (event.keyCode == asciiFwd)            return false;
                if (event.keyCode == asciiWWW)            return false;
            }
        }
    }
}

function teclaPermitidaCTRL(keyCode){
    //a, A
    if (keyCode == asciiUpperA) return true;
    if (keyCode == asciiLowerA) return true;
    //c, C
    if (keyCode == asciiUpperC) return true;
    if (keyCode == asciiLowerC) return true;
    //x, X
    if (keyCode == asciiUpperX) return true;
    if (keyCode == asciiLowerX) return true;
    //v, V
    if (keyCode == asciiUpperV) return true;
    if (keyCode == asciiLowerV) return true;
    //y, Y
    if (keyCode == asciiUpperY) return true;
    if (keyCode == asciiLowerY) return true;
    //z, Z
    if (keyCode == asciiUpperZ) return true;
    if (keyCode == asciiLowerZ) return true;

    //end, home
    if (keyCode == asciiEnd) return true;
    if (keyCode == asciiHome) return true;

    //flechitas
    if (keyCode == asciiLeftArrow)    return true;
    if (keyCode == asciiUpArrow)    return true;
    if (keyCode == asciiRightArrow) return true;
    if (keyCode == asciiDownArrow)    return true;

    return false;
}

function teclaPermitidaALT(keyCode){
    if (keyCode == asciiALT) return true;

    //q, Q
    if (keyCode == asciiUpperQ) return true;
    if (keyCode == asciiLowerQ) return true;

    //2, 2
    if (keyCode == asciiNumber2) return true;
    if (keyCode == asciiPAD2) return true;

    return false;
}

function noContext(){return false;}

function noContextKey(e) {
    if (navigator.appName == "Microsoft Internet Explorer"){
        tmp = String.fromCharCode(window.event.keyCode);
        var EventStatus = '';
    }else{
        tmp = e.which;

        if (e.charCode == 0){
            //teclas desde f1 hasta f12
            if (keys["f"+e.keyCode])    return false;

            if (e.keyCode == asciiMS)   return false;
            if (e.keyCode == asciiView) return false;

            //teclas atras, home y adelante del teclado
            if (e.keyCode == asciiBack) return false;
            if (e.keyCode == asciiFwd)  return false;
            if (e.keyCode == asciiWWW)  return false;

            //end, home
            if (e.keyCode == asciiEnd) return true;
            if (e.keyCode == asciiHome) return true;

            //flechitas
            if (e.keyCode == asciiLeftArrow)    return true;
            if (e.keyCode == asciiUpArrow)    return true;
            if (e.keyCode == asciiRightArrow) return true;
            if (e.keyCode == asciiDownArrow)    return true;
        }

        if (e.altKey)
            if (!teclaPermitidaALT(tmp))    return false;

        if (e.ctrlKey)
            if (!teclaPermitidaCTRL(tmp))    return false;

        var EventStatus = e.target.nodeName.toUpperCase();
        if (EventStatus != 'INPUT' && EventStatus != 'TEXTAREA')
            if (tmp == asciiBackspace)    return false;
    }
    return;
}

function noClick(e) {
    if (document.all)
        if (event.button > 1)    return false;
    if (document.layers)
        if (e.which == 3)        return false;
}