// JavaScript Document

// JScript File
/*==========================================================================#
# * Function for adding a Filter to an Input Field                          #
# * @param  : [filterType  ] Type of filter 0=>Alpha, 1=>Num, 2=>AlphaNum   #
# * @param  : [evt         ] The Event Object                               #
# * @param  : [allowDecimal] To allow Decimal Point set this to true        #
# * @param  : [allowCustom ] Custom Characters that are to be allowed       #
#==========================================================================*/
function filterInput(filterType, evt, allowDecimal, allowCustom){
    var keyCode, Char, inputField, filter = '';
    var alpha = 'abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ ';
    var num   = '0123456789 ';
    // Get the Key Code of the Key pressed if possible else - allow
    if(window.event){
        keyCode = window.event.keyCode;
        evt = window.event;
    }else if (evt)keyCode = evt.which;
    else return true;
    // Setup the allowed Character Set
    if(filterType == 0) filter = alpha;
    else if(filterType == 1) filter = num;
    else if(filterType == 2) filter = alpha + num;
    if(allowCustom)filter += allowCustom;
    if(filter == '')return true;
    // Get the Element that triggered the Event
    inputField = evt.srcElement ? evt.srcElement : evt.target || evt.currentTarget;
    // If the Key Pressed is a CTRL key like Esc, Enter etc - allow
    if((keyCode==null) || (keyCode==0) || (keyCode==8) || (keyCode==9) || (keyCode==13) || (keyCode==27) )return true;
    // Get the Pressed Character
    Char = String.fromCharCode(keyCode);
    // If the Character is a number - allow
    if((filter.indexOf(Char) > -1)) return true;
    // Else if Decimal Point is allowed and the Character is '.' - allow
    else if(filterType == 1 && allowDecimal && (Char == '.') && inputField.value.indexOf('.') == -1)return true;
    else return false;
}


function UpperCaseUp(x) {
    var y = x.value
    x.value = y.toUpperCase()
}


function ValidaFechas(textbox) {

    var strFecha, strKeyCode, strCharAnt
    var iLen
    if ((event.keyCode >= 46) && (event.keyCode <= 57)) {
        strFecha = new String(textbox.value);
        iLen = strFecha.length;
        strKeyCode = event.keyCode;
        switch (iLen) {
            case 0:
                {
                    if ((strKeyCode >= 48) && (strKeyCode <= 51))
                        return true;
                    else
                        return false;
                }
            case 1:
                if ((strKeyCode >= 48) && (strKeyCode <= 57)) {
                    strCharAnt = strFecha.substr(iLen - 1, 1)
                    if (strCharAnt == 3)
                        if (strKeyCode < 50) {
                        textbox.value = textbox.value + String.fromCharCode(strKeyCode) + '/';
                        return false;
                    }
                    else
                        return false;
                    else {

                        textbox.value = textbox.value + String.fromCharCode(strKeyCode) + '/';
                        return false;
                    }
                }
                else
                    return false;
            case 2:
                if (strKeyCode == 47)
                    return true;
                else
                    return false;
            case 3:
                if ((strKeyCode >= 48) && (strKeyCode <= 49))
                    return true;
                else
                    return false;
            case 4:
                if ((strKeyCode >= 48) && (strKeyCode <= 57)) {
                    strCharAnt = strFecha.substr(iLen - 1, 1)
                    if (strCharAnt == 1)
                        if (strKeyCode < 51) {
                        textbox.value = textbox.value + String.fromCharCode(strKeyCode) + '/';
                        return false;
                    }
                    else
                        return false;
                    else {
                        textbox.value = textbox.value + String.fromCharCode(strKeyCode) + '/';
                        return false;
                    }
                }
                else
                    return false;
            case 5:
                if (strKeyCode == 47)
                    return true;
                else
                    return false;
            case 6:
                if ((strKeyCode >= 49) && (strKeyCode <= 50))
                    return true;
                else
                    return false;
            case 7:
                if ((strKeyCode >= 48) && (strKeyCode <= 57))
                    return true;
                else
                    return false;
            case 8:
                if ((strKeyCode >= 48) && (strKeyCode <= 57))
                    return true;
                else
                    return false;
            case 9:
                if ((strKeyCode >= 48) && (strKeyCode <= 57))
                    return true;
                else
                    return false;
        }
    }
    else
        return false;
}

// ============= DisableKeys.js =============//

// Keys to be disabled can be added to the lists below.
// The number is the key code for the particular key
// and the text is the description displayed in the
// status window if the key [combination] is pressed.

var badKeys = new Object();
badKeys.single = new Object();
badKeys.single['8'] = 'Backspace outside text fields';
badKeys.single['13'] = 'Enter outside text fields';
badKeys.single['116'] = 'F5 (Refresh)';
badKeys.single['122'] = 'F11 (Full Screen)';

badKeys.alt = new Object();
badKeys.alt['37'] = 'Alt+Left Cursor';
badKeys.alt['39'] = 'Alt+Right Cursor';

badKeys.ctrl = new Object();
badKeys.ctrl['78'] = 'Ctrl+N';
badKeys.ctrl['79'] = 'Ctrl+O';

function checkKeyCode(type, code) {
if (badKeys[type][code]) {
return true;
} else {
return false;
}
}
function getKeyText(type, code) {
return badKeys[type][code];
}

var ie=document.all;
var w3c=document.getElementById&&!document.all;

function keyEventHandler(evt) {
this.target = evt.target || evt.srcElement;
this.keyCode = evt.keyCode || evt.which;
var targtype = this.target.type;
if (w3c) {
if (document.layers) {
this.altKey = ((evt.modifiers & Event.ALT_MASK) > 0);
this.ctrlKey = ((evt.modifiers & Event.CONTROL_MASK) > 0);
this.shiftKey = ((evt.modifiers & Event.SHIFT_MASK) > 0);
} else {
this.altKey = evt.altKey;
this.ctrlKey = evt.ctrlKey;
}
// Internet Explorer
} else {
this.altKey = evt.altKey;
this.ctrlKey = evt.ctrlKey;
}
// Find out if we need to disable this key combination
var badKeyType = "single";
if (this.ctrlKey) {
badKeyType = "ctrl";
} else if (this.altKey) {
badKeyType = "alt";
}
if (checkKeyCode(badKeyType, this.keyCode)) {
return cancelKey(evt, this.keyCode, this.target, getKeyText(badKeyType, this.keyCode));
}
}

function cancelKey(evt, keyCode, target, keyText) {
if (keyCode==8 || keyCode==13) {
// Don't want to disable Backspace or Enter in text fields
if (target.type == "text" || target.type == "textarea" || target.type == "password") {
window.status = "";
return true;
}
}
if (evt.preventDefault) {
evt.preventDefault();
evt.stopPropagation();
} else {
evt.keyCode = 0;
evt.returnValue = false;
}
window.status = keyText+" is disabled";
return false;
}



function addEvent(obj, evType, fn, useCapture) {
// General function for adding an event listener
if (obj.addEventListener) {
obj.addEventListener(evType, fn, useCapture);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent('on' + evType, fn);
return r;
} else {
alert(evType+ ' handler could not be attached');
}
}
function addKeyEvent() {
// Specific function for this particular browser
var e = 'keydown';
addEvent(document,e,keyEventHandler,false);

//var e = (document.addEventListener) ? 'keypress' : 'keydown';
//addEvent(document,e,keyEventHandler,false);
}
addKeyEvent();
//To disable the right mouse button
document.oncontextmenu=new Function('return false');




