
function addCommas(nStr)
{
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}


function recoveryCount()
{
    recoveryTotal += recoveryInc;
    var recoveryString = 'Total Member Recovery Time: ';
    
    var years = Math.floor(recoveryTotal / 31556926);
    var rem = recoveryTotal % 31556926;
    var months = Math.floor(rem / 2629743);
    rem = rem % 2629743;
    //var weeks = Math.floor(rem / 604800);
    //rem = rem % 604800;
    var days = Math.floor(rem / 86400);
    rem = rem % 86400;
    var hours = Math.floor(rem / 3600);
    
    recoveryString += addCommas(years) + ' year';
    if (years != 1) {
        recoveryString += 's';
    }
    recoveryString += ' ' + months + ' month';
    if (months != 1) {
        recoveryString += 's';
    }
    recoveryString += ' ' + days + ' day';
    if (days != 1) {
        recoveryString += 's';
    }
    recoveryString += ' ' + hours + ' hour';
    if (hours != 1) {
        recoveryString += 's';
    }

    $('#total-recovery').html(recoveryString);
    setTimeout("recoveryCount()",1000);
}
recoveryCount();


