

function getApparentStats(dataReceivedCallback)
{
    jQuery.ajax({
        type: 'GET',
        url: '/apparent-stats.php',
        dataType: 'json',
        success: function(j) {
           dataReceivedCallback(j);
        }
    });
}

jQuery(document).ready(function() {
    jQuery('.stats_loading').append('<img src="/images/loading.gif" align="center" style="text-align: center; vertical-align: middle" /> &nbsp;Loading Data...');
    getApparentStats(function(json) {
        if (undefined == json.error) {
            jQuery('.stats_loading').hide();
            jQuery('#stats_current_power').html(json.currentPower).show();
            jQuery('#stats_current_reactive_power').html(json.currentReactivePower).show();
            jQuery('#stats_lifetime_energy').html(json.lifetimeEnergy).show();
            jQuery('#stats_lifetime_reactive_energy').html(json.lifetimeReactiveEnergy).show();
        } else {
            jQuery('.stats_loading').html('<i>Failed to load data, try again later.</i>');
        }
    });
});

