ASPxClientFilterControl = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.callBacksEnabled = true;
  this.nodeIndex = -1;
  this.editorIndex = "";
  this.prevEditorValue = null;
  this.imagemouseoversrc = null;
  this.ownerControl = null;  
  this.isApplied = false;
  this.lpTimer = -1;
  this.lpDelay = 500;
  this.delayedApply = false;
  this.sizingConfig.allowSetWidth = false;
  this.sizingConfig.allowSetHeight = false;
  this.Applied = new ASPxClientEvent();
 },
 GetChildElementById: function(childName){
  return _aspxGetElementById(this.name + "_" + childName);
 },
 GetFilterExpression: function() { return this.GetChildElementById("E").value; },
 GetAppliedFilterExpression: function() { return this.GetChildElementById("AE").value; },
 GetEditor: function(editorIndex) { return aspxGetControlCollection().Get(this.name + "_" + "DXEdit" + editorIndex.toString()); },
 GetNodeIndexByEditor: function(editorIndex) { return Math.round(editorIndex / 1000); },
 GetValueIndexByEditor: function(editorIndex) { return editorIndex % 1000; },
 GetRootTable: function() { return _aspxGetElementById(this.name); },
 GetRootTD: function() { 
  var table = this.GetRootTable();
  if(!_aspxIsExists(table)) return null;
  return table.rows[0].cells[0];
 },  
 WakeLoadingPanel: function() {
  if(this.lpTimer > -1) return;
  this.CreateLoadingDiv(this.GetRootTD());   
  var js = "aspxFCShowLoadingPanel('" + this.name + "')";
  this.lpTimer = _aspxSetTimeout(js, this.lpDelay);
 },
 ShowLoadingPanel: function() {
  this.ClearLoadingPanelTimer();  
  var div = this.GetLoadingDiv();
  if(div) div.style.cursor = "wait";
  var cell = this.GetRootTD();
  if(cell) this.CreateLoadingPanelWithAbsolutePosition(cell);
 },
 ClearLoadingPanelTimer: function() {
  this.lpTimer = _aspxClearTimer(this.lpTimer);  
 },
 HideLoadingPanel: function() {
  this.ClearLoadingPanelTimer();
  this.constructor.prototype.HideLoadingPanel.call(this);
 },   
 FilterCallback: function(action, index, params) {
  if(!_aspxIsExists(index)) {
   index = this.nodeIndex;
  }
  this.nodeIndex = -1;
  var args = action + '|' + index.toString()  + '|' + params;
  if(!_aspxIsExists(this.callBack) || !this.callBacksEnabled) {
   this.SendPostBack(args);
   return;
  } 
  this.WakeLoadingPanel();
  this.CreateCallback(args, "");
 },
 OnCallback: function(result){  
  this.ClearEditorsValues();
  if(this.ownerControl != null && !this.delayedApply) {
   this.ownerControl.OnCallback(result);
  } else {
   var rootTD = this.GetRootTD();
   if(rootTD != null) {
    _aspxSetInnerHtml(rootTD, result);
   }
  }  
  if(this.isApplied) {
   this.RaiseFilterApplied();
  }
  this.isApplied = false;
 },
 DoEndCallback: function() {
  if(this.ownerControl != null && !this.delayedApply) {
   this.ownerControl.DoEndCallback();
   this.ownerControl = null;
  } else {  
   ASPxClientControl.prototype.DoEndCallback.call(this);
   if(this.delayedApply) {
    this.delayedApply = false;
    this.Apply(this.ownerControl);
   }
  }
 },
 OnCallbackError: function(result, data){  
  this.isApplied = false;
  alert(result);
  if(this.editorIndex > -1) {
   var editor = this.GetEditor(this.editorIndex);
   editor.SetFocus();
  }
 }, 
 ShowPopupMenu: function(menuName, evt, index, propertyType) {
  if(this.CheckEditor()) return;
  this.nodeIndex = index;
  var menu = aspxGetControlCollection().Get(this.name + "_" + menuName);
  if(menu != null) {
   if(_aspxIsExists(propertyType)) {
    this.CheckOperationMenuItemVisibility(menu, propertyType);
   }
   menu.ShowAtElement(_aspxGetEventSource(evt));
  }
 },
 ShowFieldNamePopup: function(evt, index) { this.ShowPopupMenu("FieldNamePopup", evt, index); },
 ShowOperationPopup: function(evt, index, propertyType) { this.ShowPopupMenu("OperationPopup", evt, index, propertyType); },
 ShowGroupPopup: function(evt, index) { this.ShowPopupMenu("GroupPopup", evt, index); },
 ChangeFieldName: function(fieldName, index) {  this.FilterCallback("FieldName", index, fieldName); },
 ChangeOperation: function(operation, index) {  this.FilterCallback("Operation", index, this.RemoveDivider(operation)); },
 ChangeGroup: function(group, index) {  
  if(group.indexOf("|") == 0) {
   this.FilterCallback(group.substr(1), index, ""); 
  } else {
   this.FilterCallback("GroupType", index, group); 
  }
 },
 Apply: function(ownerControl) { 
  if(this.editorIndex > -1) {
   var editor = this.GetEditor(this.editorIndex);
   if(editor && !editor.GetIsValid())
    return;
  }  
  this.ownerControl = ownerControl;
  if(this.InCallback()) {
   this.delayedApply = true;
   return;
  }
  this.isApplied = true;
  this.FilterCallback("Apply", -1, ownerControl ? "T" : "F"); 
 },
 Reset: function() {
  this.FilterCallback("Reset", -1, ""); 
 },
 RemoveNode: function(index) { this.FilterCallback("Remove", index, ""); },
 AddConditionNode: function(index) { this.FilterCallback("AddCondition", index, ""); },
 AddValue: function(index) {  this.FilterCallback("AddValue", index, ""); },
 ShowEditor: function(editorIndex) {
  if(this.CheckEditor()) return;
  var editor = this.ChangeEditorVisibility(editorIndex, true);
  if(editor != null) {
   editor.SetIsValid(true);
   editor.Filter = this;
   editor.Focus();
   this.prevEditorValue = editor.GetValue();
   this.editorIndex = editorIndex;
  }
 },
 HideEditor: function() {
  if(this.editorIndex < 0) return;
  this.ChangeEditorVisibility(this.editorIndex, false);
  var editor = this.GetEditor(this.editorIndex);
  if(editor != null) {
   editor.SetValue(this.prevEditorValue);
  }
  this.ClearEditorsValues();
 },
 ChangeEditorVisibility: function(editorIndex, visible) {
  var link = this.GetChildElementById("DXValue" + editorIndex);
  var editor = this.GetEditor(editorIndex);
  if(link != null && editor != null) {
   link.style.display = visible ? "none" : "";
   editor.SetVisible(visible);
   return editor;
  }
  return null;
 },
 CheckEditor: function() {
  if(this.editorIndex < 0) return false;
  var editor = this.GetEditor(this.editorIndex);
  if(editor == null) return false;
  editor.Validate();
  if(!editor.GetIsValid()) return true;  
  if(editor.GetValue() == this.prevEditorValue) {
   this.HideEditor();
   return false;
  }
  var editorIndex = this.editorIndex;
  var value = editor.GetValueString();
  if(value == null) value = "";
  var params = this.GetValueIndexByEditor(editorIndex).toString() + '|' + value;
  this.FilterCallback("Value", this.GetNodeIndexByEditor(editorIndex), params);
  return true;
 },
 ClearEditorsValues: function() {
  this.prevEditorValue = null;
  this.editorIndex = -1;
 },
 CheckOperationMenuItemVisibility: function(menu, propertyType) {
  for(var i = 0; i < menu.GetItemCount(); i ++) {
   var item = menu.GetItem(i);
   var str = this.GetBeforeDivider(item.name);
   item.SetVisible( propertyType.length > 0 && str.indexOf(propertyType) > -1);
  }
 },
 RemoveDivider: function(str) {
  var pos = str.indexOf('|');
  if(pos < 0) return str;
  return str.substr(pos + 1);
 },
 GetBeforeDivider: function(str) {
  var pos = str.indexOf('|');
  if(pos < 0) return "";
  return str.substr(0, pos);
 },
 RaiseFilterApplied: function() {
  if(this.Applied.IsEmpty()) return;
  var args = new ASPxClientFilterAppliedEventArgs(this.GetFilterExpression());
  this.Applied.FireEvent(this, args);
 }
});
ASPxClientFilterAppliedEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
 constructor: function(filterExpression){
  this.constructor.prototype.constructor.call(this);
  this.filterExpression = filterExpression;
 }
});
function aspxFCShowFieldNamePopup(name, evt, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ShowFieldNamePopup(evt, index);
 }
}
function aspxFCShowOperationPopup(name, evt, index, propertyType) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ShowOperationPopup(evt, index, propertyType);
 }
}
function aspxFCShowGroupPopup(name, evt, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ShowGroupPopup(evt, index);
 }
}
function aspxFCChangeFieldName(name, fieldName) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ChangeFieldName(fieldName);
 }
}
function aspxFCChangeOperation(name, operation) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ChangeOperation(operation);
 }
}
function aspxFCAddValue(name, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.AddValue(index);
 }
}
function aspxFCChangeGroup(name, group) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ChangeGroup(group);
 }
}
function aspxFCRemoveNode(name, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.RemoveNode(index);
 }
}
function aspxFCAddConditionNode(name, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.AddConditionNode(index);
 }
}
function aspxFCNodeValueClick(name, index) {
 var control = aspxGetControlCollection().Get(name); 
 if(control != null) {
  control.ShowEditor(index);
 }
}
function aspxFCEditorKeyDown(s, e) {
 var keyCode = _aspxGetKeyCode(e.htmlEvent);
 if(keyCode == ASPxKey.Enter)
  _aspxPreventEventAndBubble(e.htmlEvent); 
}
function aspxFCEditorKeyUp(s, e) {
 var filter = s.Filter;
 if(!filter) return;
 var keyCode = _aspxGetKeyCode(e.htmlEvent);
 if(keyCode == ASPxKey.Enter) {
  filter.CheckEditor();
 } else if(keyCode == ASPxKey.Esc) {
  filter.HideEditor();
 }
}
function aspxFCEditorLostFocus(s, e) {
 if(s.Filter)
  s.Filter.CheckEditor();
}
function aspxFCPopupInit(s, e) { s.Show(); }
function aspxFCPopupShown(s, e) { s.GetWindowContentElement(-1).style.height = 0; } 
function aspxFCShowLoadingPanel(name) {
 var obj = aspxGetControlCollection().Get(name);
 if(obj) obj.ShowLoadingPanel();
}

