/****************************************************************************/
/**                                                                        **/
/**          __  /  - ____   __   __  __                                   **/
/**        /  / /  / / / / /  / /_  /__/                                   **/
/**       /__/ /_ / / / / /__/ __/ /__                                     **/
/**       __/            /                                                 **/
/**           PHP Library (v 1.18)                                         **/
/**                                                                        **/
/**       Copyright (c) 2000-2002 Glimpse - Licence LGPL                   **/
/**       http://glimpselib.fr.fm - glimpse@fr.fm                          **/
/**                                                                        **/
/**                                                                        **/
/****************************************************************************/


var _ShiftKeyPressed = false;
function _initShiftKeyIndicator(e) {
  if (IE) {
    if (window.event.shiftKey) {
      _ShiftKeyPressed = true;
    } else {
       _ShiftKeyPressed = false;
    }
  }
}


function __GCB(value) {
  this.__isGCB = true;
  this.value = value;
  return this;
}


function GDataTable (id, nbCB, formName, allImg, noneImg, iconPath, custom) {
        this.id = id;
        this.nbCB = nbCB;
        this.lastChecked = -1;
        this.formName = formName;
        this.allChecked = false;
        this.allImg = allImg;
        this.noneImg = noneImg;
        this.custom = custom;
        this.colors = new Array();
        this.cssClasses = new Array();
        this.useAttribute = 'class';
        this.nbLines = 0;
        this.nbCBLines = 0;
        this.indexes = new Array();
        this.layer = null;
        this.TR = new Array();
        this.header = new Array();
        this.colSort = 1;
        this.sortOrder = "asc";
        this.container = document;
        this.dhtmlTable = new DHTMLTable('dt_'+id);
        this.iconPath = iconPath;
        this.lastColSort = -1;
}

GDataTable.prototype.setColors = function (light, dark, hilite) {
        this.colors[0] = light;
        this.colors[1] = dark;
        this.colors[2] = hilite;
        this.useAttribute = 'bgColor';
}


GDataTable.prototype.setCSSClasses = function (light, dark, hilite) {
        this.cssClasses[0] = light;
        this.cssClasses[1] = dark;
        this.cssClasses[2] = hilite;
        this.useAttribute = 'class';
}

GDataTable.prototype.shiftCheck = function (n) {
        if (this.lastChecked == -1) {
                this.lastChecked = n;
                return;
        }
        if (_ShiftKeyPressed) {
          var beg = this.lastChecked;
          var end = n;
          var stap;
          if (beg > end) step = -1;
          else step = 1;
          if (beg == end) return;
                var i = beg;
                do {
                        var cb = eval('document.'+this.formName+'.'+this.id+'cb'+i);
                        if (cb) cb.checked = true;
                        i += step;
                } while (i != end && i>=0 && i<this.nbCB);
        }
        var cb = eval('document.'+this.formName+'.'+this.id+'cb'+n);
        if (cb.checked) this.lastChecked = n;
        else this.lastChecked = -1;
}




GDataTable.prototype.selectAll = function () {
  for (var i=0; i<this.nbCB; i++) {
    var cb = eval('document.'+this.formName+'.'+this.id+'cb'+i);
    if (cb) cb.checked = true;
  }
  document.images[this.id+'gdtscbimg'].src = this.iconPath + this.allImg;
  this.allChecked = true;
}




GDataTable.prototype.selectNone = function () {
  for (var i=0; i<this.nbCB; i++) {
    var cb = eval('document.'+this.formName+'.'+this.id+'cb'+i);
    if (cb) cb.checked = false;
  }
  document.images[this.id+'gdtscbimg'].src = this.iconPath + this.noneImg;
  this.allChecked = false;
}



GDataTable.prototype.toggle = function () {
        if (this.allChecked) {
                this.selectNone();
        } else {
                this.selectAll();
        }
}



GDataTable.prototype.haveChecked = function () {
  var nbc = 0;
  for (var i=0; i<this.nbCB; i++) if (eval('document.'+this.formName+'.'+this.id+'cb'+i).checked==true) nbc++;
  return (nbc);
}


GDataTable.prototype.sort = function (iCol, sortOrder) {
  if (!this.dhtmlTable) return;
  this.dhtmlTable.sort(iCol, sortOrder);
  if (this.lastColSort > -1) {
    oImg = document.images[this.id+''+this.lastColSort+'img']
    if (oImg) oImg.src = this.iconPath + 'dt_nosort.gif';
  }
  oImg = document.images[this.id+''+iCol+'img']
  if (oImg) oImg.src = this.iconPath + 'dt_sort' + this.dhtmlTable.sortOrder + '.gif';
  this.lastColSort = iCol;
}


function GDataTable_addLine(TDs) {
  this.TR[this.TR.length] = TDs;
}
GDataTable.prototype.addLine = GDataTable_addLine;
GDataTable.prototype.al = GDataTable_addLine;
