/* Copyright 2009 WeatherBill Inc. */
if (!wb) throw new Error("required module wb not loaded!");
wb.data = wb.data || {};

(function($){
   function get_historical_data(pricingId, startDate, endDate, measurements,
                                success, error, source, interval){
     source = source || 0;
     interval = interval || 1;
     $.ajax({type: "get",
             url: historical_data_url(pricingId, startDate, endDate),
             data: {source: source, interval: interval, meas: measurements},
             success: success,
             error: error,
             timeout: 20000,
             dataType: "json"});
   }

   function historical_data_url(pricingId, startDate, endDate){
     return "/api/data/historical/" + pricingId + "/" + format_date(startDate) +
       "/" + format_date(endDate);
   }

   function format_date(date){
     return $.datepicker.formatDate(wb.DATE_FORMAT, date);
   }

   wb.data.getHistorical = get_historical_data;
})(jQuery);
