/** Constructs a 'Quote' with maxCap and startDateShift
(startDate is set to today + startDateShift days). */

var TIMEZONEOFFSET = 0;

function Quote(maxCap, startDateShift)
{
  this._MAXCAP = maxCap;
  this._STARTDATESHIFT = startDateShift;

  /* public method to get maxCap */

  this.getMaxCap = function()
  {
    return this._MAXCAP;
  };

  /* public method to get startDateShift */

  this.getStartDateShift = function()
  {
    return this._STARTDATESHIFT;
  };

  this._CONST = 
  {
     _week:{_ALLDAYS:3, _WEEKDAYS:1, _WEEKENDS:2},
     _meas:{_AVGTEMP:4, _MAXTEMP:2, _MINTEMP:3, _PRECIP:1},
     _dv:{_DIRECT:3, _ABOVE:1, _BELOW:2, _ABOVETHRESH:4, _BELOWTHRESH:5},
     _dvop:{_SUM:1, _AVG:2, _MAX:3, _MIN:4},
     _dvop_type:{_ABS_ABOVE:3, _ABS_BELOW:4, _BINARY_ABOVE:1, _BINARY_BELOW:2}
  };

  this._toJulianDate = function(date)
  {
    var month = date.getMonth() + 1;
    var a = parseInt((14 - month) / 12);
    var y = date.getFullYear() + 4800 - a;
    var m = month + 12 * a - 3;
    return date.getDate() + parseInt((153 * m + 2) / 5) + 365 * y + parseInt(y / 4) - parseInt(y / 100) + parseInt(y / 400) - 32045;
  };

  this._fromJulianDate = function(julianDate)
  {
    var L = julianDate + 68569;
    var N = parseInt(4 * L / 146097);
    L = L - parseInt((146097 * N + 3) / 4);
    var I = parseInt(4000 * (L + 1) / 1461001);
    L = L - parseInt(1461 * I / 4) + 31;
    var J = parseInt(80 * L / 2447);
    var K = L - parseInt(2447 * J / 80);
    L = parseInt(J / 11);
    J = J + 2 - 12 * L;
    I = 100 * (N - 49) + I + L;

    return new Date(I, J - 1, K, 0, 0, 0);
  };

  this._addDays = function(date, days)
  {
    return this._fromJulianDate(this._toJulianDate(date) + days);
  };

  this._getToday = function()
  {
    var today = new Date();
    var utc = today.getTime() + (today.getTimezoneOffset() * 60000);
    return new Date(utc + (3600000 * TIMEZONEOFFSET));
  };

  var today = this._getToday();
  this._startDate = this._addDays(today, this.getStartDateShift());
  this._endDate = this._startDate;
  this._week = this._CONST._week._ALLDAYS;
  this._zip = '';
  this._rmsid = '';
  this._tick = 0;
  this._strike = 0;
  this._cap = 0;

  this._meas = this._CONST._meas._MAXTEMP;
  this._dv = this._CONST._dv._DIRECT;
  this._dv_t = 0;
  this._dvop = this._CONST._dvop._SUM;
  this._dvop_type = this._CONST._dvop_type._NOTBINARY;
  this._dvop_t = 0;

  this._computeDays = function(startDate, endDate, week)
  {
    if ((typeof startDate) == 'undefined')
    {
      startDate = this._startDate;
    }

    if ((typeof endDate) == 'undefined')
    {
      endDate = this._endDate;
    }

    if ((typeof week) == 'undefined')
    {
      week = this._week;
    }

    var days = this._toJulianDate(endDate) - this._toJulianDate(startDate);

    if (week == this._CONST._week._ALLDAYS)
    {
      days = days + 1;
    }
    else 
    {
      var startDay = startDate.getDay();
      var endDay = endDate.getDay();
      var adjustedDays = days;
      var startAdjustment = 0;
      var endAdjustment = 0;

      if (week == this._CONST._week._WEEKDAYS)
      {
        adjustedDays = adjustedDays + startDay;

        if (startDay >= 1)
        {
          startAdjustment = startDay - 1;
        }

        adjustedDays = adjustedDays + (7 - endDay);

        if (endDay < 6)
        {
          endAdjustment = 5 - endDay;
        }

        var weeks = Math.floor(adjustedDays / 7);

        return weeks * 5 - (startAdjustment + endAdjustment);
      }
      else if (week == this._CONST._week._WEEKENDS)
      {
        adjustedDays = adjustedDays + startDay;

        if (startDay >= 1)
        {
          startAdjustment = 1;
        }

        adjustedDays = adjustedDays + (7 - endDay);

        if (endDay < 6)
        {
          endAdjustment = 1;
        }

        var weeks = Math.floor(adjustedDays / 7);

        return weeks * 2 - (startAdjustment + endAdjustment);
      }
    }

    return days;
  };
}
