
// www.w3schools.com told me to do this
function getKeyCode(e) {
    var ret;
    if(window.e) { //IE
        ret = e.keyCode;
    } else if(e.which) {// Netscape/Firefox/Opera
        ret = e.which;
    } else {
        ret = null;
    }
    //alert(ret);
    return ret;
}

function getKeyChar(e) {
    return String.fromCharCode(getKeyCode(e));
}

function isEditKey(e) {
    var keycode = getKeyCode(e);
    return keycode == null || keycode == 8 || e.altKey || e.ctrlKey || e.metaKey; //8=backspace
}

function isKeyNumber(e) {   
    return /[0-9]/.test(getKeyChar(e));
}

function enforceNumericKeys(e) {
    return isKeyNumber(e) || isEditKey(e);
}

function isNaturalNumber(value) {   
    return /^(0|[1-9][0-9]*)$/.test(value);
}