function hbSource (source)
{
  this.source = source;
//  this.sourceElement = null;
//  this.filterElements = null;
//  this.captionElement = null;
  this.checked = null;
  this.activeByDefault = false;
  this.persistent = false;
//  this.myDocument = null;
  this.filter = null;
  this.unfoldable = false;

  if ((this.source ["activeByDefault"]) && ("true" == this.source ["activeByDefault"]))
  {
    this.activeByDefault = true;
  }
  if ((this.source ["persistent"]) && ("true" == this.source ["persistent"]))
  {
    this.persistent = true;
  }
  if ((this.source ["unfoldable"]) && ("true" == this.source ["unfoldable"]))
  {
    this.unfoldable = true;
  }

  if ((this.source ["timeFilter"]) && ("true" == this.source ["timeFilter"]))
  {
    this.filter = new hbTimeFilter (this.source ["name"], "hour");
  }
  else
  {
    this.filter = new hbFilter (this.source ["name"]);

    var filterSettings = source ["filter"];

    if ((filterSettings) && (0 < filterSettings.length))
    {
      for (var f in filterSettings)
      {
        this.filter.add (filterSettings [f]);
      }
    }
  }
}
/*
hbSource.prototype.init = function (newDocument)
{
  if ((null == this.filterElements) || (newDocument != this.myDocument))
  {
    this.filterElements = new Array ();
    var checkedString = vcnlinfoCookies.get ("source_" + this.source ["name"]);
    var enabled = false;

    if ("" == checkedString)
    {
      enabled = this.activeByDefault;
    }
    else if ("enabled" == checkedString)
    {
      enabled = true;
    }

    this.filterElements = this.filter.createElements (newDocument, enabled);
  }

  if ((null == this.sourceElement) || (newDocument != this.myDocument))
  {
    this.sourceElement = newDocument.createElement ("input");
    this.sourceElement.type = "checkbox";
    this.sourceElement.name = "source";
    this.sourceElement.value = this.source ["name"];

    var checkedString = vcnlinfoCookies.get ("source_" + this.source ["name"]);

    if ("" == checkedString)
    {
      this.checked = this.activeByDefault;
    }
    else if ("enabled" == checkedString)
    {
      this.checked = true;
    }
    else
    {
      this.checked = false;
    }

    var thisSource = this;

    this.sourceElement.onclick = function ()
    {
      thisSource.filter.setEnabled (thisSource.sourceElement.checked);
    }
  }

  this.myDocument = newDocument;
}*/
/*
hbSource.prototype.reset = function ()
{
  this.sourceElement = null;
  this.filterElement = null;
}
*//*
hbSource.prototype.storeValue = function ()
{
  this.checked = this.sourceElement.checked;
  this.filter.storeValue ();
}*/
/*
hbSource.prototype.resetValue = function ()
{
  this.sourceElement.checked = this.checked;
  this.filter.setEnabled (this.checked);
  this.filter.resetValue ();
}
*/
/*
hbSource.prototype.refresh = function ()
{
  this.sourceElement.checked = this.checked;
}*/

hbSource.prototype.hasFilter = function ()
{
  if (!this.filter)
  {
    return false;
  }

  if (this.filter instanceof hbTimeFilter)
  {
    return true;
  }

  return !this.filter.isEmpty ();
}

hbSource.prototype.hasLayer = function (layername)
{
  if (layername == this.source ["layer"])
  {
    return true;
  }
  else if (!this.filter)
  {
    return false;
  }

  if (this.filter instanceof hbTimeFilter)
  {
    return layername == this.source ["layer"];
  }

  return this.filter.hasLayer (layername);
}

hbSource.prototype.isChecked = function ()
{
  if (null == this.checked)
  {
    var checkedString = vcnlinfoCookies.get ("source_" + this.source ["name"]);

    if ("" == checkedString)
    {
      this.checked = this.activeByDefault;
    }
    else if ("enabled" == checkedString)
    {
      this.checked = true;
    }
    else
    {
      this.checked = false;
    }
  }

  if (this.checked)
  {
    return true;
  }

  return false; 
}
/*
hbSource.prototype.getCaptionElement = function (myDocument)
{
//  if (null == this.captionElement)
  {
    this.captionElement = myDocument.createTextNode (this.source ["name"]);
  }

  return this.captionElement;
}*/

hbSource.prototype.getName = function ()
{
  return this.source ["name"];
}
/*
hbSource.prototype.getSourceElement = function (myDocument)
{
  this.init (myDocument);
  return this.sourceElement;
}*/
/*
hbSource.prototype.getFilterElements = function (myDocument)
{
  this.init (myDocument);
  return this.filterElements;
}*/

hbSource.prototype.getActiveLayer = function ()
{
  var filterSpec = this.filter.getSpec ();
  
  if (null == filterSpec.layername)
  {
    filterSpec.layername = this.source ["layer"];
  }
  
  return filterSpec;
}

hbSource.prototype.getActiveFilterName = function ()
{
  if (false == this.filter.isEmpty ())
  {
    return this.filter.getActiveFilterName ();
  }
  else
  {
    return "";
  }
}

hbSource.prototype.activateOnly = function (layer)
{
  if (false == this.filter.isEmpty ())
  {
    if (true == this.filter.hasLayer (layer))
    {
      this.filter.activate (layer);
      this.checked = true;
    }
    else if (false == this.persistent)
    {
      this.checked = false;
    }
  }
  else if (layer == this.source ["layer"])
  {
    if (this.filter instanceof hbTimeFilter)
    {
      this.filter.clear ();
    }

    this.checked = true;
  }
  else if (false == this.persistent)
  {
    this.checked = false;
  }
}

hbSource.prototype.activate = function (layer)
{
  if (false == this.filter.isEmpty ())
  {
    if (true == this.filter.hasLayer (layer))
    {
      this.filter.activate (layer);
      this.checked = true;
    }
    else if (false == this.persistent) // kann das weg?
    {
      this.checked = false;
    }
  }
  else if (layer == this.source ["layer"])
  {
 /*   if (this.filter instanceof hbTimeFilter)
    {
      this.filter.clear ();
    }*/

    this.checked = true;
  }
}

hbSource.prototype.deactivate = function (layer)
{
  if (false == this.filter.isEmpty ())
  {
    if (true == this.filter.hasLayer (layer))
    {
      this.filter.deactivate (layer);
      this.checked = false;
    }
  }
  else if (layer == this.source ["layer"])
  {
 /*   if (this.filter instanceof hbTimeFilter)
    {
      this.filter.clear ();
    }*/

    this.checked = false;
  }
}

