﻿function isNumberKey(evt, allowNegative) {
    //Controlla se nella casella di testo è stato digitato un numero.
    var charCode = (evt.which) ? evt.which : event.keyCode;
    var undoChar = false;

    //alert(null.value);
    if (allowNegative == undefined)
        allowNegative = false;

    if (charCode == 13) {
        //Annulla la pressione del tasto Invio.
        undoChar = true;
    }
    else {
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            undoChar = true;
        if (charCode == 45 && allowNegative)    //E' stata digitato il segno meno, ma in questo caso è consentito.
            undoChar = false;
    }

    if (undoChar) {
        if (evt.which)
            evt.which = 0;
        else
            event.keyCode = 0;

        return false;
    }

    return true;
}

function showButtonsOnChange(evt, img1, img2) {
    var isNumber = isNumberKey(evt);
    if (isNumber) {
        //E' stato digitato un numero, quindi visualizza le immagini.
        document.getElementById(img1).style.display = 'inline';
        if (document.getElementById(img2) != null)
            document.getElementById(img2).style.display = 'inline';
    }
}

function showButtonsOnKeyDown(evt, img1, img2) {
    //Controlla se nella casella di testo è stato digitato CANC oppure backspace.
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode == 8 || charCode == 46) {
        //E' stato digitato CANC oppure backspace, quindi mostra le immagini.
        document.getElementById(img1).style.display = 'inline';
        if (document.getElementById(img2) != null)
            document.getElementById(img2).style.display = 'inline';
    }
}

function openWindow(a_str_windowURL, a_int_windowWidth, a_int_windowHeight, a_scrollBar) {
    var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
    var int_windowTop = (screen.height - a_int_windowHeight) / 2;
    var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft;
    if (a_scrollBar)
        str_windowProperties += ',scrollbars=yes';
    var obj_window = window.open(a_str_windowURL, 'popup', str_windowProperties);
    if (obj_window != null && parseInt(navigator.appVersion) >= 4) {
        obj_window.window.focus();
    }
}

