var __aspxCPStyleSheet = null;
var __aspxCPColorTableIDSuffix = "_CT";
var __aspxCPColorCellIDSuffixPart = "_C";
var __aspxHEColorTableCellCssClassName = "dxctCell";
var __aspxHEColorTableCellDivCssClassName = "dxctCellDiv";
ASPxClientColorTable = _aspxCreateClass(ASPxClientControl, {
 constructor: function(name) {
  this.constructor.prototype.constructor.call(this, name);
  this.colorColCount = 8;
  this.colorValues = [];
  this.selectedIndex = -1;
  this.usedInDropDown = false;
  this.colorTableCellStyleCssText = "";
  this.colorTableCellDivStyleCssText = "";
  this.colorTableCellStyleCssClassName = "";
  this.colorTableCellDivStyleCssClassName = "";
  this.ColorChanged = new ASPxClientEvent();
  this.ItemClick = new ASPxClientEvent();
 },
 Initialize: function() {
  this.constructor.prototype.Initialize.call(this);
  var mainElement = this.GetMainElement();
  mainElement.unselectable = "on";
  mainElement.rows[0].cells[0].unselectable = "on";
  this.InitializeColorTableCellStyle();
  this.InitializeColorsTable();
  if(this.usedInDropDown)
   this.InitializeColorsTableEvents();
 },
 InitializeColorTableCellStyle: function() {
  var colorTableStyleSheet = this.GetStyleSheet();
  _aspxAddStyleSheetRule(colorTableStyleSheet,
    "." + __aspxHEColorTableCellCssClassName + "_" + this.name, this.colorTableCellStyleCssText);
  _aspxAddStyleSheetRule(colorTableStyleSheet,
    "." + __aspxHEColorTableCellDivCssClassName + "_" + this.name, this.colorTableCellDivStyleCssText);
  var colorTableElement = this.GetColorsTableElement();
  var trElements = _aspxGetElementsByTagName(colorTableElement, "TR");
  for (var i = 0; i < trElements.length; i++) {
   var tdElements = _aspxGetElementsByTagName(trElements[i], "TD");
   for (var j = 0; j < tdElements.length; j++) {
    if (this.colorTableCellStyleCssText != "")
     tdElements[j].className += " " + __aspxHEColorTableCellCssClassName + "_" + this.name;
    if (this.colorTableCellStyleCssClassName != "")
     tdElements[j].className += " " + this.colorTableCellStyleCssClassName;
    var tdDiv = _aspxGetElementsByTagName(tdElements[j], "DIV");
    if (tdDiv[0] != null) {
     tdDiv.className = "";
     if (this.colorTableCellDivStyleCssClassName != "")
      tdDiv[0].className += " " + this.colorTableCellDivStyleCssClassName;
     if (this.colorTableCellDivStyleCssText != "")
      tdDiv[0].className += " " + __aspxHEColorTableCellDivCssClassName + "_" + this.name;
    }
   }
  }
 },
 InitializeColorsTable: function() {
  var colorsTable = this.GetColorsTableElement();
  colorsTable.unselectable = "on";
  var colorIndex = 0;
  for (var i = 0; i < colorsTable.rows.length; i++) {
   for (var j = 0; j < colorsTable.rows[i].cells.length; j++) {
    var colorCell = colorsTable.rows[i].cells[j];
    colorCell.id = this.GetColorCellElementID(colorIndex);
    colorCell.unselectable = "on";
    if (__aspxWebKitFamily)
     colorCell.cellIndex_Safari = j;
    var colorDiv = colorCell.firstChild;
    if (_aspxIsExists(colorDiv) && colorDiv.tagName == "DIV") {
     colorDiv.style.backgroundColor = this.colorValues[colorIndex];
     colorDiv.unselectable = "on";
     colorIndex++;
    }
   }
  }
 },
 InitializeColorsTableEvents: function(listTable, method){
  var colorsTable = this.GetColorsTableElement();
  colorsTable.ColorsTableId = this.name;
  _aspxAttachEventToElement(colorsTable, "mouseup", aspxCTMouseUp);
 },
 GetStyleSheet: function(){
  if(__aspxCPStyleSheet == null)
   __aspxCPStyleSheet = _aspxCreateStyleSheet();
  return __aspxCPStyleSheet;
 },
 FindColorIndexByColor: function(colorValue) {
  if (colorValue)
   colorValue = colorValue.toLowerCase();
  for (var i = 0; i < this.colorValues.length; i++) {
   if (this.colorValues[i].toLowerCase() == colorValue)
    return i;
  }
  return -1;
 },
 GetColorsTableElement: function() {
  return _aspxGetElementById(this.name + __aspxCPColorTableIDSuffix);
 },
 GetColorCellElementID: function(colorIndex) {
  return this.name + __aspxCPColorCellIDSuffixPart + colorIndex.toString();
 },
 GetColorCellElementByIndex: function(colorIndex) {
  return _aspxGetElementById(this.GetColorCellElementID(colorIndex));
 },
 SelectColorByIndex: function(colorIndex, fireEvent) {
  if (this.selectedIndex != colorIndex) {
   var stateController = aspxGetStateController();
   var element = this.GetColorCellElementByIndex(this.selectedIndex);
   if (element != null)
    stateController.DeselectElementBySrcElement(element);
   this.selectedIndex = colorIndex;
   element = this.GetColorCellElementByIndex(this.selectedIndex);
   if (element != null)
    stateController.SelectElementBySrcElement(element);
   if (fireEvent)
    this.RaiseColorChanged();
  }
 },
 OnControlClick: function(clickedElement, htmlEvent) {
  if (_aspxIsExists(clickedElement)) {
   if (clickedElement.tagName == "DIV")
    clickedElement = clickedElement.parentNode;
   if (clickedElement.tagName == "TD") {
    var cellIndex = !__aspxWebKitFamily ? clickedElement.cellIndex : clickedElement.cellIndex_Safari;
    var rowIndex = clickedElement.parentNode.rowIndex;
    var colorIndex = rowIndex * this.colorColCount + cellIndex;
    if (0 <= colorIndex && colorIndex < this.colorValues.length) {
     this.RaiseItemClick();
     this.SelectColorByIndex(colorIndex, true);
    }
   }
  }
 },
 RaiseColorChanged: function() {
  if (!this.ColorChanged.IsEmpty()) {
   var args = new ASPxClientEventArgs(false); 
   this.ColorChanged.FireEvent(this, args);
  }
 },
 RaiseItemClick: function() {
  if (!this.ItemClick.IsEmpty()) {
   var args = new ASPxClientEventArgs(false);
   this.ItemClick.FireEvent(this, args);
  }
 },
 GetColor: function() {
  if (0 <= this.selectedIndex && this.selectedIndex < this.colorValues.length)
   return this.colorValues[this.selectedIndex].toUpperCase();
  return "";
 },
 SetColor: function(value) {
  var colorIndex = this.FindColorIndexByColor(value);
  this.SelectColorByIndex(colorIndex, false);
 }
});
function aspxCTMouseUp(evt) {
 var element = _aspxGetEventSource(evt);
 while(element != null && element.tagName != "BODY") {
  if(element.tagName == "TR") {
   var table = element.offsetParent;
   if(_aspxIsExists(table) && _aspxIsExists(table.ColorsTableId)) {
    var ct = aspxGetControlCollection().Get(table.ColorsTableId);
    if(ct != null && _aspxGetIsLeftButtonPressed(evt))
     ct.OnControlClick(_aspxGetEventSource(evt), evt);
    break;
   }
  }
  element = element.parentNode;
 }
}
