function savingsCounter() {
    savingsDo();
    window.setInterval("savingsDo()", counter_update*1000);    
}

function savingsDo(){
    savingsCalc();
    savingsOutput();  
}

function savingsCalc(){
    value_petrol = value_petrol + (cps_petrol * counter_update);
    value_co2 = value_co2 + (cps_co2 * counter_update);
    value_consumption = value_consumption + (cps_consumption * counter_update);
}

function savingsOutput(){
    $(".value_petrol").html( formatNumber(value_petrol,0,'.','','','','','') );
    $(".value_co2").html( formatNumber(value_co2,0,'.','','','','','') );
    $(".value_consumption").html( formatNumber(value_consumption,0,'.','','','','','') );        
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}
