function hbTimeFilter (nameOfSource, granularity)
{
  this.sourceName = nameOfSource;
  this.granularity = granularity;
  this.from = this.getNow ();
  this.to = this.getNow ();
  this.ignored = false;
  this.indexOf = new Object ();

  if ("year" == this.granularity.toLowerCase ())
  {
    this.to.setFullYear (this.to.getFullYear () + 1);
  }
  else if ("month" == this.granularity.toLowerCase ())
  {
    this.to.setMonth ((this.to.getMonth () + 1) % 12);
  }
  else if ("day" == this.granularity.toLowerCase ())
  {
    this.to.setTime (this.to.getTime () + 86400000);
  }
  else if ("hour" == this.granularity.toLowerCase ())
  {
    this.to.setTime (this.to.getTime () + 86400000);
  }
  else if ("minute" == this.granularity.toLowerCase ())
  {
    this.to.setTime (this.to.getTime () + 86400000);
  }
  else if ("second" == this.granularity.toLowerCase ())
  {
    this.to.setTime (this.to.getTime () + 86400000);
  }
}
/*
hbTimeFilter.prototype.clear = function ()
{
  this.from = this.getNow ();
  this.to = this.getNow ();
  this.to.setFullYear (this.to.getFullYear () + 100);
}
*/
hbTimeFilter.prototype.getNow = function ()
{
  var now = new Date ();

  if ("year" == this.granularity.toLowerCase ())
  {
    now.setMonth (0);
    now.setDate (1);
    now.setHours (0);
    now.setMinutes (0);
    now.setSeconds (0);
  }
  else if ("month" == this.granularity.toLowerCase ())
  {
    now.setDate (1);
    now.setHours (0);
    now.setMinutes (0);
    now.setSeconds (0);
  }
  else if ("day" == this.granularity.toLowerCase ())
  {
    now.setHours (0);
    now.setMinutes (0);
    now.setSeconds (0);
  }
  else if ("hour" == this.granularity.toLowerCase ())
  {
    now.setMinutes (0);
    now.setSeconds (0);
  }
  else if ("minute" == this.granularity.toLowerCase ())
  {
    now.setSeconds (0);
  }

  return now;
}
/*
hbTimeFilter.prototype.makeTextElem = function (document, enabled, maxLength)
{
  var result = document.createElement ("input");
  result.type = "text";
  result.size = (maxLength ? maxLength : 2) / 2;
  result.maxLength = maxLength ? maxLength : 2;
  result.disabled = ! enabled;
  return result;
}

hbTimeFilter.prototype.makeFormattedText = function (myDocument, text)
{
  var textElem = myDocument.createTextNode (text);
  var formatted = myDocument.createElement ("font");
  formatted.color = "white";
  formatted.face = "Arial";
  formatted.size = "3";
  formatted.appendChild (textElem);
  return formatted;
}

hbTimeFilter.prototype.createElements = function (myDocument, enabled)
{
  var fromString = vcnlinfoCookies.get ("timeFilterFrom_" + this.sourceName);
  var toString = vcnlinfoCookies.get ("timeFilterTo_" + this.sourceName);

  if ("" != fromString)
  {
    this.from = Date.parse (fromString);
  }

  if ("" != toString)
  {
    this.to = Date.parse (toString);
  }

  this.timeFilterElements = new Array ();

  if ("year" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_year"] = 1;
    this.indexOf ["to_year"] = 3;
    this.timeFilterElements = new Array (4);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, " t/m ");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled, 4);
  }
  else if ("month" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_month"] = 1;
    this.indexOf ["from_year"] = 3;
    this.indexOf ["to_month"] = 5;
    this.indexOf ["to_year"] = 7;
    this.timeFilterElements = new Array (8);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [4] = this.makeFormattedText (myDocument, " t/m ");
    this.timeFilterElements [5] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [6] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [7] = this.makeTextElem (myDocument, enabled, 4);
  }
  else if ("day" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_day"] = 1;
    this.indexOf ["from_month"] = 3;
    this.indexOf ["from_year"] = 5;
    this.indexOf ["to_day"] = 7;
    this.indexOf ["to_month"] = 9;
    this.indexOf ["to_year"] = 11;
    this.timeFilterElements = new Array (8);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [4] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [5] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [6] = this.makeFormattedText (myDocument, " t/m ");
    this.timeFilterElements [7] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [8] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [9] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [10] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [11] = this.makeTextElem (myDocument, enabled, 4);
  }
  else if ("hour" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_day"] = 1;
    this.indexOf ["from_month"] = 3;
    this.indexOf ["from_year"] = 5;
    this.indexOf ["from_hour"] = 7;
    this.indexOf ["to_day"] = 11;
    this.indexOf ["to_month"] = 13;
    this.indexOf ["to_year"] = 15;
    this.indexOf ["to_hour"] = 17;
    this.timeFilterElements = new Array (19);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [4] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [5] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [6] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [7] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [8] = this.makeFormattedText (myDocument, "h");
    this.timeFilterElements [9] = myDocument.createElement ("br");
    this.timeFilterElements [10] = this.makeFormattedText (myDocument, "t/m ");
    this.timeFilterElements [11] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [12] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [13] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [14] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [15] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [16] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [17] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [18] = this.makeFormattedText (myDocument, "h");
  }
  else if ("minute" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_day"] = 1;
    this.indexOf ["from_month"] = 3;
    this.indexOf ["from_year"] = 5;
    this.indexOf ["from_hour"] = 7;
    this.indexOf ["from_minute"] = 9;
    this.indexOf ["to_day"] = 13;
    this.indexOf ["to_month"] = 15;
    this.indexOf ["to_year"] = 17;
    this.indexOf ["to_hour"] = 19;
    this.indexOf ["to_minute"] = 21;
    this.timeFilterElements = new Array (23);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [4] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [5] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [6] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [7] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [8] = this.makeFormattedText (myDocument, "h");
    this.timeFilterElements [9] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [10] = this.makeFormattedText (myDocument, "m");
    this.timeFilterElements [11] = myDocument.createElement ("br");
    this.timeFilterElements [12] = this.makeFormattedText (myDocument, "t/m ");
    this.timeFilterElements [13] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [14] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [15] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [16] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [17] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [18] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [19] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [20] = this.makeFormattedText (myDocument, "h");
    this.timeFilterElements [21] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [22] = this.makeFormattedText (myDocument, "m");
  }
  else if ("second" == this.granularity.toLowerCase ())
  {
    this.indexOf ["from_day"] = 1;
    this.indexOf ["from_month"] = 3;
    this.indexOf ["from_year"] = 5;
    this.indexOf ["from_hour"] = 7;
    this.indexOf ["from_minute"] = 9;
    this.indexOf ["from_second"] = 11;
    this.indexOf ["to_day"] = 15;
    this.indexOf ["to_month"] = 17;
    this.indexOf ["to_year"] = 19;
    this.indexOf ["to_hour"] = 21;
    this.indexOf ["to_minute"] = 23;
    this.indexOf ["to_second"] = 25;
    this.timeFilterElements = new Array (27);
    this.timeFilterElements [0] = this.makeFormattedText (myDocument, "v/a ");
    this.timeFilterElements [1] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [2] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [3] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [4] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [5] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [6] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [7] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [8] = this.makeFormattedText (myDocument, "h");
    this.timeFilterElements [9] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [10] = this.makeFormattedText (myDocument, "m");
    this.timeFilterElements [11] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [12] = this.makeFormattedText (myDocument, "s");
    this.timeFilterElements [13] = myDocument.createElement ("br");
    this.timeFilterElements [14] = this.makeFormattedText (myDocument, "t/m ");
    this.timeFilterElements [15] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [16] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [17] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [18] = this.makeFormattedText (myDocument, "-");
    this.timeFilterElements [19] = this.makeTextElem (myDocument, enabled, 4);
    this.timeFilterElements [20] = this.makeFormattedText (myDocument, String.fromCharCode (160, 160, 160));
    this.timeFilterElements [21] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [22] = this.makeFormattedText (myDocument, "h");
    this.timeFilterElements [23] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [24] = this.makeFormattedText (myDocument, "m");
    this.timeFilterElements [25] = this.makeTextElem (myDocument, enabled);
    this.timeFilterElements [26] = this.makeFormattedText (myDocument, "s");
  }

  if (this.indexOf ["from_year"])
  {
    var yearStr = this.from.getFullYear ().toString ();
    this.timeFilterElements [this.indexOf ["from_year"]].value = yearStr;
    //this.timeFilterElements [this.indexOf ["from_year"]].value = yearStr.substr (yearStr.length - 2, 2);
  }
  if (this.indexOf ["from_month"])
  {
    this.timeFilterElements [this.indexOf ["from_month"]].value = 1 + this.from.getMonth ();
  }
  if (this.indexOf ["from_day"])
  {
    this.timeFilterElements [this.indexOf ["from_day"]].value = this.from.getDate ();
  }
  if (this.indexOf ["from_hour"])
  {
    this.timeFilterElements [this.indexOf ["from_hour"]].value = this.from.getHours ();
  }
  if (this.indexOf ["from_minute"])
  {
    this.timeFilterElements [this.indexOf ["from_minute"]].value = this.from.getMinutes ();
  }
  if (this.indexOf ["from_second"])
  {
    this.timeFilterElements [this.indexOf ["from_second"]].value = this.from.getSeconds ();
  }

  if (this.indexOf ["to_year"])
  {
    var yearStr = this.to.getFullYear ().toString ();
    this.timeFilterElements [this.indexOf ["to_year"]].value = yearStr;
    //this.timeFilterElements [this.indexOf ["to_year"]].value = yearStr.substr (yearStr.length - 2, 2);
  }
  if (this.indexOf ["to_month"])
  {
    this.timeFilterElements [this.indexOf ["to_month"]].value = 1 + this.to.getMonth ();
  }
  if (this.indexOf ["to_day"])
  {
    this.timeFilterElements [this.indexOf ["to_day"]].value = this.to.getDate ();
  }
  if (this.indexOf ["to_hour"])
  {
    this.timeFilterElements [this.indexOf ["to_hour"]].value = this.to.getHours ();
  }
  if (this.indexOf ["to_minute"])
  {
    this.timeFilterElements [this.indexOf ["to_minute"]].value = this.to.getMinutes ();
  }
  if (this.indexOf ["to_second"])
  {
    this.timeFilterElements [this.indexOf ["to_second"]].value = this.to.getSeconds ();
  }

  return this.timeFilterElements;
}

hbTimeFilter.prototype.storeValue = function ()
{
  var f_year = undefined;
  var f_month = undefined;
  var f_day = undefined;
  var f_hour = undefined;
  var f_minute = undefined;
  var f_second = undefined;
  var t_year = undefined;
  var t_month = undefined;
  var t_day = undefined;
  var t_hour = undefined;
  var t_minute = undefined;
  var t_second = undefined;

  var e = "Invalid entry in field year.";

  if ((this.indexOf ["from_year"]) && ("" != this.timeFilterElements [this.indexOf ["from_year"]].value))
  {
    f_year = parseInt (this.timeFilterElements [this.indexOf ["from_year"]].value, 10);

    if (true == isNaN (f_year))
    {
      throw e;
    }

    if (f_year < 100)
    {
      f_year = f_year + 2000;
    }
  }
  if ((this.indexOf ["from_month"]) && ("" != this.timeFilterElements [this.indexOf ["from_month"]].value))
  {
    f_month = parseInt (this.timeFilterElements [this.indexOf ["from_month"]].value, 10);

    if (true == isNaN (f_month))
    {
      throw e;
    }

    f_month = f_month - 1;
  }
  if ((this.indexOf ["from_day"]) && ("" != this.timeFilterElements [this.indexOf ["from_day"]].value))
  {
    f_day = parseInt (this.timeFilterElements [this.indexOf ["from_day"]].value, 10);

    if (true == isNaN (f_day))
    {
      throw e;
    }
  }
  if ((this.indexOf ["from_hour"]) && ("" != this.timeFilterElements [this.indexOf ["from_hour"]].value))
  {
    f_hour = parseInt (this.timeFilterElements [this.indexOf ["from_hour"]].value, 10);

    if (true == isNaN (f_hour))
    {
      throw e;
    }
  }
  if ((this.indexOf ["from_minute"]) && ("" != this.timeFilterElements [this.indexOf ["from_minute"]].value))
  {
    f_minute = parseInt (this.timeFilterElements [this.indexOf ["from_minute"]].value, 10);

    if (true == isNaN (f_minute))
    {
      throw e;
    }
  }
  if ((this.indexOf ["from_second"]) && ("" != this.timeFilterElements [this.indexOf ["from_second"]].value))
  {
    f_second = parseInt (this.timeFilterElements [this.indexOf ["from_second"]].value, 10);

    if (true == isNaN (f_second))
    {
      throw e;
    }
  }

  if ((this.indexOf ["to_year"]) && ("" != this.timeFilterElements [this.indexOf ["to_year"]].value))
  {
    t_year = parseInt (this.timeFilterElements [this.indexOf ["to_year"]].value, 10);

    if (true == isNaN (t_year))
    {
      throw e;
    }

    if (t_year < 100)
    {
      t_year = t_year + 2000;
    }
  }
  if ((this.indexOf ["to_month"]) && ("" != this.timeFilterElements [this.indexOf ["to_month"]].value))
  {
    t_month = parseInt (this.timeFilterElements [this.indexOf ["to_month"]].value, 10);

    if (true == isNaN (t_month))
    {
      throw e;
    }

    t_month = t_month - 1;
  }
  if ((this.indexOf ["to_day"]) && ("" != this.timeFilterElements [this.indexOf ["to_day"]].value))
  {
    t_day = parseInt (this.timeFilterElements [this.indexOf ["to_day"]].value, 10);

    if (true == isNaN (t_day))
    {
      throw e;
    }
  }
  if ((this.indexOf ["to_hour"]) && ("" != this.timeFilterElements [this.indexOf ["to_hour"]].value))
  {
    t_hour = parseInt (this.timeFilterElements [this.indexOf ["to_hour"]].value, 10);

    if (true == isNaN (t_hour))
    {
      throw e;
    }
  }
  if ((this.indexOf ["to_minute"]) && ("" != this.timeFilterElements [this.indexOf ["to_minute"]].value))
  {
    t_minute = parseInt (this.timeFilterElements [this.indexOf ["to_minute"]].value, 10);

    if (true == isNaN (t_minute))
    {
      throw e;
    }
  }
  if ((this.indexOf ["to_second"]) && ("" != this.timeFilterElements [this.indexOf ["to_second"]].value))
  {
    t_second = parseInt (this.timeFilterElements [this.indexOf ["to_second"]].value, 10);

    if (true == isNaN (t_second))
    {
      throw e;
    }
  }

  this.from = this.getNow ();
  this.to = this.getNow ();

  if (f_year)
  {
    this.from.setYear (f_year);
  }
  if (f_month)
  {
    this.from.setMonth (f_month);
  }
  if (f_day)
  {
    this.from.setDate (f_day);
  }
  if (f_hour)
  {
    this.from.setHours (f_hour);
  }
  if (f_minute)
  {
    this.from.setMinutes (f_minute);
  }
  if (f_second)
  {
    this.from.setSeconds (f_second);
  }

  if (t_year)
  {
    this.to.setYear (t_year);
  }
  if (t_month)
  {
    this.to.setMonth (t_month);
  }
  if (t_day)
  {
    this.to.setDate (t_day);
  }
  if (t_hour)
  {
    this.to.setHours (t_hour);
  }
  if (t_minute)
  {
    this.to.setMinutes (t_minute);
  }
  if (f_second)
  {
    this.to.setSeconds (t_second);
  }
}

hbTimeFilter.prototype.setEnabled = function (enabled)
{
  for (var e in this.timeFilterElements)
  {
    if ((this.timeFilterElements [e].type) && ("text" == this.timeFilterElements [e].type))
    {
      this.timeFilterElements [e].disabled = ! enabled;
    }
  }
}
*/
hbTimeFilter.prototype.isEmpty = function ()
{
  return true;
}

hbTimeFilter.prototype.getSpec = function ()
{
  var spec = new hbFilterSpec (null);

  if (!this.ignored)
  {
    if (this.from.getTime () > this.to.getTime ())
    {
      spec.addFilter ("startTime", {"max": 0});
    }
    else
    {
      spec.addFilter ("startTime", {"max": this.to.getTime ()});
      spec.addFilter ("stopTime", {"min": this.from.getTime ()});
    }
  }

  return spec;
}
