
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function setDataType(cValue)
  {
    // THIS FUNCTION CONVERTS DATES AND NUMBERS FOR PROPER ARRAY
    // SORTING WHEN IN THE SORT FUNCTION
    var isDate = new Date(cValue);
    if (isDate == "NaN")
      {
        if (isNaN(cValue))
          {
            // THE VALUE IS A STRING, MAKE ALL CHARACTERS IN
            // STRING UPPER CASE TO ASSURE PROPER A-Z SORT
            cValue = cValue.toUpperCase();
            return cValue;
          }
        else
          {
            // VALUE IS A NUMBER, TO PREVENT STRING SORTING OF A NUMBER
            // ADD AN ADDITIONAL DIGIT THAT IS THE + TO THE LENGTH OF
            // THE NUMBER WHEN IT IS A STRING
            var myNum;
            myNum = String.fromCharCode(48 + cValue.length) + cValue;
            return myNum;
          }
        }
  else
      {
        // VALUE TO SORT IS A DATE, REMOVE ALL OF THE PUNCTUATION AND
        // AND RETURN THE STRING NUMBER
        //BUG - STRING AND NOT NUMERICAL SORT .....
        // ( 1 - 10 - 11 - 2 - 3 - 4 - 41 - 5  etc.)
        var myDate = new String();
        myDate = isDate.getFullYear() + " " ;
        myDate = myDate + isDate.getMonth() + " ";
        myDate = myDate + isDate.getDate(); + " ";
        myDate = myDate + isDate.getHours(); + " ";
        myDate = myDate + isDate.getMinutes(); + " ";
        myDate = myDate + isDate.getSeconds();
        //myDate = String.fromCharCode(48 + myDate.length) + myDate;
        return myDate ;
      }
  }
function sortTable(col, tableToSort, id, current, ordre)
  {
    var iCurCell = col + tableToSort.cols;
    var totalRows = tableToSort.rows.length;
    var bSort = 0;
    var colArray = new Array();
    var oldIndex = new Array();
    var indexArray = new Array();
    var bArray = new Array();
    var newRow;
    var newCell;
    var i;
    var c;
    var j;
    for (i=0; i < tableToSort.cols; i++)
      {
	td = document.getElementById(id+i);
//	td = document.getElementById(id.substring(0,2)+i);
	if(td.innerHTML.indexOf("<IMG") != -1)
        td.innerHTML = td.innerHTML.substring(td.innerHTML.indexOf("<IMG"),td.innerHTML.indexOf("</a>")-1);
      }
	  	td = document.getElementById(id+current);
    	td.innerHTML = td.innerHTML.replace('&nbsp;</A>','&nbsp;<img src="../_img/ASC.gif" border="0"></A>')	
    	td.innerHTML = ordre=="ASC"?td.innerHTML.replace('ASC','DESC').replace('ASC','DESC'):td.innerHTML.replace('DESC','ASC').replace('DESC','ASC');

    // ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
    for (i=1; i < tableToSort.rows.length; i++)
      {
        colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
        iCurCell = iCurCell + tableToSort.cols;
      }
    // ** COPY ARRAY FOR COMPARISON AFTER SORT
    for (i=0; i < colArray.length; i++)
      {
        bArray[i] = colArray[i];
      }
    // ** SORT THE COLUMN ITEMS
    //alert ( colArray );
    colArray.sort();
    //alert ( colArray );
    for (i=0; i < colArray.length; i++)
      { // LOOP THROUGH THE NEW SORTED ARRAY
        indexArray[i] = (i+1);
        for(j=0; j < bArray.length; j++)
          { // LOOP THROUGH THE OLD ARRAY
            if (colArray[i] == bArray[j])
              {  // WHEN THE ITEM IN THE OLD AND NEW MATCH, PLACE THE
                // CURRENT ROW NUMBER IN THE PROPER POSITION IN THE
                // NEW ORDER ARRAY SO ROWS CAN BE MOVED ....
                // MAKE SURE CURRENT ROW NUMBER IS NOT ALREADY IN THE
                // NEW ORDER ARRAY
                  for (c=0; c<i; c++)
                  {
                    if ( oldIndex[c] == (j+1) )
                    {
                      bSort = 1;
                    }
                  }
                  if (bSort == 0)
                  {
                  	  oldIndex[i] = (j+1);
                  }
                  bSort = 0;
               }
          }
    }
  // ** SORTING COMPLETE, ADD NEW ROWS TO BASE OF TABLE ....
  newTabSorted = new Array; //Mettre le tableau trié ds une var
  if(ordre == "DESC")
  {
  	iNewTabSorted = 0;
    for (i=oldIndex.length-1; i>=0; i--)
    {
      newRow = new Array;
      for (c=0; c<tableToSort.cols; c++)
        {
			newRow[c] =  tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
        }
		newTabSorted[iNewTabSorted] = newRow;
		iNewTabSorted++;
     }
   }
   else
  {
  	iNewTabSorted = 0;
    for (i=0; i<=oldIndex.length-1; i++)
    {
      newRow = new Array;
      for (c=0; c<tableToSort.cols; c++)
        {
			newRow[c] =  tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
        }
		newTabSorted[iNewTabSorted] = newRow;
		iNewTabSorted++;
     }
   }
  //insert NEW VALUES ROWS  TABLE ....
  for (i=1; i<totalRows; i++)
    {
		newRow = newTabSorted[i-1];
      for (c=0; c<tableToSort.cols; c++)
        {
			tableToSort.rows(i).cells(c).innerHTML = newRow[c] ;
        }
    }
  }
//  End -->

