﻿/************************************************/
/********ENERGY SAVINGS COUNTER******************/
/************************************************/
$(document).ready(function () {
    var base_date = 210000000;

    // Store the current date and time
    var current_date = new Date();

    // Store the date of the Our Starting point 10/1/2011
    var base_date = new Date();
    base_date.setYear(2011);
    base_date.setMonth(9);
    base_date.setDate(1);

    var days = days_between(current_date, base_date);

    cnt = 210000000 + (days * 24 * 60 * 60 * .67);

    var counter = setInterval(function () { $('#pes-savingsCounter').html(numberWithCommas(cnt)); cnt++; }, 1000);
    var dollar = "$";

    function numberWithCommas(x) {
        return dollar.concat(x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ","));
    }
});

function days_between(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.round(difference_ms / ONE_DAY)

}

 

