function Calcola(form)
{
    var secondi,metri,velocita,velocitaKMH,resto;
    secondi = Number(form.ore.value) * 60 * 60
            + Number(form.minuti.value) * 60
            + Number(form.secondi.value);
    metri =   Number(form.metri.value);
    velocitaKMH = metri * 3600 / secondi;
    velocita = metri / secondi;
    velocita = 1000 / velocita;
    resto=Math.round(velocita % 60)/100;
    velocita = Math.floor(velocita / 60);
        
    if (resto==0.6){
      velocita=velocita+1;
    }
    else{
      velocita=velocita+resto;
    } 

    form.velocita.value = formatNumber(velocita, 2);
    form.KMH.value = Math.floor(velocitaKMH) / 1000
}

function formatNumber (num, decplaces) {
    num = parseFloat(num);
    if (!isNaN(num)) {
        var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
        if (str.indexOf("e") != -1) {
            return "Out of Range";
        }
        while (str.length <= decplaces) {
            str = "0" + str;
        }
        var decpoint = str.length - decplaces;
        return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
    } else {
        return "NaN";
    }
}
