subclass(RecordListGridFilter, IRecordListPanelHeaderContent);
function RecordListGridFilter(id)
{
  this.id = id;
  this.filterValueLists = new Array();
  this.filterSelectedValue = new Array();

  this.onChange = new REvent();
  
  RegisterControl.statics.getInstance().add(this);
}

RecordListGridFilter.prototype.addFilterValueList = function(filterValueList, selectedValue)
{
  this.filterValueLists[this.filterValueLists.length] = filterValueList;
  this.filterSelectedValue[this.filterSelectedValue.length] = selectedValue;
}

RecordListGridFilter.prototype.attachFilterValueList = function(node, index)
{
  var filterValueList = this.filterValueLists[index];
  var value = this.filterSelectedValue[index];

  var select = document.createElement("select");
  select.id = RegisterControl.statics.encodeId(this, index);
  select.options.length = filterValueList.length;
  select.onchange = RecordListGridFilter.statics.onChange;
  var selectedIndex = 0;
  for (var i = 0; i<filterValueList.length; i++)
  {
    var item = filterValueList[i];
    if (item.key==value)
      selectedIndex = i;
    select.options[i].text = item.value;
    select.options[i].value = item.key;
  }
  select.options.selectedIndex = selectedIndex;
  node.appendChild(select);
}

RecordListGridFilter.prototype.attach = function(node)
{
  if (0<this.filterValueLists.length)
  {
    node.appendChild(document.createTextNode('Display: '));
    this.attachFilterValueList(node, 0);
    for (var i=1; i<this.filterValueLists.length; i++)
    {
      node.appendChild(document.createTextNode(' and '));
      this.attachFilterValueList(node, i);
    }
  }
}

RecordListGridFilter.prototype.getId = function()
{
  return this.id;
}

RecordListGridFilter.prototype.getValueList = function()
{
  var values = new Array();
  
  for (var i=0; i<this.filterValueLists.length; i++)
  {
    value = '';
    var select = document.getElementById(RegisterControl.statics.encodeId(this, i));
    if (select && select.options && select.options[select.options.selectedIndex])
      value = select.options[select.options.selectedIndex].value;
    values[values.length] = value;
  }
  
  return values;
}

RecordListGridFilter.statics = new Object();

RecordListGridFilter.statics.onChange = function() { RecordListGridFilter.statics.callFunction(this.id, "onChange"); }

RecordListGridFilter.statics.callFunction = function(id, eventName)
{
  var params = new Array();
  var instance = RegisterControl.statics.decodeId(id, params);
  instance[eventName].trigger( );
}
