var __aspxBarDockToolbarNameSuffix = "_T";
ASPxClientBarDockControl = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name){
  this.constructor.prototype.constructor.call(this, name);
  this.toolbarsCount = -1;
  this.toolbarName = "";
  this.updateItemsTimeout = 300;
  this.updateItemsTimerId = -1;
  this.updateItemsTimerString = "";
  this.Command = new ASPxClientEvent();
  this.ItemUpdate = new ASPxClientEvent();
  this.DropDownItemBeforeFocus = new ASPxClientEvent();
  this.DropDownItemCloseUp = new ASPxClientEvent();
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
  this.toolbarName = this.name + __aspxBarDockToolbarNameSuffix;
  this.updateItemsTimerString = "aspxBDUpdateItemsByTimer('" + this.name + "')";
 },
 GetToolbarControl: function(index){
  return aspxGetControlCollection().Get(this.toolbarName + index);
 },
 Focus: function(){
  if(this.toolbarsCount > 0)
   this.GetToolbarControl(0).Focus();
 },
 FocusLastToolbar: function(){    
  if(this.toolbarsCount > 0)
   this.GetToolbarControl(this.toolbarsCount - 1).FocusLastItem();
 }, 
 DoUpdateItems: function(){ 
  if(!_aspxIsExists(this.GetMainElement())) return;
  for(var i = 0 ; i < this.toolbarsCount; i ++) {
   var toolBar = this.GetToolbarControl(i);
   if (_aspxIsExists(toolBar)) 
    toolBar.UpdateItems();
  }
 },
 OnCommand: function(toolbar, item, value){
  this.RaiseCommand(toolbar, item, value);
 },
 OnItemUpdate: function(toolbar, item){
  this.RaiseItemUpdate(toolbar, item);
 },
 OnDropDownItemBeforeFocus: function(toolbar, item){
  this.RaiseDropDownItemBeforeFocus(toolbar, item);
 },
 OnDropDownItemCloseUp: function(toolbar, item){
  this.RaiseDropDownItemCloseUp(toolbar, item);
 },
 OnPopup: function(toolbar, e){
  this.HideAllPopups(toolbar, e.item);
 },
 RaiseCommand: function(toolbar, item, value){
  if(!this.Command.IsEmpty()){
   var args = new ASPxClientBarDockControlEventArgs(false, toolbar, item, value);
   this.Command.FireEvent(this, args);
  }
 },
 RaiseItemUpdate: function(toolbar, item){
  if(!this.ItemUpdate.IsEmpty()){
   var args = new ASPxClientBarDockControlEventArgs(false, toolbar, item, null);
   this.ItemUpdate.FireEvent(this, args);
  }
 },
 RaiseDropDownItemBeforeFocus: function(toolbar, item){
  if(!this.DropDownItemBeforeFocus.IsEmpty()){
   var args = new ASPxClientBarDockControlEventArgs(false, toolbar, item, null);
   this.DropDownItemBeforeFocus.FireEvent(this, args);
  }
 },
 RaiseDropDownItemCloseUp: function(toolbar, item){
  if(!this.DropDownItemCloseUp.IsEmpty()){
   var args = new ASPxClientBarDockControlEventArgs(false, toolbar, item, null);
   this.DropDownItemCloseUp.FireEvent(this, args);
  }
 },
 UpdateItems: function(){
  _aspxClearTimer(this.updateItemsTimerId);
  this.updateItemsTimerId = window.setTimeout(this.updateItemsTimerString, this.updateItemsTimeout);
 },
 HideAllPopups: function(exeptToolbar, exeptItem){
  var exeptId = _aspxIsExists(exeptToolbar) && _aspxIsExists(exeptItem) ? 
   exeptToolbar.GetMenuElement(exeptItem.GetIndexPath()).id : "";
  aspxGetMenuCollection().DoHidePopupMenus(null, 0, "", false, exeptId);
  for(var i = 0 ; i < this.toolbarsCount; i ++) {
   var toolBar = this.GetToolbarControl(i);
   if (_aspxIsExists(toolBar))
    toolBar.HideTemplatesPopup();
  }
 }
});
ASPxClientBarDockControlEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
 constructor: function(processOnServer, toolbar, item, value){
  this.constructor.prototype.constructor.call(this);
  this.item = item;
  this.toolbar = toolbar;
  this.value = value;
 }
});
ASPxClientToolbarItem = _aspxCreateClass(ASPxClientMenuItem, {
 constructor: function(menu, parent, index, name){
  this.constructor.prototype.constructor.call(this, menu, parent, index, name);
  this.itemTemplateControl = null;
  this.itemTextTemplateControl = null;
 },
 SetValue: function(value){
  var templateControl = this.GetTemplateControl();
  if(_aspxIsExists(templateControl)){
   templateControl.SetValue(value);
  }
 },
 GetTemplateControl: function(){
  var itemTemplate = this.GetItemTemplateControl();
  if(_aspxIsExists(itemTemplate))
   return itemTemplate;
  return this.GetItemTextTemplateControl();
 },
 GetItemTemplateControl: function(){
  if(this.itemTemplateControl === null){
   var templateCell = this.menu.GetItemTextCell(this.GetIndexPath());
   this.itemTemplateControl = this.GetControlFromParentElement(templateCell);
  }
  return this.itemTemplateControl;
 },
 GetItemTextTemplateControl: function(){
  if(this.itemTextTemplateControl === null){
   var templateCell = this.menu.GetItemTemplateCell(this.GetIndexPath());
   this.itemTextTemplateControl = this.GetControlFromParentElement(templateCell);
  }
  return this.itemTextTemplateControl;
 },
 GetControlFromParentElement: function(element){
  if (_aspxIsExists(element)) {
   for(var i = 0; i < element.childNodes.length; i ++) {
    var childNode = element.childNodes[i];
    if(!_aspxIsExists(childNode.id)) continue;
    var control = aspxGetControlCollection().Get(childNode.id);
    if (_aspxIsExists(control))
     return control;
   }
  }
  return null;
 }
});
ASPxClientToolbar = _aspxCreateClass(ASPxClientMenu, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.barDockControlName = "";
  this.barDockControl = null;
  this.ItemUpdate = new ASPxClientEvent();
  this.DropDownItemBeforeFocus = new ASPxClientEvent();
  this.DropDownItemCloseUp = new ASPxClientEvent();
  this.Command = new ASPxClientEvent();
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
  this.SetMenuUnselectable();
  this.InitializeItemState();
 },
 InitializeItemState: function() {
  var element = this.GetItemTextCell(this.GetItem(0).GetIndexPath());
  if (element != null)
   element = this.GetItemImageCell(this.GetItem(0).GetIndexPath());
  this.SetHoverElement(element);
  this.SetHoverElement(null);
  if (_aspxIsExists(this.itemCheckedGroups[0])) {
   this.SetItemChecked(this.itemCheckedGroups[0][0].toString(), true);
   this.SetItemChecked(this.itemCheckedGroups[0][0].toString(), false);
  }
 },
 SetMenuUnselectable: function() {
  _aspxSetTimeout("aspxSetMenuUnselectableByTimer('" + this.name + "')", 0);
 },
 GetToolbarDockControl: function() {
  if (this.barDockControl == null)
   this.barDockControl = aspxGetControlCollection().Get(this.barDockControlName);
  return this.barDockControl;
 },
 GetClientItemType: function() {
  return ASPxClientToolbarItem;
 },
 GetToolbatItemTemplateID: function(indexPath) {
  return this.GetItemByIndexPath(indexPath).name;
 },
 GetToolbarItemTemplateId: function(indexPath) {
  var templateName = this.GetToolbatItemTemplateID(indexPath);
  return this.name + "_ITTCNT" + indexPath + "_" + templateName;
 },
 GetToolbarItemTemplateElement: function(indexPath) {
  return _aspxGetElementById(this.GetToolbarItemTemplateId(indexPath));
 },
 GetToolbarItemTemplateControl: function(indexPath) {
  var templateElement = this.GetToolbarItemTemplateElement(indexPath);
  return _aspxIsExists(templateElement) ? aspxGetControlCollection().Get(this.GetToolbarItemTemplateId(indexPath)) : null;
 },
 SetItemEnabled: function(indexPath, enabled) {
  ASPxClientMenu.prototype.SetItemEnabled.call(this, indexPath, enabled);
  var item = this.GetItemByIndexPath(indexPath);
  var templateControl = item.GetTemplateControl();
  if (_aspxIsExists(templateControl)) {
   var templateElement = templateControl.GetMainElement();
   if (enabled)
    aspxGetStateController().EnableElement(templateElement);
   else
    aspxGetStateController().DisableElement(templateElement);
  }
 },
 HideTemplatesPopup: function() {
  for (var i = 0; i < this.GetItemCount(); i++) {
   var item = this.GetItem(i);
   var templateControl = item.GetTemplateControl();
   if (_aspxIsExists(templateControl)) {
    if (_aspxIsExists(templateControl.HideDropDownArea))
     templateControl.HideDropDownArea(true);
   }
  }
 },
 DoUpdateItems: function() {
  for (var i = 0; i < this.GetItemCount(); i++) {
   var curItem = this.GetItem(i);
   this.RaiseItemUpdate(curItem);
   for (var j = 0; j < curItem.GetItemCount(); j++)
    this.RaiseItemUpdate(curItem.GetItem(j));
  }
 },
 OnTemplateItemValueChanged: function(itemName, itemValue) {
  var item = this.GetItemByName(itemName);
  this.DoRaiseCommand(item.GetIndexPath(), itemValue);
 },
 OnDropDownItemBeforeFocus: function(itemName) {
  var item = this.GetItemByName(itemName);
  this.RaiseDropDownItemBeforeFocus(item);
 },
 OnDropDownItemCloseUp: function(itemName) {
  var item = this.GetItemByName(itemName);
  this.RaiseDropDownItemCloseUp(item);
 },
 DoRaiseCommand: function(indexPath, value) {
  var item = this.GetItemByIndexPath(indexPath);
  this.RaiseCommand(item, value);
 },
 RaiseItemClick: function(indexPath, htmlEvent) {
  this.DoRaiseCommand(indexPath, null);
  if (_aspxIsExists(ASPxClientMenu.prototype.RaiseItemClick))
   ASPxClientMenu.prototype.RaiseItemClick.call(this, indexPath, htmlEvent);
 },
 RaiseCommand: function(item, value) {
  if (!this.Command.IsEmpty()) {
   var args = new ASPxClientToolbarEventArgs(item, value);
   this.Command.FireEvent(this, args);
  }
 },
 RaiseItemUpdate: function(item) {
  if (!this.ItemUpdate.IsEmpty()) {
   var args = new ASPxClientToolbarEventArgs(item, null);
   this.ItemUpdate.FireEvent(this, args);
  }
 },
 RaiseDropDownItemBeforeFocus: function(item) {
  if (!this.DropDownItemBeforeFocus.IsEmpty()) {
   var args = new ASPxClientToolbarEventArgs(item, null);
   this.DropDownItemBeforeFocus.FireEvent(this, args);
  }
 },
 RaiseDropDownItemCloseUp: function(item) {
  if (!this.DropDownItemCloseUp.IsEmpty()) {
   var args = new ASPxClientToolbarEventArgs(item, null);
   this.DropDownItemCloseUp.FireEvent(this, args);
  }
 },
 UpdateItems: function() {
  this.DoUpdateItems();
 }
});
ASPxClientToolbarEventArgs = _aspxCreateClass(ASPxClientEventArgs, {
 constructor: function(item, value){
  this.constructor.prototype.constructor.call(this);
  this.item = item;
  this.value = value;
 }
});
ASPxClientToolbarColorButton = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name){
  this.constructor.prototype.constructor.call(this, name);
  this.colorDiv = null;
  this.colorPicker = null;
  this.colorPickerName = "";
  this.colorPickerLockCount = 0;
  this.defaultColor = "";
  this.ColorChanged = new ASPxClientEvent();
  this.isEmptyColor = false;
 },
 Initialize: function(){
  this.constructor.prototype.Initialize.call(this);
  _aspxSetElementAsUnselectable(this.GetColorDiv());
 },
 GetColorDiv: function(){
  if(this.colorDiv == null)
   this.colorDiv = _aspxGetElementById(this.name + "_CD");
  return this.colorDiv;
 },
 ColorDegToHex: function(color){
  var str = color.toString(16);
  var length = str.length;
  for (var i = str.length; i < 6; i ++ )
   str = "0" + str;
  return "#" + str;
 },
 GetColor: function(){
  var colorDiv = this.GetColorDiv();
  var color = this.isEmptyColor ? null : _aspxGetCurrentStyle(colorDiv).backgroundColor;
  return _aspxColorToHexadecimal(color);
 },
 SetColor: function(color){
  this.isEmptyColor = false;
  if(color == null) {
   this.isEmptyColor = true;
   color = this.defaultColor;
  }
  var colorDiv = this.GetColorDiv();
  colorDiv.style.backgroundColor = color;
  this.SetColorPickerColor();
 },
 SetColorPickerColor: function(){
  if(this.colorPickerLockCount == 0){
   var colorPicker = this.GetColorPicker();
   if(_aspxIsExists(colorPicker))
    colorPicker.SetColor(this.GetColor());
  }
 },
 GetValue: function(){
  return this.GetColor();
 },
 SetValue: function(color){
  this.SetColor(color);
 },
 GetColorPicker: function(){
  if(!_aspxIsExists(this.colorPicker))
   this.colorPicker = aspxGetControlCollection().Get(this.colorPickerName);
  return this.colorPicker;
 },
 OnColorPickerInit: function (colorPicker){
  this.colorPicker = colorPicker;
  this.colorPickerName = colorPicker.name;
  colorPicker.SetColor(this.GetColor());
  var method = new Function("sender", "args", "aspxTBCPColorItemClick(\"" + this.name + "\", sender, args);");
  colorPicker.ItemClick.AddHandler(method);
 },
 OnColorPickerColorItemClick: function(){
  aspxGetMenuCollection().HideAll();
 },
 OnColorPickerColorChanged: function (color){
  this.colorPickerLockCount ++;
  this.SetValue(color);
  this.colorPickerLockCount --;
  this.RaiseColorChanged();
 },
 RaiseColorChanged: function(){
  if(!this.ColorChanged.IsEmpty()){
   var args = new ASPxClientEventArgs();
   this.ColorChanged.FireEvent(this, args);
  }
 }
});
function aspxBDUpdateItemsByTimer(name){
 var barDocCotrol = aspxGetControlCollection().Get(name);
 if(_aspxIsExists(barDocCotrol))
  barDocCotrol.DoUpdateItems();
}
function aspxSetMenuUnselectableByTimer(name){
 var toolbar = aspxGetControlCollection().Get(name);
 if(_aspxIsExists(toolbar)){
  for (var i = 0; i < toolbar.GetItemCount(); i++) {
   var curItem = toolbar.GetItem(i);
   aspxSetMenuItemUnselectable(toolbar, curItem.GetIndexPath());
   for (var j = 0; j < curItem.GetItemCount(); j++)
    aspxSetMenuItemUnselectable(toolbar, curItem.GetItem(j).GetIndexPath());   
  }
 }
}
function aspxSetMenuItemUnselectable(parent, indexPath) {
 _aspxSetElementAsUnselectable(parent.GetItemTextCell(indexPath), true);
 _aspxSetElementAsUnselectable(parent.GetItemImageCell(indexPath));
 _aspxSetElementAsUnselectable(parent.GetItemIndentCell(indexPath));
 _aspxSetElementAsUnselectable(parent.GetItemTemplateCell(indexPath));
 _aspxSetElementAsUnselectable(parent.GetItemPopOutImageCell(indexPath));
 _aspxSetElementAsUnselectable(parent.GetMenuBorderCorrectorElement(indexPath));
 _aspxSetElementAsUnselectable(parent.GetItemIndentElement(indexPath), true);
 _aspxSetElementAsUnselectable(parent.GetItemSeparatorElement(indexPath), true);
 _aspxSetElementAsUnselectable(parent.GetItemSeparatorIndentElement(indexPath), true);
}
function aspxToolbarCommand(toolbar, item, value){
 var barDocCotrol = toolbar.GetToolbarDockControl();
 if(_aspxIsExists(barDocCotrol))
  barDocCotrol.OnCommand(toolbar, item, value);
}
function aspxToolbarItemUpdate(toolbar, item){
 var barDocCotrol = toolbar.GetToolbarDockControl();
 if(_aspxIsExists(barDocCotrol))
  barDocCotrol.OnItemUpdate(toolbar, item);
}
function aspxToolbarDropDownItemBeforeFocus(toolbar, item){
 var barDocControl = toolbar.GetToolbarDockControl();
 if(_aspxIsExists(barDocControl))
  barDocControl.OnDropDownItemBeforeFocus(toolbar, item);
}
function aspxToolbarDropDownItemCloseUp(toolbar, item){
 var barDocControl = toolbar.GetToolbarDockControl();
 if(_aspxIsExists(barDocControl))
  barDocControl.OnDropDownItemCloseUp(toolbar, item);
}
function aspxToolbarPopup(toolbar, e){
 var barDocCotrol = toolbar.GetToolbarDockControl();
 if(_aspxIsExists(barDocCotrol))
  barDocCotrol.OnPopup(toolbar, e);
}   
function aspxTBCPInit(name, s){
 var control = aspxGetControlCollection().Get(name);
 if(control != null) control.OnColorPickerInit(s);
}
function aspxTBCPColorChanged(name, color){
 var control = aspxGetControlCollection().Get(name);
 if(control != null) control.OnColorPickerColorChanged(color);
}
function aspxTBCPColorItemClick(name){
 var control = aspxGetControlCollection().Get(name);
 if(control != null) control.OnColorPickerColorItemClick();
}
function aspxTBCBBeforeFocus(toolbarName, itemName){
 var tbControl = aspxGetControlCollection().Get(toolbarName);
 if(_aspxIsExists(tbControl))
  tbControl.OnDropDownItemBeforeFocus(itemName);
}
function aspxTBCBCloseUp(toolbarName, itemName){
 var tbControl = aspxGetControlCollection().Get(toolbarName);
 if(_aspxIsExists(tbControl))
  tbControl.OnDropDownItemCloseUp(itemName);
}
function aspxTBCBValueChanged(toolbarName, itemName, itemValue){
 var tbControl = aspxGetControlCollection().Get(toolbarName);
 if(_aspxIsExists(tbControl))
  tbControl.OnTemplateItemValueChanged(itemName, itemValue);
}
function aspxTBColorButtonValueChanged(toolbarName, itemName, itemValue){
 var tbControl = aspxGetControlCollection().Get(toolbarName);
 if(_aspxIsExists(tbControl))
  tbControl.OnTemplateItemValueChanged(itemName, itemValue);
}
function aspxHEToolbarCommand(heControlName, item, value){
 var heControl = aspxGetControlCollection().Get(heControlName);
 if(_aspxIsExists(heControl))
  heControl.ExecuteCommand(item.name, value);
}
function aspxHEToolbarItemUpdate(heControlName, toolbar, item){
 if(item == "") return; 
 var heControl = aspxGetControlCollection().Get(heControlName);
 if(_aspxIsExists(heControl)){
  var commandName = item.name;
  var command = ASPxHtmlEditorCommandList[commandName];
  if(_aspxIsExists(command)){
   var isLocked = command.IsLocked(heControl);
   var isChecked = command.GetState(heControl);
   item.SetEnabled(!isLocked);   
   aspxProcessToolbarItemTemplate(item, !isLocked);
   item.SetChecked(isLocked ? false : isChecked);
   if(!isLocked)
    item.SetValue(command.GetValue(heControl));  
  }
 }
}
function aspxHEToolbarDropDownItemBeforeFocus(heControlName, toolbar, item){
 if(item == "") return; 
 var heControl = aspxGetControlCollection().Get(heControlName);
 if(heControl != null)
  heControl.SaveSelectionForPopup();
}
function aspxHEToolbarDropDownItemCloseUp(heControlName, toolbar, item){
 if(item == "") return; 
 var heControl = aspxGetControlCollection().Get(heControlName);
 if(heControl != null)
  heControl.OnToolbarDropDownItemCloseUp();
}
function aspxProcessToolbarItemTemplate(item, enabled) {
 var clientInstance = item.GetTemplateControl();
 if(_aspxIsExists(clientInstance) && _aspxIsExists(clientInstance.SetEnabled))
  clientInstance.SetEnabled(enabled);
}
