function checkNewConsumptionTotal() {
    newTotal = readInput("#newTotal");
    errMsg = '';
    jQuery("#newTotal").focus();
    if (newTotal != '') {
        newTotal = getFloat(newTotal);
        if (isNaN(newTotal)) {
            errMsg = 'NaN';
        } else if (newTotal <= 0.) {
            errMsg = '&lt;= 0';
        } else {
            grdTotal = getFloat(readStr("#grdTotal"));
            actualTotal = getFloat(readStr("#actualTotal"));
            realTotal = getFloat(readStr("#realTotal"));
            if (isFloat(grdTotal) && isFloat(actualTotal) && isFloat(realTotal)) {
                borneInf = getMin3(grdTotal, actualTotal, realTotal);
                borneSup = getMax3(grdTotal, actualTotal, realTotal) * 3.;
                if (isFloat(borneInf) && newTotal < parseFloat(borneInf)) {
                    errMsg = fixFloat(borneInf, 0) + " min";
                } else if (isFloat(borneSup) && newTotal > parseFloat(borneSup)) {
                    errMsg = fixFloat(borneSup, 0) + " max";
                }
            }
        }
    }
    if (errMsg != '') {
        errMsg += '&nbsp;&nbsp;&nbsp;';
    }

    r = !writeError("#errorTotal", errMsg);

    return r;
}

function updateNewConsumption(timeframe) {
    grdKey = "#grdConsumption" + timeframe;
    newKey = "#newConsumption" + timeframe;
    newTotal = readInput("#newTotal");
    newValue = '';
    if (newTotal != '') {
        newTotal = getFloat(newTotal);
        if (newTotal != NaN && newTotal > 0.) {
            grdTotal = getFloat(readStr("#grdTotal"));
            grdValue = getFloat(readStr(grdKey));
            tempValue = (grdValue / grdTotal) * newTotal;
            if (isFloat(tempValue)) {
                newValue = fixFloat(tempValue, 0) + "&nbsp;&nbsp;&nbsp;";
            }
        }
    }
    writeHtml(newKey, newValue);
}

function updateConsumptions(timeframes) {
    size = timeframes.length;
    for (i = 0; i < size; ++i) {
        updateNewConsumption(timeframes[i]);
    }
    visibility = checkNewConsumptionTotal();
    showOrNotButton("#submit_button", visibility);
}

// desactivee mais conservee au cas ou l'affichage de pourcentages serait a nouveau a l'ordre du jour
/* function updateConsumptionPercentage(timeframe) {
 keyPercentage = "#percentage" + timeframe;
 keyOld = "#oldConsumption" + timeframe;
 newConsumption = jQuery("#newConsumption" + timeframe).val();
 jQuery(keyPercentage).empty();
 ok = true;
 percentage = '';
 message = '';
 if (typeof(newConsumption) != 'undefined' && newConsumption != '') {
 try {
 oldConsumption = jQuery(keyOld).text();
 oldConsumption = parseFloat(oldConsumption.replace(",", "."));
 newConsumption = parseFloat(newConsumption.replace(",", "."));
 percentage = ((newConsumption / oldConsumption) * 100.0);
 percentage = percentage - 100.0;
 percentage = percentage.toFixed(0);
 if (percentage != 'NaN') {
 if (percentage.indexOf("-") == 0) {
 ok = percentage >= -20;
 if (!ok) {
 message = '- 20% max !';
 }
 percentage = "- " + percentage.substring(1);
 }
 else {
 ok = percentage <= 100;
 if (!ok) {
 message = '+ 100% max !';
 }
 percentage = "+ " + percentage;
 }
 percentage += ' %';
 } else {
 percentage = '';
 message = 'NaN !';
 ok = false;
 }
 } catch(err) {
 ok = false;
 message = 'ERROR !';
 percentage = '';
 }
 }
 if (percentage != '') {
 jQuery(keyPercentage).append(percentage);
 }
 if (!ok && message != '') {
 jQuery(keyPercentage).append("<span class = 'rederrror'>" + message + "</span>");
 }
 return ok;
 }  */
