// Gaia Ajax Copyright (C) 2008 - 2009 Gaiaware AS. details at http://gaiaware.net/

/* 
 * Gaia Ajax - Ajax Control Library for ASP.NET
 * Copyright (C) 2008 - 2009 Gaiaware AS
 * All rights reserved.
 * This program is distributed under either GPL version 3 
 * as published by the Free Software Foundation or the
 * Gaia Commercial License version 1 as published by
 * Gaiaware AS
 * read the details at http://gaiaware.net
 */
 
Gaia.TableCell = Class.create(Gaia.WebControl, {
  initialize: function(element, options) {
    this.initializeTableCell(element, options);
  },
  
  initializeTableCell: function(element, options) {
    this.initializeWebControl(element, options);
  },
  
  setText: function(value) {
    this._getChildControls().invoke('destroy');
    this.element.update(value);
    return this;
  },
  
  setColSpan: function(value) {
    this.element.setAttribute('colspan', value);
    return this;
  },
  
  setRowSpan: function(value) {
    this.element.setAttribute('rowspan', value);
    return this;
  },
  
  setHeaders: function(value) {
    if (value && value.length)
      this.element.setAttribute('headers', value.join(' '));
    else
      this.element.removeAttribute('headers');
    return this;
  },
  
  setHorAlign: function(value) {
    return this._setAttribute('align', value, Gaia.WebControl.HorAligns);
  },
  
  setVerAlign: function(value) {
    return this._setAttribute('valign', value, Gaia.WebControl.VerAligns);
  },
  
  setWrap: function(value) {
    this.element.setStyle({whiteSpace: value});
    return this;
  },
  
  setAbbr: function(value) {
    this.element.setAttribute('abbr', value);
    return this;
  },
  
  setScope: function(value) {
    return this._setAttribute('scope', value, Gaia.TableCell.Scopes);
  },
  
  _setAttribute: function(name, value, values) {
    if (value)
      this.element.setAttribute(name, values[value - 1]);
    else
      this.element.removeAttribute(name);
    return this;
  },
  
  destroy: function() {
    this.destroyTableCell();
  },
  
  destroyTableCell: function() {
    this.destroyContainer();
    this._destroyImpl();
  }
});

Object.extend(Gaia.TableCell.prototype, Gaia.Container.prototype);
Gaia.TableCell.Scopes = ['row', 'col'];
Gaia.TableCell.loaded = true;