/*=========================================================================
OBJECT: Tableau
DESC: Gestion de tableau dynamique
TEST PLATFORMS: IE
Creation  01/07/2003
============================================================================*/
// ATTENTION pour utiliser cette librairie il faut redefinir cette methode

// Evenement de click sur une ligne
//	function ClickLine(obj,Tableau, lineNumber )
//	{
//    if( event.button == 1 ) {
//		Tableau.selectLine(obj,lineNumber);
//	    } 
//            else 
//              if( event.button == 2 ) {
//	    	Tableau.clearSelect();
//	    }
//	}
// Evenement doubleclique sur ligne
//	function DblClickLine (obj,Tableau, lineNumber )
//	{
//	}
// Redefinir cette methode quand le constructeur est appelé avec gestionPage=1
//function clickFirstPage()
//{
//}
//function clickLastPage()
//{
//}
//function updateBouton()
//{
//}


// Exemple d'utilisation

//function InitialiserTableau() {
//	tContact = new Table( 'tContact', 1000, linePerPage ,'Contacts',0);
//	tContact.changeHeader( new Line( 'Nom', 'Prénom', 'Service', 'Téléphone'));     
//	tContact.addLine( new Line ( 'GILLOT', 'Olivier', 'ST2I', '06.03.06.57.72','olivier.gillot@st2i.com'));
//	tContact.addLine( new Line ( 'ALAZET', 'Marc', 'ST2I', '06.14.71.32.85','marc.alazet@st2i.com'));
//	document.all.tTableButton.insertAdjacentHTML( "AfterEnd", "<div align='center'>" +   tContact.toHTML() +"</div>" );
//}

// Insertion d'une checkbox dans 1 champ
//	Tableau.addLine( new Line ( 'checkbox|true', 'titi', '3'));

// Evenenment click sur checkbox
// function clickCheckbox (ckBox,Tableau, lineNumber, colNumber) {
//  Tableau[lineNumber][colNumber].checkedValue=ckBox.checked;
//        }

// exemple de Test des checkbox
//    for(i=0;i<Tableau.lineNumber;i++){
//      if(Tableau[i][colNumber].checkedValue)
//            nbChoisie++;
//    }

// Insertion d'une testEdit dans 1 champ la taille sera de 10
//	Tableau.addLine( new Line ( 'textEdit|10|valeur', 'titi', '3'));

// Evenement click sur un text edit
//function clickTextEdit(textEdit,Tableau, lineNumber, colNumber)
//{
//  Tableau[lineNumber][0].editValue=textEdit.value;
//}

// exemple de Test des testEdit
//    for(i=0;i<Tableau.lineNumber;i++){
//      alert(Tableau[i][colNumber].editValue))
//    }

// insertion d'un select
//	Tableau.addLine( new Line ( 'select|text;value|text2;value2...', 'titi', '3'));
//function clickSelect(select,Tableau, lineNumber, colNumber)
//{
//  Tableau[lineNumber][colNumber].selectedIndex=select.selectedIndex;
//  alert(Tableau[lineNumber][colNumber].values[Tableau[lineNumber][0].selectedIndex]);
//  alert(Tableau[lineNumber][colNumber].texts[Tableau[lineNumber][0].selectedIndex]);
//}


// Exemple d'alignemt de la colonne 0 a gauche
// tableau.setAlign(0,"left");

// CSS
document.write('<link rel="stylesheet" type="text/css" href="/css/Tableau.css">');

// Constructor
function Table( name, length, linePerPage, caption, multiLigne, typeNavigation, IndicateurPage, gestionPage)
{
  // Affiche les bouton de navigation
  // typeNavigation = 0 => aucun bouton
  // typeNavigation = 1 => tous les boutons 
  // typeNavigation = 2 => Boutons avant arriere
  // IndicateurPage = 1 => Indication de la page (page 1/3)
  // IndicateurPage = 0 => pas d'indicaion de page
  // gestionPage = 1 => redefinir les methodes
  // gestionPage = 0 => redefinir les methodes
  // gestionPage permet de redefinir les methode de click sur les fleche premiere et dernier page
    this.typeNavigation=typeNavigation;
    this.IndicateurPage=IndicateurPage;

    // descriptif
    this.Objet = "Tableau";
    this.Navigateur = "IE";
    this.Version = "1.0";
    this.Auteur = "Olivier Gillot";
    this.DateModif="1 Juillet 2003";
    
    this.multiLigne =multiLigne;
    this.lineNumber = 0;
    this.colNumber = 0;
    this.name = name;
    this.dimension = length;
    this.currentLine = 0;
    this.setLinePerPage( linePerPage );
    this.header = null;
    this.footer = null;
    this.sortedColumn  = null;
    this.sortedOrder  = 0;
    this.pageNumber = 1;
    this.currentPage = 1;
    this.highLightedLine = null;
    this.searchColumn = 0;
    this.searchedValue = "";
    this.updatableColumnList = null;
    this.caption = caption;
    this.tableHtmlObject=null;
    this.selectedLine=null;
    if ((Table.arguments.length==8)&&(gestionPage==1))
    {
      this.gestionPage=1;
      Table.prototype.goToLastPage=clickLastPage;
      Table.prototype.goToFirstPage=clickFirstPage;
    }
    else
    {
      this.gestionPage=0;
    }
}



// Object's methods
Table.prototype.setPageNumber = TableSetPageNumber;
Table.prototype.changeHeader = TableChangeHeader;
Table.prototype.changeFooter = TableChangeFooter;
Table.prototype.setLinePerPage = TableSetLinePerPage;
Table.prototype.getColumnValueList = TableGetColumnValueList;
Table.prototype.addUpdatableColumn = TableAddUpdatableColumn;
Table.prototype.setColumnAttribute = TableSetColumnAttribute;
Table.prototype.hideColumn = TableHideColumn;
Table.prototype.showColumn = TableShowColumn;
Table.prototype.addLine = TableAddLine;
Table.prototype.deleteLine = TableDeleteLine;
Table.prototype.updateCell = TableUpdateCell;
Table.prototype.toHTML = TableToHTML;
Table.prototype.shellSort = TableShellSort;
Table.prototype.swap = TableSwap;
Table.prototype.search = TableSearch;
Table.prototype.firstPage = TableFirstPage;
Table.prototype.lastPage = TableLastPage;
Table.prototype.previousPage = TablePreviousPage;
Table.prototype.nextPage = TableNextPage;
Table.prototype.subShellSort = TableSubShellSort;
Table.prototype.goToFirstPage = goToFirstPage;
Table.prototype.goToNextPage = goToNextPage;
Table.prototype.goToPreviousPage = goToPreviousPage;
Table.prototype.goToLastPage = goToLastPage;
Table.prototype.displayTable = displayTable;
Table.prototype.sortTable = sortTable;
Table.prototype.selectLine = TableSelectLine;
Table.prototype.clearSelect = TableClearSelect;
Table.prototype.tableNavigation = TableNavigation;
Table.prototype.setAlign = TableSetAlign;
// Constant strings
Table.prototype.AddLineErrorMessage = "Impossible d'ajouter une ligne.";
Table.prototype.SortErrorMessage = "Impossible de trier sur cette colonne.";
Table.prototype.SearchErrorMessage = "Impossible de chercher sur cette colonne.";
Table.prototype.SearchMessage = "Chaine à rechercher dans la colonne ";
Table.prototype.NotFoundErrorMessage = "Chaine non trouvée !!";
Table.prototype.AddUpdatableColumnErrorMessage = "Longueur de champ modifiable non valide";
Table.prototype.SetColumnAttributeErrorMessage = "Impossible de modifier l'attribut de cette colonne";
Table.prototype.GetColumnValueListErrorMessage = "Impossible d'obtenir la liste des valeurs pour cette colonne";

function goToFirstPage() {
	if ( this.firstPage() ) {
	    this.displayTable();
	}
}

function goToNextPage() {
	if ( this.nextPage() ) {
	    this.displayTable();
	}
}

function goToPreviousPage() {
	if ( this.previousPage() ) {
	    this.displayTable();
	}
}

function goToLastPage() {
	if ( this.lastPage() )  {
	    this.displayTable();
	}
}

function sortTable( pCol ) {
	if (this.sortedOrder==0)
		this.sortedOrder=-1;
	if (this.sortedOrder==1)
	{
		this.shellSort( -pCol - 1 );
		this.sortedOrder=-1;
	}
	else
	{
		this.shellSort( pCol + 1 );
		this.sortedOrder=1;
	}
	this.displayTable();
	this.selectedLine=null;
	document.body.style.cursor = "auto";
}

// Permet de definir l'alignement sur une colonne
// Par defaut si cette methode n'est pas appele ca sera center
function TableSetAlign(numCol,TypeAlign) {
  for (var i=0;i<this.lineNumber;i++)
  {
    this[i].typeAlign[numCol]=TypeAlign;
  }
}

function TableNavigation() {
    StringNavigation="<table id='tableNavig"+this.name+"' align='center'><tr>";
    widthTD="28";
    var styleImg='';
    
    if (this.currentPage==1) 
         styleImg="style='display:none'";
    else 
         styleImg="style=''";
    if (this.gestionPage==1)
       StringNavigation+="<td id=firstButton width='"+widthTD+"'><button class='imgPremier' onclick='"+ this.name +".goToFirstPage()'><b>|&lt;</b></button>";
    else
    {
      if (this.typeNavigation==1)
      {
         StringNavigation+="<td width='"+widthTD+"'><button class='imgPremier'"+styleImg+" onclick='"+ this.name +".goToFirstPage()'><b>|&lt;</b></button>";
      }
    }
    if (this.typeNavigation!=0)
         StringNavigation+="<td width='"+widthTD+"'><button class='imgPrecedent'"+styleImg+" onclick='"+ this.name +".goToPreviousPage()'><b>&lt;&lt;</b></button>";
    if (this.IndicateurPage==1){
		if (this.pageNumber!=1){
		   	StringNavigation+="<td align='center'><span align='center' id='pPageNumber'>Page "+ this.currentPage + "/" + this.pageNumber+"</span></td>";
		}
	}
        
    if (this.currentPage==this.pageNumber) 
         styleImg="style='display:none'";
    else 
         styleImg="style=''";
    if (this.typeNavigation!=0)
          StringNavigation+="<td width='"+widthTD+"'><button class='imgSuivant'"+styleImg+" onclick='"+ this.name +".goToNextPage()'><b>&gt;&gt;</b></button>";
    if (this.gestionPage==1)
       StringNavigation+="<td id=lastButton width='"+widthTD+"'><button class='imgDernier' onclick='"+ this.name +".goToLastPage()'><b>&gt;|</b></button>";
    else
    {
      if (this.typeNavigation==1)
      {
         StringNavigation+="<td width='"+widthTD+"'><button class='imgDernier'"+styleImg+" onclick='"+ this.name +".goToLastPage()'><b>&gt;|</b></button>";
      }
    }
    StringNavigation+="</tr></table>";

    return  StringNavigation;
}

function displayTable() {
	document.body.style.cursor = "wait";
	window.status = "Affichage en cours .....";
	var HTMLCode = this.toHTML();
  eval("document.all." + this.name + ".outerHTML = HTMLCode" );
  StringNavigation=this.tableNavigation();
  eval("document.all.tableNavig"+this.name+".outerHTML = StringNavigation");
	document.body.style.cursor = "auto";
	window.status = "Terminé";
	this.tableHtmlObject=eval("document.all." + this.name );
	var lineMax = Math.min( this.lineNumber, this.currentLine + this.linePerPage );
	for( var i = this.currentLine; i < lineMax; i ++ ) {
	var nombre = i-this.currentLine+1;
	    this[i].lineHtmlObject=this.tableHtmlObject.rows[nombre];
	}
  if (this.gestionPage==1)
  {
    updateBouton();
  }
}

function TableToHTML()
{
	var outHTML = "<table class='Tableau' align='center' width='100%' border='1' id='" + this.name + "'  FRAME=BOX RULES=COLS >";
	if ( this.caption != '') {
		outHTML += "<CAPTION class='Caption'>"+this.caption+"</CAPTION>";
	}
	if( this.header != null ) {
		outHTML += "<THEAD class='Thead'>"
		outHTML += this.header.toHTML( true, this.sortedColumn, null, this.updatableColumnList , this.name);
		outHTML += "</THEAD>";
	}
	var lineMax = Math.min( this.lineNumber, this.currentLine + this.linePerPage );
	outHTML += "<TBODY class='Tbody'>";
	for( var i = this.currentLine; i < lineMax; i ++ ) {

	    if (this[ i ].lineHtmlObject) {
		  this[ i ].lineHtmlObject.style.backgroundColor="";		
	    }
		if( this[ i ].highLighted) {
			outHTML += this[ i ].toHTML( false, true, i, this.updatableColumnList , this.name, this.colNumber);
		} else {
			outHTML += this[ i ].toHTML( false, false, i, this.updatableColumnList , this.name, this.colNumber);
		}
	}
	outHTML += "</TBODY> ";
	if( this.footer != null ) {
		outHTML += "<TFOOT class='Tfoot'>"
		outHTML += this.footer.toHTML( true, this.sortedColumn, null, this.updatableColumnList , this.name);
		outHTML += "</TFOOT>";
	}
	outHTML += "</table>";
	docu=eval("document.all.tableNavig"+this.name);
	if (!docu) {
          outHTML += this.tableNavigation();
	}
	return outHTML;
}

function TableSetLinePerPage( linePerPage )
{
	this.linePerPage = linePerPage;
	this.setPageNumber();
}

function TableSetPageNumber()
{
	this.pageNumber = Math.floor( this.lineNumber / this.linePerPage );
	if( ( this.lineNumber % this.linePerPage )  != 0 ) {
		this.pageNumber++;
	}
	if (this.pageNumber==0)
	    this.pageNumber=1;
	if (this.pageNumber<=this.currentPage)
	    if ( this.previousPage() ) {
		this.displayTable();
	    }
	    
}

function TableHideColumn( colNumber )
{
	for( var i = 0; i < TableHideColumn.arguments.length; i++ ) {
		this.setColumnAttribute( TableHideColumn.arguments[ i ], -1 );
	}
}

function TableShowColumn( colNumber )
{
	for( var i = 0; i < TableShowColumn.arguments.length; i++ ) {
		this.setColumnAttribute( TableShowColumn.arguments[ i ], 0 );
	}
}


function TableSelectLine( lineNumber )
{
  if (this.tableHtmlObject==null) {
	  this.tableHtmlObject=eval("document.all." + this.name );
  }
  var nombre = lineNumber-this.currentLine+1;
  if (this.multiLigne==1)
  {
    if( this[ lineNumber ].highLighted) {
	    this[ lineNumber ].highLighted=false;
	    this[ lineNumber ].lineHtmlObject.className="TRNormal";
    } else 
    {
	    this[ lineNumber ].highLighted=true;
	    this[ lineNumber ].lineHtmlObject=this.tableHtmlObject.rows[nombre];
	    this[ lineNumber ].lineHtmlObject.className="TRSelect";
    }
  }
  else
  {
    this.selectedLine=lineNumber;
    for (var i = 0; i<this.lineNumber;i++)
    {
      if (this[ i ].highLighted) {
        this[ i ].lineHtmlObject.className="TRNormal";
        this[ i ].lineHtmlObject.style.backgroundColor="";
        this[ i ].highLighted=false;
      }
    }
    this[ lineNumber ].highLighted=true;
    this[ lineNumber ].lineHtmlObject=this.tableHtmlObject.rows[nombre];
    this[ lineNumber ].lineHtmlObject.className="TRSelect";
  }
}

function TableClearSelect()
{
  this.selectedLine=null;
  var lineMax = Math.min( this.lineNumber, this.currentLine + this.linePerPage );
  for( var i = this.currentLine; i < lineMax; i ++ ) 
  {
	  if (this[ i ].lineHtmlObject)
      this[ i ].lineHtmlObject.style.backgroundColor="";
    this[ i ].highLighted=false;
  }
}
function TableAddUpdatableColumn( colNumber, maxLength )
{
	if( maxLength != 0 ) {
		this.setColumnAttribute( colNumber, maxLength );
	} else {
		alert( Table.prototype.AddUpdatableColumnErrorMessage );
	}
}

function TableSetColumnAttribute( colNumber, attribute )
{
	//colNumber--;
	if( this.header != null ) {
		if( this.updatableColumnList == null ) {
			this.updatableColumnList = new Array( this.header.itemNumber );
		}
		if( colNumber < this.header.itemNumber ) {
			this.updatableColumnList[ colNumber ] = attribute;
		} else {
			alert( Table.prototype.SetColumnAttributeErrorMessage );
		}
	}
}

function TableUpdateCell( lineNumber, colNumber, value )
{
	if( typeof( this[ lineNumber ][ colNumber ] ) == "string" ) {
		this[ lineNumber ][ colNumber ] = value;
	} else {
		this[ lineNumber ][ colNumber ] = parseInt( value, 10 );
	}
}


function TableGetColumnValueList( idCol, col )
{
	idCol--;
	col--;
	if( col < this.header.itemNumber && idCol < this.header.itemNumber ) {
		var valueList = "";
		for( var i = 0; i < this.lineNumber; i++ ) {
			valueList += this[ i ][ idCol ] + "{" + this[ i ][ col ] + "}";
		}
		return valueList;
	} else {
		alert( Table.prototype.GetColumnValueListErrorMessage );
		return null;
	}
}



function TableChangeHeader( line )
{ 
	this.header = line;
	this.colNumber=this.header.itemNumber;
}

function TableChangeFooter( line )
{ 
	this.footer = line;
}

function TableAddLine( line )
{
	if( this.lineNumber < this.dimension ) {
		this[ this.lineNumber++ ] = line;
		this.setPageNumber();
	} else {
		alert( Table.prototype.AddLineErrorMessage );
	}
}

function TableDeleteLine( number )
{
    this.lineNumber--;
    for( var i = number; i < this.lineNumber; i ++ ) {
	this[i]=this[i+1]
    }
    this.setPageNumber();
    this.selectedLine=null;
}

function TableFirstPage()
{
	if( this.currentPage != 1 ) {
	    this.currentLine = 0;
	    this.currentPage = 1;
	    return true;
	} else {
	    return false;
	}
}

function TableLastPage()
{
	if( this.currentPage != this.pageNumber ) {
	    this.Update;
	    this.currentLine = ( this.pageNumber - 1 ) * this.linePerPage;
	    this.currentPage = this.pageNumber;
	    return true;
	} else {
	    return false;
	}
	
}

function TablePreviousPage()
{
	if( this.currentPage != 1 ) {
		this.currentLine = this.currentLine - this.linePerPage;
		this.currentPage--;
		return true;
	} else {
		return false;
	}
}

function TableNextPage()
{
	if( this.currentPage != this.pageNumber ) {
		this.currentLine = this.currentLine + this.linePerPage;
		this.currentPage++;
		return true;
	} else {
		return false;
	}
}

function TableSearch( col, promptSearchString )
{
	if( TableSearch.arguments.length == 1 ) {
		promptSearchString = true;
	}
	if( promptSearchString == false || col < this.header.itemNumber ) {
		if( promptSearchString ) {
			var searchString = prompt( Table.prototype.SearchMessage + this.header[ col ], this.searchedValue );
		} else {
			searchString = this.searchedValue;
			col = this.searchColumn;
		}
		if( searchString != null && searchString.length != 0 ) {
			this.searchedValue = searchString;
			var found = false;
			var i, startLineSearch;
			if( this.highLightedLine != null && this.searchColumn == col ) {
				startLineSearch = this.highLightedLine + 1;
			} else {
				this.searchColumn = col;
				startLineSearch = 0;
			}
			for( var j = 0; j < this.lineNumber; j++ ) {
				i = ( j + startLineSearch ) % this.lineNumber;
				if( typeof( this[ i ][ col ] ) == "string" ) {
					var re = new RegExp( searchString, "i" );
					if( this[ i ][ col ].substring(0, 30).search( re ) != -1 ) {
						found = true;
						break;
					}
				} else if( this[ i ][ col ] == searchString ) {
						found = true;
						break;
				}
			}
		
			if( found ) {
				this.currentLine = Math.floor( i / this.linePerPage ) * this.linePerPage;
        			if (this.multiLigne==0) {
        			        // on efface les ligne deja selectionné
     			              for (var ii = 0; ii<this.lineNumber;ii++)
                                      {
	                                  if (this[ ii ].highLighted) {
                                       	      this[ ii ].lineHtmlObject.className="TRNormal";
	                                      this[ ii ].lineHtmlObject.style.backgroundColor="";
	                                      this[ ii ].highLighted=false;
	                                  }
	                              }
                                }
				this[ i ].highLighted=true;
				//this.highLightedLine = i;
				this.currentPage = Math.floor( ( this.currentLine + 1 ) / this.linePerPage );
				if( ( ( this.currentLine +  1 ) % this.linePerPage ) != 0 ) {
					this.currentPage++;
				}
				return true;
			} else {
				alert( Table.prototype.NotFoundErrorMessage );
				return false;
			}
		} else {
			return false;
		}
	} else {
		alert( Table.prototype.SearchErrorMessage );
		return false;
	}	
}

function TableSwap( i , j )
{
	var tempitem = this[ i ];
	this[ i ] = this[ j ];
	this[ j ] = tempitem;
}

function TableShellSort( col )
{	
     for (var i = 0; i<this.lineNumber;i++)
      {
        if (this[ i ].lineHtmlObject)
      	  this[ i ].lineHtmlObject.style.backgroundColor="";
        this[ i ].lineHtmlObject=null;
	this[ i ].highLighted=false;
      }
	if( typeof( col ) == "number" ) {
		var colTempo;
		colTempo = col;
		col = new Array();
		col[ 0 ] = colTempo;
	}
	if( Math.abs( col[ 0 ] ) < ( this.header.itemNumber + 1 ) ) {
		var i, j, start, length;
		this.currentLine = 0;
		this.currentPage = 1;
		this.sortedColumn = Math.abs( col[ 0 ] ) - 1;
		this.highLightedLine = null;
		this.subShellSort( col[ 0 ], 0, this.lineNumber );
		start = 0;
		length = 0;
		for( i = 1; i < col.length; i++ ) {
			start = 0;
			length = 1;
			for( j = 0; j < ( this.lineNumber - 1 ); j++ ) {
				if( this[ j ][ Math.abs( col[ i - 1 ] ) - 1 ] == this[ j + 1 ][ Math.abs( col[ i - 1 ] ) - 1 ] ) {
					length++;
				} else {
					if( length > 1 ) {
						this.subShellSort( col[ i ], start, length );
					}
					start = j + 1;
					length = 1;
				}
			}
		}
	} else {
		alert( Table.prototype.SortErrorMessage );
	}
}


function TableSubShellSort( col, start, length )
{
	var reverseSort = false;
	if( col < 0 ) {
		reverseSort = true;
		col = Math.abs( col );
	}
	var delta, i, theEnd;
	if( length > 2 ) {
		delta = length - 1 - 1;
		while( delta > 0 ) { 
			theEnd = true;
			for( i = start; i <= ( start + length - 1 - delta ); i++ ) {
				if( ( !reverseSort && FirstValueIsGreaterThanSecond( this[ i ][ col - 1 ], this[ i + delta ][ col - 1 ] ) ) || ( reverseSort && FirstValueIsGreaterThanSecond( this[ i + delta ][ col - 1 ], this[ i ][ col - 1 ] ) ) ) {
					this.swap( i, i + delta );
					theEnd = false;
				}
			}
			if( theEnd ) {
			 	delta = Math.floor( ( delta + 1 ) / 3 );
			}	
		}
	} else if( length == 2 ) {
		if( ( !reverseSort && FirstValueIsGreaterThanSecond( this[ start ][ col - 1 ], this[ start + 1 ][ col - 1 ] ) ) || ( reverseSort && FirstValueIsGreaterThanSecond( this[ start + 1 ][ col - 1 ], this[ start ][ col - 1 ] ) ) ) {
			this.swap( start, start + 1 );
		}
	}
	
}

function FirstValueIsGreaterThanSecond( col1, col2 )
{
	if( typeof( col1 ) != typeof( col2 ) ) {
		if( typeof( col1 ) == "string" ) {
			return false;
		} else {
			return true;
		}
	} else {
		if( col1 > col2 ) {
			return true;
		} else {
			return false;
		}
	}
}


//	Traitement de l'Evenement Click sur une colonne
	function ClickTable(Tableau, col )
	{
		if( event.button == 1 ) {
			document.body.style.cursor = "wait";
			Tableau.sortTable(  col );
		} else if( event.button == 2 ) {
			if( Tableau.search( col ) ) {
				Tableau.displayTable();
			}
		}
	}
	
// Object Chekbox
function CheckboxObj (value) {
        this.checkedValue=value;
}

// Object TextEdit
function TextEditObj (value,taille) {
        this.editValue=value;
        this.editSize=taille;
}

// Object TextEdit
function SelectObj (elements) {
  var value="";
  var text="";
  for(var iElem=1;iElem<elements.length;iElem++)
  {
    var selectElements=elements[iElem].split(';');
    if (value!="")
    {
      value=value+";";
      text=text+";";
    }
    value=value+selectElements[0];
    text=text+selectElements[1];
  }
 this.values=value.split(";");
 this.texts=text.split(";");
 this.selectedIndex=0;
}
//Line object

// Constructor
function Line( colList )
{
	var argv = Line.arguments;
	var argc = Line.arguments.length;
  this.title="";
	this.itemNumber = argc;
	this.highLighted = false;
	this.lineHtmlObject=null;
	this.color=null;
	this.typeAlign=new Array();
	for( var i = 0; i < argc; i++ ) {
	  this.typeAlign[i]="center";
		if( typeof( argv[ i ] ) == "string" ) {
			if( argv[ i ].length == 0 ) {
				this[ i ] = "";
			} else {
			        if (argv[ i ]=="checkbox|true") {
				        this[ i ] = new CheckboxObj(true);
			          this[i].type="checkbox";
			          this[i].readOnly=false;
				      } else {
				          if (argv[ i ]=="checkbox|false") {
				            this[ i ] = new CheckboxObj(false);
			              this[i].type="checkbox";
    			          this[i].readOnly=false;
				          } else {
  				          if (argv[ i ]=="checkbox|readonly|false") {
  				            this[ i ] = new CheckboxObj(false);
  			              this[i].type="checkbox";
      			          this[i].readOnly=true;
  				          } else {
    				          if (argv[ i ]=="checkbox|readonly|true") {
    				            this[ i ] = new CheckboxObj(true);
    			              this[i].type="checkbox";
        			          this[i].readOnly=true;
    				          } else {
    				            if (argv[ i ].substring(0,8)=="textEdit") {
    				              var tableEdit=argv[i].split('|');
    				              this[ i ] = new TextEditObj(tableEdit[2],tableEdit[1]);
    			                this[i].type="textEdit";
    				            } else {
        				            if (argv[ i ].substring(0,7)=="select|") {
        				              var selectElements=argv[i].split('|');
        				              this[ i ] = new SelectObj(selectElements);
        			                this[i].type="select";
        				            } else {
          				              if (argv[ i ].substring(0,5)=="title") {
          				                var titleText=argv[i].split('|');
          			                  this.title=titleText[1];
          				              } else {
                				          this[ i  ] = argv[ i ];
                				        }
            				        }
        				        }
      				      }
      				   }
    			   }
    			}
			}
		} else {
			this[ i ] = argv[ i ];
		}
	}
}

function mouseOverTD(Col)
{
    //  alert('mouseOverTD');

    Col.className="TDOver";
}

function mouseOutTD(Col, Tableau, colNumber)
{
    //    alert('mouseOutTD');

    if (Tableau.sortedColumn==colNumber)
      Col.className="TDSort";
    else
      Col.className="TDNormal";
}

function mouseOverTR(Line, Tableau, lineNumber)
{
     if (Tableau[lineNumber].highLighted)
	 Line.className="TRSelect";
     else
	 Line.className="TROver"; 
}

function mouseOutTR(Line, Tableau, lineNumber)
{
     if (Tableau[lineNumber].highLighted)
	 Line.className="TRSelect";
     else
	 Line.className="TRNormal";	 
}
// Tentative Java Script Daniel.
function CheckValue(value, column)
{	var ok = true;
	for (i=0; i<this.lineNumber; i++)
	{	if (this[ i ][ column ] == value)
		{	ok = false;
		}
	}
	return ok;
}

// Ojbect's methods
Line.prototype.toHTML = LineToHTML;
Line.prototype.changeColor = LineChangeColor;

function LineChangeColor(theColor)
{ 
    this.color=theColor;
    if (this.lineHtmlObject!=null){
	this.lineHtmlObject.style.color=this.color;
    }
}

function LineToHTML( isHead, sortedColumn, lineNumber, updatableColumnList , Tableau, colNumber)
{
	var outHTML = "<tr ";
	if (this.title!="")
	{
	  outHTML=outHTML+"title='"+this.title+"'";
	}
	if( lineNumber != null ) {
		var isHighligted = sortedColumn;
		// Modif Stef supprime equivalent du ALT	outHTML += " title='ligne " + ( lineNumber + 1 ) + "'"; 
		outHTML += " id='ligne" + ( lineNumber + 1 ) + "'"; 
	}
	if( isHead ) {
		outHTML += ">";
		for( var i = 0; i < this.itemNumber; i ++ ) {
			if( updatableColumnList == null || !updatableColumnList[ i ] || updatableColumnList[ i ] != -1 ) {
				outHTML += "<td align=center onmouseover='mouseOverTD(this);' onmouseout='mouseOutTD(this,"+Tableau+","+i+");'"
				if( sortedColumn != null && i == sortedColumn ) {
					outHTML += "class='TDSort'"
				}
				else {
					outHTML += "class='TDNormal'"
				}
				outHTML += " onmousedown='ClickTable("+ Tableau + ',' + i + ")'><strong>" + this[ i ] + "</strong></td>";
				//outHTML += "' align=center '><strong>" + this[ i ] + "</strong></td>";
			}
		}
	} else {
		if( isHighligted ) {
			outHTML += " class='TRSelect' ";
		} else {
		    outHTML += " class='TRNormal' ";
		}
		outHTML += " style='color:"+this.color+"'";
		outHTML += " onmouseover='mouseOverTR(this,"+ Tableau +","+lineNumber+")' onmouseout='mouseOutTR(this,"+ Tableau +","+lineNumber+")' ondblClick='DblClickLine(this," + Tableau + ','  + lineNumber + ")' onmousedown='ClickLine(this," + Tableau + ','  + lineNumber + ")' >";
		for( var i = 0; i < colNumber; i ++ ) {
			if( updatableColumnList == null || !updatableColumnList[ i ] || updatableColumnList[ i ] != -1 ) {
				outHTML += "<td align="+this.typeAlign[i]+" >";
				var Espaces="";
				if (this.typeAlign[i]!="center")
				 Espaces="&nbsp;&nbsp;";
				if( updatableColumnList != null && updatableColumnList[ i ] ) {
					outHTML += "<input TYPE='text' SIZE='" + updatableColumnList[ i ] + "' NAME='cell_" + lineNumber + "_" + i + "' maxlength="+ updatableColumnList[ i ] +" VALUE='"+ this[ i ] +"' TABINDEX=" + ( lineNumber + 1 ) + ">";
				} else {
				  if (typeof(this[ i ])!="object")
					  outHTML += Espaces+this[ i ];
					else
					{
				    if (this[ i ].type=="textEdit") {
					    outHTML += "<input type='text' size="+this[i].editSize+" name='textEdit_"+Tableau+"_"+lineNumber+"_"+i+"' Value='"+this[i].editValue+"'";
					    outHTML += "onchange='clickTextEdit(this, " + Tableau + "," + lineNumber + ", " + i + ")' >";
					  }
					  else 
					    if (this[ i ].type=="checkbox") {
  					    outHTML += "<input type='checkbox' name='checkbox_"+Tableau+"_"+lineNumber+"_"+i+"'";
  					    if (this[ i ].checkedValue)
  					      outHTML += " checked ";
  					    if (this[ i ].readOnly)
  					      outHTML += " disabled ";
  					    outHTML += " onclick ='clickCheckbox(this, " + Tableau + "," + lineNumber + ", " + i + ")' >";
					    }
					    else
  					    if (this[ i ].type=="select") {
  					      outHTML+="<SELECT name='oSelect_"+Tableau+"_"+lineNumber+"_"+i+"' onChange='clickSelect(this, " + Tableau + "," + lineNumber + ", " + i + ")' >";
  					      for(var iElem=0;iElem<this[i].values.length;iElem++)
  					      {
  					        if (this[ i ].selectedIndex==iElem){
    					        outHTML+="<OPTION SELECTED VALUE="+this[i].values[iElem]+">"+this[i].texts[iElem]+"</option>";
    					      }
    					      else
    					      {
    					        outHTML+="<OPTION VALUE="+this[i].values[iElem]+">"+this[i].texts[iElem]+"</option>";
    					      }
  					      }
  					      outHTML+="</SELECT>";
	  				    }
  				}
				}
				outHTML += "</td>";
			}
		}
	}
	outHTML += "</tr>";
	return outHTML;
}


