//for drag support
var dragging = false;
function Point(pX,pY)
{
  this.x = pX;
  this.y = pY;
}
var startPoint = new Point(0,0);
var endPoint = new Point(0,0);
var srcCell = new Point(0,0);

function Table(nRows, nCols)
{
  this.nRows = nRows||0;
  this.nCols = nCols||0;

  //create an array to hold the data for the cells
  this.data = new Array(nRows); 	
  for (i=0; i1))
    tempSize--;
  this.fontSize = tempSize;
}

function enableColumnHeaders(flag)
{
  this.columnHeadersEnabled = flag;
  if (this.columnHeadersEnabled)
  {
    this.rowStartIndex = 1;
  }
  else
  {
    this.rowStartIdex = 0;
  }
  this.selectedRow = this.rowStartIndex;
}

function enableRowHeaders(flag)
{
  this.rowHeadersEnabled = flag;
  if (this.rowHeadersEnabled)
  { 
    this.columnStartIndex = 1;
  }
  else
  {
    this.columnStartIndex = 0;
  }
}

function enableRowSelection(flag,color)
{
  this.rowSelectionEnabled = flag;
  this.rowSelectionColor = color;
}

function setHeaderBackgroundColor(theColor)
{
  this.headerBackgroundColor = theColor;
}

function setHeaderForegroundColor(theColor)
{
  this.headerForegroundColor = theColor;
}

function setDataForegroundColor(theColor)
{
  this.DataForegroundColor = theColor;
}

function setRowColors(theColors)
{
  this.rowColors = theColors;
}

function onMouseOut(e)
{
  if (at.ns)
  {
    var theCell = this.parent;
    var theTable = this.parent.parent;
    if (!((theTable.rowHeadersEnabled && theCell.columnIndex==0) || (theTable.columnHeadersEnabled && theCell.rowIndex==0)))
    {
      if (theTable.hoverHelpEnabled)
        hideHoverHelp(theTable);
    }
  }  
}

function onMouseOver(e)
{
  var theCell = this.parent;
  var theTable = this.parent.parent;
  var theEvent;
  if (at.ie)
    theEvent = window.event;
  else if (at.ns)
    theEvent = e;
  if (!((theTable.rowHeadersEnabled && theCell.columnIndex==0) || (theTable.columnHeadersEnabled && theCell.rowIndex==0)))
  {
    if (theTable.hoverHelpEnabled)
      showHoverHelp(theEvent,theTable.hoverHelpData[theCell.rowIndex][theCell.columnIndex],theTable);
  }
}

function onMouseUp(e)
{
  if (dragging)
  {
    dragging = false;
    if (at.ns)
      this.releaseEvents(Event.MOUSEMOVE);
  }
}

function onMouseDown(e)
{
  selectRow(this.parent.parent,this.parent.rowIndex);
  dragging = true;
  srcCell.y = this.parent.columnIndex;
  if (at.ie)
      startPoint.x = window.event.clientX;
  else if (at.ns)
  {
      if (at.ns4)
        this.captureEvents(Event.MOUSEMOVE);
      startPoint.x = e.x;
  }
}

function onMouseMove(e)
{
  if (dragging)
  {
    if (at.ie)
      endPoint.x = window.event.clientX;
    else if (at.ns)
      endPoint.x = e.x;
    var theTable = this.parent.parent;
    var newWidth = theTable.columnWidth[srcCell.y] + endPoint.x - startPoint.x;
    if (newWidth>=0)
    {
      theTable.columnWidth[srcCell.y] = newWidth;
      theTable.backupWidth[srcCell.y] = newWidth;
      startPoint.x = endPoint.x;
      resizeTable(theTable);
    }
  }
}

function selectRow(theTable,rowIndex)
{
  if ((theTable.rowSelectionEnabled) && !(theTable.columnHeadersEnabled && rowIndex==0))
  {
    var colorIndex = theTable.selectedRow % theTable.rowColors.length;
    for (j=0;j=this.columnStartIndex)&&(column2>=this.columnStartIndex))
  {
    var temp = '';
    for(i=0;i=this.rowStartIndex) && (row2>=this.rowStartIndex))
  {
    var temp = '';
    for(j=0;j this.data[n][theColumn])
	  this.swapRows(m,n);
      }
      else if (order=="descending")
      {
        if (this.data[m][theColumn] < this.data[n][theColumn])
	  this.swapRows(m,n);
      }
    }
  }
}

function paint()
{
  var x = this.xPos;
  var y = this.yPos;
  var caption = "";
  var colorIndex = 0;
  for(j=0;jcolumnIndex;temp--)
  {
    this.swapColumns(temp,temp-1);
  }
}


function removeColumn(columnIndex)
{
  if ((columnIndex>this.nCols-1) || (columnIndexthis.columnStartIndex)
  {
    for (temp=columnIndex;temprowIndex;temp--)
  {
    this.swapRows(temp,temp-1);
  }
}

function removeRow(rowIndex)
{
  if ((rowIndex>this.nRows-1) || (rowIndexthis.rowStartIndex)
  {
    for (temp=rowIndex;temp 0)
      x = x + width + theTable.horizontalCellSpacing;
    y = theTable.yPos;
  }
}

function showHoverHelp(theEvent,theText,theTable)
{
  if (at.ie)
  {
    theMsg=theText.split('
'); if (theMsg.length>1) { theHelp=''; for (i=0;i'+theText+''); theTable.hoverHelp.document.close(); theTable.hoverHelp.left=theEvent.pageX+5; theTable.hoverHelp.top=theEvent.pageY+5; theTable.hoverHelp.visibility="show"; } } function hideHoverHelp(theTable) { if (at.ns) theTable.hoverHelp.visibility="hide"; }