function replaceSubString(originalString, searchForString, replaceWithString) {
    var objRegExp = eval("/" + searchForString + "/g");
    return (originalString.replace(objRegExp, replaceWithString));
}

function isNumber(item, min, max) {

    item.value = replaceSubString(item.value, ",", ".");
    item.value = replaceSubString(item.value, " ", "");

    if (item.value.length == 0) {
        alert("Calcul interrompu : vous devez renseigner ce champ !");
        item.focus();
        return false;
    }

    if (!isNaN(item.value)) {
        if (min != null) if (parseFloat(item.value) < min) item.value = min;
        if (max != null) if (parseFloat(item.value) > max) item.value = max;
        return true;
    }

    alert("Calcul interrompu :\n\n\"" + item.value + "\" n'est pas un nombre valide !");
    item.focus();
    return false;
}

function round(number, decimal) {
    var factor = Math.pow(10, decimal);
    return Math.round(number * factor) / factor;
}

function compute1(f) {
    var repetitions = 0.0;
    var poids = 0.0;

    if (!isNumber(f.Repetitions, 5, 60)) return false;
    if (!isNumber(f.Poids, 1)) return false;

    repetitions = parseFloat(f.Repetitions.value);
    poids = parseFloat(f.Poids.value);

    var maxi = 0.022 * ( poids * repetitions ) + 21.5; 
    f.Dean.value = "≈ " + round(maxi, 0);

    var maxi = 0.014 * ( poids * repetitions ) + 29; 
    f.Mayhew.value = "≈ " + round(maxi, 0);

    poids = 0.6 * poids;
    var maxi = poids / ( (52.2 + 41.9 * Math.exp(-0.055 * repetitions) ) / 100 );
    f.Fabrice.value = "≈ " + round(maxi, 0);

    poids = 0.6 * poids;
    var maxi = poids / ( (48.8 + 53.8 * Math.exp(-0.075 * repetitions) ) / 100 );
    // f.Fabrice2.value = "≈ " + round(maxi, 0);
}

function compute2(f) {
    var repetitions = 0.0;
    var poids = 0.0;

    if (!isNumber(f.Repetitions, 5, 60)) return false;
    if (!isNumber(f.Poids, 1)) return false;
    if (!isNumber(f.Lest, 0)) return false;

    repetitions = parseFloat(f.Repetitions.value);
    poids = parseFloat(f.Poids.value);
    lest = parseFloat(f.Lest.value);

    poids = 0.75 * (poids + lest);
    var maxi = poids / ( (52.2 + 41.9 * Math.exp(-0.055 * repetitions) ) / 100 );
    f.Fabrice.value = "≈ " + round(maxi, 0);

    poids = 0.75 * (poids + lest);
    var maxi = poids / ( (48.8 + 53.8 * Math.exp(-0.075 * repetitions) ) / 100 );
        // f.Fabrice2.value = "≈ " + round(maxi, 0);
}
