/*

  Liste des styles importants pour les cellules :
    - Couleur de fond
    - Couleur de cellule

*/



/*
Global functions
*/
function GetElement(oElement,sMatchTag) 
  {
  while (oElement!=null && oElement.tagName!=sMatchTag) 
    {//alert(oElement.tagName)
    if(oElement.id==obj.Name) return null;
    oElement = oElement.parentElement
    }
  return oElement
  }
  
  
  
  
function fixSel(oName,oSel)//oName=string, oSel=object
  {
  var oEditor = eval(oName);

  if(oSel.parentElement != null)
    {
    if(!IsInsideEditor(oSel.parentElement()))
      {
      oEditor.focus();
      var oSel = oEditor.document.selection.createRange();
      }
    }
  else
    {
    if(!IsInsideEditor(oSel.item(0)))
      {
      oEditor.focus();
      var oSel = oEditor.document.selection.createRange();
      }
    }
  return oSel;
  }
function fixSelType(oName,oSel,sType)//oName=string, oSel=object
  {
  var oEditor = eval(oName);
  if(oSel.parentElement != null)
    {
    if(!IsInsideEditor(oSel.parentElement()))
      {
      oEditor.focus();
      var sType = oEditor.document.selection.type;
      }
    }
  else
    {
    if(!IsInsideEditor(oSel.item(0)))
      {
      oEditor.focus();
      var sType = oEditor.document.selection.type;
      }
    }
  return sType;
  }
function IsInsideEditor(oElement)
  {
  while (oElement!=null)
    {
    if(oElement.tagName=="BODY" && oElement.contentEditable=="true")return true;
    oElement = oElement.parentElement;
    }
  return false;
  }
function retFalse()
  {
  return false;
  }  
/*
end of global functions
*/

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : WysiwygEditor(iframe)
  ----------
    DESCRIPTION :
      "Constructeur" de l'objet utilisé pour effectuer l'édition WYSIWYG.

    PARAMETRES : 
      iframe = nom de l'iframe
    
    VALEURS RETURNEES :
      aucune    
*/
function WysiwygEditor(iframe, objName)
{
  // propriétés de l'objet
  this.Editor = eval(iframe);
  this.Editor.document.designMode = "on"; // Permet le mode édition

  this.Name = this.Editor.name;
  if(typeof objName == "undefined") this.ObjName = 'obj';
  else this.ObjName = objName
  this.Sel;
  this.SelType;
//  this.Stylesheet = "http://ipka/site1/theme/styles.css";
  this.Stylesheet;
  this.StyleMaze = 0;
  this.TableIdMax = 0;
  // Initialise le contenu du body de l'iframe
/*
  this.PrebuiltBody = "<table border=\"1\" cellspacing=\"0\" borderColor=\"#000000\" cellpadding=\"2\" leftmargin=\"0\" topmargin=\"0\"><tr bgcolor=\"#888888\">";
  this.PrebuiltBody += "<td width=\"50\">0</td><td width=\"50\">1</td><td width=\"50\">2</td><td width=\"50\">3</td><td width=\"50\">4</td></tr><tr height=100 >";
  this.PrebuiltBody += "<td colspan=4 rowspan=4>1.1</td><td>Salut</td></tr><tr>";
  this.PrebuiltBody += "<TD>a</TD></tr><tr>";
  this.PrebuiltBody += "<TD>b</TD></tr><tr>";
  this.PrebuiltBody += "<TD>c</TD></tr><tr>";
//  this.PrebuiltBody += "<td colspan=\"2\">2.1</td><td>2.3</td><td>2.4</td><td>2.4</td></tr><tr>";
//  this.PrebuiltBody += "<td colspan=\"3\">3.1</td><td rowspan=2>3.4</td><td>2.4</td></tr><tr>";
//  this.PrebuiltBody += "<td colspan=\"3\">3.1</td><td>2.4</td></tr><tr>";
  this.PrebuiltBody += "<td>4.1</td><td>4.2</td><td>4.3</td><td>4.4</td><td>2.4</td></tr></table>";
*/
  this.PrebuiltBody = ''
  this.Color1 = "#000000"
  
  this.PasteTable = true;
  this.BodyClass = "Content"
  

  this.RealPosition; // tableau contenant les vrais indices des cellules du tableau HTMl // = new Array(new Array());
  this.newWin; // fenêtre popup
  // Méthodes de l'objet
  this.RUN = RUN;
  this.PutContent = PutContent;
  this.SaveSelection = SaveSelection;
  this.DoCmd = DoCmd;
  this.RedimArray = RedimArray;
  this.SplitCellH = SplitCellH;
  this.SplitCellV = SplitCellV;
  this.MergeCellH = MergeCellH;
  this.MergeCellV = MergeCellV;
  this.AllColSpan = AllColSpan;
  this.AllRowSpan = AllRowSpan;
  this.CellAlign = CellAlign;
  this.InsertRowUp = InsertRowUp;
  this.InsertRowDown = InsertRowDown;
  this.InsertColLeft = InsertColLeft;
  this.InsertColRight = InsertColRight;
  this.ChangeColor = ChangeColor;
  this.DelRow = DelRow;
  this.DelCol = DelCol;
  this.Format = Format;
  this.CreateTable = CreateTable;
  this.EditTable = EditTable;
  this.ChangeWidth = ChangeWidth;
  this.ChangeHeight = ChangeHeight;
  this.AlignTable = AlignTable;
  this.ChangeFont = ChangeFont;
  this.IsOver500Px = IsOver500Px;
  this.Paste = Paste;
  this.InsertImage = InsertImage;
  this.InsertLink = InsertLink;
  this.InsertLinkFromForum = InsertLinkFromForum;
/*  this.cleanFromWord = cleanFromWord;
  this.getContent = getContent;
  this.getContentBody = getContentBody;
*/  
}

function RUN()
{
//  this.PrebuiltBody = "<table border=1><tr bgcolor=#888888><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr><td colspan=3>abc</td><td>556</td></tr></table>";
  // Initialise le contenu du body de l'iframe
  this.PrebuiltHtml = "<html><head>";
  //this.PrebuiltHtml += "<link href=\"" + this.Stylesheet + "\" rel=\"stylesheet\" type=\"text/css\">";
  //this.PrebuiltHtml += "<style>BODY{background-image:url('ghost.gif');}</style>";
  this.PrebuiltHtml += "</head><body name=\"test\" class=" + this.BodyClass + " id=Editor marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" topmargin=\"0\">" + this.PrebuiltBody + "</body></html>";

  //Initialisations de l'objet
  this.PutContent(this.PrebuiltHtml);
  this.Editor.focus();
  this.SaveSelection();
  this.IsInHeader = IsInHeader;
  //this.Editor.document.body.onkeypress = DoOnKeyPress;
  this.Editor.onkeypress = DoOnKeyPress;
  //this.Editor.document.body.onclick = IsInHeader;
  this.Editor.onclick = IsInHeader;
  if(this.ObjName == 'obj2') this.Editor.document.body.onpaste = DoPaste2;
  else this.Editor.document.body.onpaste = DoPaste;
  if(this.Editor.document.all.tags("TABLE").length != 0)
  {
     var align = this.Editor.document.all.tags("TABLE")[0].align;
     //this.Editor.document.body.background = "TABLE_EDITOR/imgs/bg-"+align+".gif";
	 if (this.StyleMaze == 1)
	 {
	     //this.Editor.document.body.style.background = "url(\"TABLE_EDITOR/imgs/bgMaze-"+align+".gif\")";
	 }else{
	     //this.Editor.document.body.style.background = "url(\"TABLE_EDITOR/imgs/bg-"+align+".gif\")";
	 }
  }
  else if (this.PasteTable)
     //this.Editor.document.body.background = "TABLE_EDITOR/imgs/bg-left.gif"
	 if (this.StyleMaze == 1)
	 {
		 //this.Editor.document.body.style.background = "url(\"TABLE_EDITOR/imgs/bgMaze-left.gif\")";
	 }else{
		 //this.Editor.document.body.style.background = "url(\"TABLE_EDITOR/imgs/bg-left.gif\")";
	 }
	 

  for(i=0; i < this.Editor.document.all.tags("TABLE").length; i++)
  {
    //ShowNoBorder(this.Editor.document.all.tags("TABLE")[i]);
  }
  
}
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : SaveSelection()
  ----------
    DESCRIPTION :
      Lors de l'appel de cette fonction, la sélection dans la zone 
      d'édition ainsi que son type est sauvegardée

    PARAMETRES : 
      auncun
    
    VALEURS RETURNEES :
      aucune    
*/
function SaveSelection()
{
  this.Sel = this.Editor.document.selection.createRange();
  this.SelType = this.Editor.document.selection.type;
  this.Sel = fixSel(this.Name, this.Sel)
  this.SelType = fixSelType(this.Name, this.Sel, this.SelType)
}

/*
  FONCTION : doOnKeyPress()
  ----------
    DESCRIPTION :
      Test si lorsqu'on ajoute tape du texte, on est dans un tableau si on est en edit table

    PARAMETRES : 
      auncun
    
    VALEURS RETURNEES :
      aucune    
*/
function DoOnKeyPress()
{
//  if()
  var obj = eval("document.parentWindow.obj")//+this.ObjName)
  try
  {
    var tmp = document.parentWindow.obj2.Name
    return
  }
  catch(e) {}
  obj.SaveSelection();
  var Sel = obj.Sel;
  if(obj.PasteTable && obj.Editor.event.keyCode!=13)
  {
    try
    {
     //alert(Sel.htmlText)
      var TABLE = document.parentWindow.GetElement(Sel.parentElement(),"TABLE")
      var test = TABLE.name
    }
    catch(e)
    {
      alert("You can't edit text out of a table. Please set the cursor into a table")
      return false;
    }
  }
}


/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : PutContent(prebuiltHtml)
  ----------
    DESCRIPTION :
      Permet d'initialiser la zone d'édition avec un contenu

    PARAMETRES : 
      prebuiltHtml = le code source initial de la zone d'édition
    
    VALEURS RETURNEES :
      aucune    
*/
function PutContent(prebuiltHtml)
{
  //var doc = this.Editor.document.open("text/html", "replace");
  //doc.write(prebuiltHtml);
  //doc.close();
  this.Editor.innerHTML = prebuiltHtml;
  
  var EdTmp = eval(this.Name + "Tmp")
//  alert(EditorTmp.outerHTML)
  EdTmp.document.designMode = "on"; // Permet le mode édition
  var doc = EdTmp.document.open("text/html", "replace");
  doc.write(prebuiltHtml);
  doc.close();
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : DoCmd(command)
  ----------
    DESCRIPTION :
      Permet d'effectuer une commande telle que "gras", "italique", ... sur une
      sélection de texte 

    PARAMETRES : 
      command = Chaine de caractère contenant la commande à effectuer
           Liste sur le site :
           http://msdn.microsoft.com/workshop/author/dhtml/reference/commandids.asp  
    
    VALEURS RETURNEES :
      aucune    
*/
function DoCmd(command)
{
  this.SaveSelection();
  var Target = (this.SelType == "None" ? this.Editor.document : this.Sel);
  Target.execCommand(command);
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : SplitCellH()
  ----------
    DESCRIPTION :
      Permet de séparer la cellule ayant la sélection en deux cellules adjacentes
      horizontalement.      

    PARAMETRES : 
      aucun
    
    VALEURS RETURNEES :
      aucune    
*/
function SplitCellH()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(TD,"TR")
    var TABLE = GetElement(TR,"TABLE")
    // construit la variable Array dynamiquement pour géréer les bons indices
    this.RedimArray(TABLE, this.RealPosition); 
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }  
  var iCell = TD.cellIndex;
  var iRow = TR.rowIndex;
  var iCellReel;
  var iRowReel;
  for (i=0; i<TABLE.rows(0).cells.length; i++)
  {
    if('' + iRow + '.' + iCell == this.RealPosition[iRow][i])
    {
      iCellReel = parseInt(i);
      iRowReel = parseInt(iRow);
      i = TABLE.rows(0).cells.length;
    } 
  } 

  if (TD.colSpan > 1)
  {
    newColSpan1 = Math.ceil(TD.colSpan/2);
    newColSpan2 = TD.colSpan - newColSpan1;
    TR.cells(iCell).colSpan = newColSpan1;
    var newCell = TR.insertCell(iCell+1);
    newCell.innerHTML = "&nbsp;"
    TR.cells(iCell+1).colSpan = newColSpan2;
    TR.cells(iCell+1).rowSpan = TD.rowSpan;
    if(TR.cells(iCell).align != "") TR.cells(iCell+1).align = TR.cells(iCell).align;
    if(TR.cells(iCell).vAlign != "") TR.cells(iCell+1).vAlign = TR.cells(iCell).vAlign;
    if(TR.cells(iCell).style.border != "") TR.cells(iCell+1).style.border = TR.cells(iCell).style.border;
    if(TR.cells(iCell).style.background != "") TR.cells(iCell+1).style.background = TR.cells(iCell).style.background;
    if(TR.cells(iCell).className != "") TR.cells(iCell+1).className = TR.cells(iCell).className;
    if(TR.cells(iCell).id != "") TR.cells(iCell+1).id = TR.cells(iCell).id;
    if(TR.cells(iCell).perso != "") TR.cells(iCell+1).perso = TR.cells(iCell).perso;
    if(TR.cells(iCell).borderColor != "") TR.cells(iCell+1).borderColor = TR.cells(iCell).borderColor;
    if(TR.cells(iCell).bgColor != "") TR.cells(iCell+1).bgColor = TR.cells(iCell).bgColor;
  }
  else // colspan=1
  {
    var cList = TABLE.all.tags("COL");

    var col = eval(cList[iCellReel]);
    var newCol = document.createElement("<col>");
    var width = parseInt(col.width);
    newCol.width = Math.ceil(width/2);
    col.insertAdjacentElement("AfterEnd",newCol);
    if(!isNaN(width) && width > 1) col.width = width - parseInt(newCol.width);

    for (i=0; i < TABLE.rows.length; ++i)
    {
      var point = this.RealPosition[i][iCellReel].indexOf('.')
      var iCellHtml = parseInt(this.RealPosition[i][iCellReel].substring(point+1));
      var iRowHtml = parseInt(this.RealPosition[i][iCellReel].substring(0, point));
      if (i != iRow)
      {
        TABLE.rows(i).cells[iCellHtml].colSpan ++;
      }
      else 
      {
        var newCell = TABLE.rows(i).insertCell(iCellHtml+1);
        newCell.innerHTML = "&nbsp;"
        TABLE.rows(i).cells(iCellHtml+1).rowSpan = TD.rowSpan;
        if(TD.align != "") newCell.align = TD.align;
        if(TD.vAlign != "") newCell.vAlign = TD.vAlign;
        if(TD.style.border != "") newCell.style.border = TD.style.border;
        if(TD.style.background != "") newCell.style.background = TD.style.background;
        if(TD.className != "") newCell.className = TD.className;
        if(TD.id != "") newCell.id = TD.id;
        if(TD.perso != "") newCell.perso = TD.perso;
        if(TD.borderColor != "") newCell.borderColor = TD.borderColor;
        if(TD.bgColor != "") newCell.bgColor = TD.bgColor;
        
      }
      // On saute toutes les lignes englobées par le rowSpan
      i += TABLE.rows(i).cells[iCellHtml].rowSpan - 1;
    }
  }
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : SplitCellV()
  ----------
    DESCRIPTION :
      Permet de séparer la cellule ayant la sélection en deux cellules adjacentes verticalement.      

    PARAMETRES : 
      aucun
    
    VALEURS RETURNEES :
      aucune    
*/
function SplitCellV()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD");
    var TR = GetElement(TD,"TR")
    var TABLE = GetElement(TR,"TABLE")
    // construit la variable Array dynamiquement pour géréer les bons indices
    this.RedimArray(TABLE, this.RealPosition); 
  }
  catch(e)
  {
    alert('No table selected !');
    return;
  }  
  var iCellHtml = TD.cellIndex;
  var iRowHtml = TR.rowIndex;
  for (i=0; i<TABLE.rows(0).cells.length; i++)
  {
    if('' + iRowHtml + '.' + iCellHtml == this.RealPosition[iRowHtml][i])
    {
      iCellReel = parseInt(i);
      iRowReel = parseInt(iRowHtml);
      i = TABLE.rows(0).cells.length;
    } 
  } 
  var newRowSpan1 = Math.ceil(TD.rowSpan/2);
  var iNewRow = iRowHtml + newRowSpan1;
  if (TD.rowSpan > 1)
  {
    var iCellReel = 0;
    while( this.RealPosition[iRowHtml][iCellReel] != ''+iRowHtml+'.'+iCellHtml && iCellReel < this.RealPosition[1].length)
    {
      iCellReel++;
    }  
    var iNewRowHtml = iRowHtml;
    var i = iCellReel;
    while( i >= 0)
    {
      var point = this.RealPosition[iNewRow][i].indexOf('.');
      var iNewRowHtml = parseInt(this.RealPosition[iNewRow][i].substring(0, point));
      var iNewCellHtml = parseInt(this.RealPosition[iNewRow][i].substring(point+1));  
      if (iNewRowHtml > iRowHtml) break;
      i--;
    }
    if (i == -1) iNewCellHtml = -1;
    var newRowSpan2 = TD.rowSpan - newRowSpan1;
    var newCell = TABLE.rows(iNewRow).insertCell(iNewCellHtml+1);
    newCell.innerHTML = "&nbsp;"
    TD.rowSpan = newRowSpan1;
    newCell.rowSpan = newRowSpan2;
    newCell.colSpan = TD.colSpan;
    if(TD.align != "") newCell.align = TD.align;
    if(TD.vAlign != "") newCell.vAlign = TD.vAlign;
    if(TD.style.border != "") newCell.style.border = TD.style.border;
    if(TD.style.background != "") newCell.style.background = TD.style.background;
    if(TD.className != "") newCell.className = TD.className;
    if(TD.id != "") newCell.id = TD.id;
    if(TD.perso != "") newCell.perso = TD.perso;
    if(TD.borderColor != "") newCell.borderColor = TD.borderColor;
    if(TD.bgColor != "") newCell.bgColor = TD.bgColor;
  }
  else // rowSpan =1
  {
    var height = parseInt(TABLE.rows(iRowHtml).height);
    var newRow = TABLE.insertRow(iNewRow);
    if(!isNaN(height) && height > 1)
    {
      newRow.height = Math.ceil(height/2);
      TABLE.rows(iRowHtml).height = height - parseInt(newRow.height)
    }

    for (i=0; i < this.RealPosition[1].length; i++)
    {
      var point;
      var iNewRowHtml;
      var iNewCellHtml;
      if(i==iCellReel) 
      {
        var newCell = TABLE.rows(iRowHtml+1).insertCell();
        newCell.colSpan = TD.colSpan;
        newCell.innerHTML = "&nbsp;"
        point = this.RealPosition[iRowHtml][i].indexOf('.');
        iNewRowHtml = parseInt(this.RealPosition[iRowHtml][i].substring(0, point));
        iNewCellHtml = parseInt(this.RealPosition[iRowHtml][i].substring(point+1));  
        if(TD.align != "") newCell.align = TD.align;
        if(TD.vAlign != "") newCell.vAlign = TD.vAlign;
        if(TD.style.border != "") newCell.style.border = TD.style.border;
        if(TD.style.background != "") newCell.style.background = TD.style.background;
        if(TD.className != "") newCell.className = TD.className;
        if(TD.id != "") newCell.id = TD.id;
        if(typeof TD.perso != 'undefined' && TD.perso != "") newCell.perso = TD.perso;
        if(TD.borderColor != "") newCell.borderColor = TD.borderColor;
        if(TD.bgColor != "") newCell.bgColor = TD.bgColor;        
      }
      else
      {

        point = this.RealPosition[iRowHtml][i].indexOf('.');
        iNewRowHtml = parseInt(this.RealPosition[iRowHtml][i].substring(0, point));
        iNewCellHtml = parseInt(this.RealPosition[iRowHtml][i].substring(point+1));  
        TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan++;        
      }
      i += TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan - 1;
    }
  }  
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : MergeCellH()
  ----------
    DESCRIPTION :
      Permet de coller deux cellule adjacentes horizontalement.
      La cellule à droite de celle sélectionnée est collée à celle sélectionnée

    PARAMETRES : 
      aucun
    
    VALEURS RETURNEES :
      aucune    
*/
function MergeCellH()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(TD,"TR")
    var TABLE = GetElement(TR,"TABLE")
    // construit la variable Array dynamiquement pour gérer les bons indices
    this.RedimArray(TABLE, this.RealPosition); 
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }  
  var iCell = TD.cellIndex;
  var iRow = TR.rowIndex;
  var iCellReel;
  var iRowReel;
  for (i=0; i<TABLE.rows(0).cells.length; i++)
  {
    if('' + iRow + '.' + iCell == this.RealPosition[iRow][i])
    {
      iCellReel = parseInt(i);
      iRowReel = parseInt(iRow);
      i = TABLE.rows(0).cells.length;
    } 
  } 
  if (iCellReel+TD.colSpan >= this.RealPosition[1].length) 
  {
    this.AllColSpan(TABLE);
    return;  
  }
  var point = this.RealPosition[iRowReel][iCellReel+TD.colSpan].indexOf('.');
  var iNewRowHtml = parseInt(this.RealPosition[iRowReel][iCellReel+TD.colSpan].substring(0,point));  
  var iNewCellHtml = parseInt(this.RealPosition[iRowReel][iCellReel+TD.colSpan].substring(point+1));  
  var newContent = '';
  var TD2 = TABLE.rows(iNewRowHtml).cells[iNewCellHtml];
  if(TD.rowSpan != TD2.rowSpan)  
  {
    alert('You can\'t merge two cells with different rowspan.')
    return;
  }
  else
  {
    if (TD2.innerHTML != '&nbsp;') TD.innerHTML += '<br>' + TD2.innerHTML;
    TD.colSpan += TD2.colSpan;
    TR.deleteCell(iCell+1);
    this.AllColSpan(TABLE)
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*  FONCTION : MergeCellV()
  ----------
    DESCRIPTION :
      Permet de coller deux cellule adjacentes verticalement.
      La cellule en-dessous de celle sélectionnée est collée à celle sélectionnée

    PARAMETRES : 
      aucun
    
    VALEURS RETURNEES :
      aucune    
*/
function MergeCellV()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(TD,"TR")
    var TABLE = GetElement(TR,"TABLE")
    // construit la variable Array dynamiquement pour géréer les bons indices
    this.RedimArray(TABLE, this.RealPosition); 
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }  
  var iCell = TD.cellIndex;
  var iRow = TR.rowIndex;
  var iCellReel;
  var iRowReel;
  for (i=0; i<TABLE.rows(0).cells.length; i++)
  {
    if('' + iRow + '.' + iCell == this.RealPosition[iRow][i])
    {
      iCellReel = parseInt(i);
      iRowReel = parseInt(iRow);
      i = TABLE.rows(0).cells.length;
    } 
  } 
  var iNewRowHtml = iRow + TD.rowSpan
  if (iNewRowHtml >= TABLE.rows.length) return;

  var point = this.RealPosition[iNewRowHtml][iCellReel].indexOf('.');
  var iNewCellHtml = parseInt(this.RealPosition[iNewRowHtml][iCellReel].substring(point+1));  
  
  var newContent = '';
  var TD2 = TABLE.rows(iNewRowHtml).cells[iNewCellHtml];
  if(TD.colSpan != TD2.colSpan)  
  {
    alert('You can\'t merge two cells with different colspan.')
    return;
  }
  else
  {
    if (TD2.innerHTML != '') TD.innerHTML += '<br>' + TD2.innerHTML;
    TD.rowSpan += TD2.rowSpan;
    TABLE.rows(iNewRowHtml).deleteCell(iNewCellHtml);
    this.AllRowSpan(TABLE)
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : RedimArray(TableElement)
  ----------
    DESCRIPTION :
      Construit une matrice Javascript stockée dans WysiwygEditor.RealPosition qui contient pour chaque case de
      la matrice, les coordonnées de la cellule HTML à laquelle elle appartient.      
      
      Exemple:
        TABLEAU HTML:            TABLEAU JS:
        
            1       2                 1   2     3
         -------------------         -------------------
      1  |  A  |     |  D  |      1  | 1.1 | 1.2 | 1.3 |
         ------   C  -------         -------------------
      2  |  B  |     |  E  |      2  | 2.1 | 1.2 | 2.2 |
         -------------------         -------------------
      3  |     G     |  F  |      3  | 3.1 | 3.1 | 3.2 |
         -------------------         -------------------

    PARAMETRES : 
      TableElement = Element HTML tableau pour lequel on désire créer la matrice
    
    VALEURS RETURNEES :
      aucune    
*/
function RedimArray(TableElement)
{
  var tHeigth = TableElement.rows.length;
  var colGroup = TableElement.children.tags("COLGROUP")[0];
  var cList = colGroup.children.tags("COL");
  var tWidth = cList.length;
  var arr = new Array(tHeigth)
  for (i=0; i < tHeigth; i++) arr[i] = new Array(tWidth);
  var TR = TableElement.rows(0);
  for (i=TR.cells.length-1; i >= 0 ;  i--)
  {
    TR.cells(i).removeNode(true);
  }
  for (i=0; i < tWidth;  i++)
  {
   arr[0][i] = "0."+i;
   var newCell = document.createElement("TD");
   newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
   newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="0" height="1">';
   TR.insertAdjacentElement("AfterBegin",newCell)// += "<td></td>"
  }
  for (i=1; i < tHeigth; i++)
  {
    for (j=0; j < TableElement.rows(i).cells.length; j++)
    {
      var k=0; 
      while(k < tWidth && typeof arr[i][k] != "undefined" )
      {
        k++;
      }// k est l'indice du tableau JS ou on va écrire la position de la cellule du tableau HTML
      var TD = eval(TableElement.rows(i).cells(j));
      var colSpan = TD.colSpan
      var rowSpan = TD.rowSpan 
      for(i2=i; i2 < i+rowSpan && i2 < tHeigth ; i2++)
      {
        for (j2=k; j2< k+colSpan && j2 < tWidth ; j2++)
        {
          arr[i2][j2] = '' + i + '.' + j;
        }    
      }
    }
  }
  this.RealPosition = arr;
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : AllColSpan(TableElement)
  ----------
    DESCRIPTION :
      Cette fonction permet de déterminer, après un Merge Horizontal ou une suppression de ligne, si
      deux ou plusieurs colonnes peuvent être remplacées par une seules
      
    PARAMETRES :
      TableElement = Element HTML tableau pour lequel on désire effectuer l'opération
    
    VALEURS RETURNEES :
      aucune    
*/
function AllColSpan(TableElement)
{
  this.RedimArray(TableElement);
  for(i=this.RealPosition[0].length-1; i > 0 ; i--)
  {
    var DelColumn = true;
    for(j=1; j < this.RealPosition.length && DelColumn == true; j++)
    {
      var point = this.RealPosition[j][i].indexOf('.');
      var iRowHtml = parseInt(this.RealPosition[j][i].substring(0,point));
      var iCellHtml = parseInt(this.RealPosition[j][i].substring(point+1));
      var TD = TableElement.rows(iRowHtml).cells(iCellHtml)
      if(TD.colSpan > 1)
      {
        if(this.RealPosition[j][i] != this.RealPosition[j][i-1])
        {
          DelColumn = false;
        }
      }
      else DelColumn = false;
    }
    if(DelColumn)
    {
      var cList = TableElement.all.tags("COL");
      // Supprime un élément <COL>
      if(cList[i-1].width != "" && cList[i].width != "")
      {
        cList[i-1].width = parseInt(cList[i-1].width) + parseInt(cList[i].width);
      }
      cList[i].removeNode(true);
      TableElement.rows(0).deleteCell();
      for(k=1; k < this.RealPosition.length; k++)
      {
        var point = this.RealPosition[k][i].indexOf('.');
        var iRowHtml = parseInt(this.RealPosition[k][i].substring(0,point));
        var iCellHtml = parseInt(this.RealPosition[k][i].substring(point+1));
        var TD = TableElement.rows(iRowHtml).cells(iCellHtml);
        TD.colSpan--;
        k += (TD.rowSpan -1);
      }
    }
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : AllRowSpan(TableElement)
  ----------
    DESCRIPTION :
      Cette fonction permet de déterminer, après un Merge Vertical, si deux ou plusieurs lignes peuvent
      être remplacées par une seule
      
    PARAMETRES :
      TableElement = Element HTML tableau pour lequel on désire effectuer l'opération
    
    VALEURS RETURNEES :
      aucune    
*/
function AllRowSpan(TableElement)
{
  this.RedimArray(TableElement);
  for(i=this.RealPosition.length-1; i > 1 ; i--)
  {
    var DelRow = true;
    for(j=0; j < this.RealPosition[i].length && DelRow == true; j++)
    {
      var point = this.RealPosition[i][j].indexOf('.');
      var iRowHtml = parseInt(this.RealPosition[i][j].substring(0,point));
      var iCellHtml = parseInt(this.RealPosition[i][j].substring(point+1));
      var TD = TableElement.rows(iRowHtml).cells(iCellHtml)
      if(TD.rowSpan > 1)
      {
        if(this.RealPosition[i][j] != this.RealPosition[i-1][j])
        {
          DelRow = false;
        }
      }
      else DelRow = false;
    }
    if(DelRow)
    {
      if(TableElement.rows(i).height != "" && TableElement.rows(i-1).height != "")
      {
        TableElement.rows(i-1).height = parseInt(TableElement.rows(i).height) + parseInt(TableElement.rows(i-1).height);
      }
      TableElement.deleteRow(i)
      for(k=0; k < this.RealPosition[i-1].length; k++)
      {
        var point = this.RealPosition[i-1][k].indexOf('.');
        var iRowHtml = parseInt(this.RealPosition[i-1][k].substring(0,point));
        var iCellHtml = parseInt(this.RealPosition[i-1][k].substring(point+1));
        var TD = TableElement.rows(iRowHtml).cells(iCellHtml);
        TD.rowSpan--;
        k += (TD.colSpan -1);
      }
    }
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : CellAlign(v,h)
  ----------
    DESCRIPTION :
      Met un alignement vertical et horizontal à la cellule sélectionnée
      
    PARAMETRES :
      v = alignement vertical
          valeurs parmis :
              "top"
              "middle"
              "bottom"
      h = alignement horizontal
          valeurs parmis :
              "left"
              "center"
              "right"
                  
    VALEURS RETURNEES :
      aucune    
*/
function CellAlign(v,h)
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    TD.align = h;
    TD.vAlign = v;
  }
  catch(e)
  {
    alert('No cell selected !')
    return;
  }  

}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : InsertRowUp()
  ----------
    DESCRIPTION :
      Insert une ligne au-dessus de celle sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function InsertRowUp()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  var iRow = TR.rowIndex
  var Top = true
  i = 0;
  while(Top && i < this.RealPosition[iRow].length)
  {
    Top = (iRow == 1 || this.RealPosition[iRow][i] != this.RealPosition[iRow-1][i]);
    i++;
  }
  var height = parseInt(TABLE.rows(iRow).height);
  var newRow = TABLE.insertRow(iRow);
  if(!isNaN(height) && height > 1)newRow.height = height;

  if(Top)
  {
    for (i=0; i < this.RealPosition[0].length; i++)
    {
      var newCell = newRow.insertCell();
      newCell.innerHTML = "&nbsp;"
    }
    ShowNoBorder(TABLE)
    return;
  }
  for (i=0; i < this.RealPosition[0].length; i++)
  {
    var point = this.RealPosition[iRow-1][i].indexOf('.');
    var iNewRowHtml = parseInt(this.RealPosition[iRow-1][i].substring(0,point));
    var iNewCellHtml = parseInt(this.RealPosition[iRow-1][i].substring(point+1));
    var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)
    if(rowSpan != 1) TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan++;
    else
    {
      for(j=0; j < colSpan; j++)
      {
        var newCell = newRow.insertCell();
        newCell.innerHTML = "&nbsp;"
      }
    }
    i += colSpan - 1;
  }
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : InsertRowDown()
  ----------
    DESCRIPTION :
      Insert une ligne en-dessous de celle sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function InsertRowDown()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  var rowSpan = parseInt(TD.rowSpan)
  var iRow = TR.rowIndex + rowSpan - 1

  var Bottom = true
  i = 0;
  while(Bottom && i < this.RealPosition[iRow].length)
  {
    Bottom = (iRow == this.RealPosition.length-1 || this.RealPosition[iRow][i] != this.RealPosition[iRow+1][i]);
    i++;
  }
  var height = parseInt(TABLE.rows(iRow).height);
  var newRow = TABLE.insertRow(iRow+1);
  if(!isNaN(height)&& height > 1)newRow.height = height;
  
  if(Bottom)
  {
    for (i=0; i < this.RealPosition[0].length; i++)
    {
      var newCell = newRow.insertCell();
      newCell.innerHTML = "&nbsp;"
    }
    ShowNoBorder(TABLE)
    return;
  }
  for (i=0; i < this.RealPosition[0].length; i++)
  {
    var point = this.RealPosition[iRow][i].indexOf('.');
    var iNewRowHtml = parseInt(this.RealPosition[iRow][i].substring(0,point));
    var iNewCellHtml = parseInt(this.RealPosition[iRow][i].substring(point+1));
    var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)

    if(rowSpan != 1) TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan++;
    else
    {
      for(j=0; j < colSpan; j++)
      {
        var newCell = newRow.insertCell();
        newCell.innerHTML = "&nbsp;"
      }
    }
    i += colSpan - 1;
  }
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : InsertColLeft()
  ----------
    DESCRIPTION :
      Insert une colonne à gauche de celle sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function InsertColLeft()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  var iRowHtml = TR.rowIndex
  var iCellHtml = TD.cellIndex
  var iRowReel = TR.rowIndex
  var iCellReel = TD.cellIndex
  var iCellReel=0;
  while(iCellReel < this.RealPosition[iRowReel].length && this.RealPosition[iRowReel][iCellReel] != ""+iRowHtml+"."+iCellHtml )
  {
    iCellReel++;
  }
  var Left = true
  i = 1;
  while(Left && i < this.RealPosition.length)
  {
    Left = (iCellReel == 0 || this.RealPosition[i][iCellReel-1] != this.RealPosition[i][iCellReel]);
    i++;
  }
  var cList = TABLE.all.tags("COL");
  var col = eval(cList[iCellReel]);
  var newCol = document.createElement("<col>");
  var width = parseInt(col.width);
  if(!isNaN(width) && width > 1) newCol.width = width
  col.insertAdjacentElement("BeforeBegin",newCol);
  if(Left)
  {
    if (iCellReel == 0)
    {
     var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
     newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
      for (i=1; i < this.RealPosition.length; i++)
      {
        var newCell = TABLE.rows(i).insertCell(0);
        newCell.innerHTML = "&nbsp;"
      }
    }
    else
    {
     var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
     newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
     for (i=1; i < this.RealPosition.length; i++)
      {
        var point = this.RealPosition[i][iCellReel].indexOf('.');
        var iNewRowHtml = parseInt(this.RealPosition[i][iCellReel].substring(0,point));
        var iNewCellHtml = parseInt(this.RealPosition[i][iCellReel].substring(point+1));

        var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
        var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)
        var newCell = TABLE.rows(iNewRowHtml).insertCell(iNewCellHtml);
        newCell.innerHTML = "&nbsp;"
        if(rowSpan != 1) 
        {
          for(j=1; j < rowSpan; j++)
          {
            var k=iCellReel;
            var GoOn = true;
            var iNewRowHtml2 = iNewRowHtml
            while(iNewRowHtml2==iNewRowHtml && k > 0 && GoOn)
            {
              k--;
              var point = this.RealPosition[i+j][k].indexOf('.');
              iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
              var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
              if (iNewRowHtml2 == i+j) GoOn = false;
            }

            var point = this.RealPosition[i+j][k].indexOf('.');
            var iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
            var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
            var newCell = TABLE.rows(i+j).insertCell(iNewCellHtml2);

            newCell.innerHTML = "&nbsp;"
          }
        }
        i += rowSpan - 1;
      }
    }
    ShowNoBorder(TABLE)
    return;
  }
     var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
     newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
  for (i=1; i < this.RealPosition.length; i++)
  {
    var point = this.RealPosition[i][iCellReel].indexOf('.');
    var iNewRowHtml = parseInt(this.RealPosition[i][iCellReel].substring(0,point));
    var iNewCellHtml = parseInt(this.RealPosition[i][iCellReel].substring(point+1));
    var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)

    if(colSpan != 1) TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan++;
    else
    {
        var point = this.RealPosition[i][iCellReel].indexOf('.');
        var iNewRowHtml = parseInt(this.RealPosition[i][iCellReel].substring(0,point));
        var iNewCellHtml = parseInt(this.RealPosition[i][iCellReel].substring(point+1));

        var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
        var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)
        var newCell = TABLE.rows(iNewRowHtml).insertCell(iNewCellHtml);
        newCell.innerHTML = "&nbsp;"
        //alert(i);
        if(rowSpan != 1) 
        {
          for(j=1; j < rowSpan; j++)
          {
            var k=iCellReel;
            var GoOn = true;
            var iNewRowHtml2 = iNewRowHtml
            while(iNewRowHtml2==iNewRowHtml && k > 0 && GoOn)
            {
              k--;
              var point = this.RealPosition[i+j][k].indexOf('.');
              iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
              var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
              if (iNewRowHtml2 == i+j) GoOn = false;
            }

            var point = this.RealPosition[i+j][k].indexOf('.');
            var iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
            var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
            var newCell = TABLE.rows(i+j).insertCell(iNewCellHtml2);

            newCell.innerHTML = "&nbsp;"
          }
        }
    }
    i += rowSpan - 1;
  }
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : InsertColRight()
  ----------
    DESCRIPTION :
      Insert une colonne à droite de celle sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function InsertColRight()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  var iRowHtml = TR.rowIndex
  var iCellHtml = TD.cellIndex
  var iRowReel = TR.rowIndex
  var iCellReel = TD.cellIndex
 
  var iCellReel=0;
  while(iCellReel < this.RealPosition[iRowReel].length && this.RealPosition[iRowReel][iCellReel] != ""+iRowHtml+"."+iCellHtml )
  {
    iCellReel++;
  }
  iCellReelDebut = iCellReel
  iCellReel += (parseInt(TD.colSpan) - 1);


  var Right = true
  i = 1;
  while(Right && i < this.RealPosition.length)
  {
    Right = (iCellReel == this.RealPosition[i].length - 1 || this.RealPosition[i][iCellReel+1] != this.RealPosition[i][iCellReel]);
    i++;
  }
  var cList = TABLE.all.tags("COL");
  var col = eval(cList[iCellReel]);
  var newCol = document.createElement("<col>");
  var width = parseInt(col.width);
  if(!isNaN(width) && width > 1) newCol.width = width
  newCol.width = col.width;
  col.insertAdjacentElement("AfterEnd",newCol);

  if(Right)
  {
 // alert(i);
    if (iCellReel == this.RealPosition[0].length - 1)
    {
     var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
     newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
      for (i=1; i < this.RealPosition.length; i++)
      {
        var newCell = TABLE.rows(i).insertCell()
        newCell.innerHTML = "&nbsp;"
      }
    }
    else
    {
     var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
     newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
      for (i=1; i < this.RealPosition.length; i++)
      {
        var point = this.RealPosition[i][iCellReel+1].indexOf('.');
        var iNewRowHtml = parseInt(this.RealPosition[i][iCellReel+1].substring(0,point));
        var iNewCellHtml = parseInt(this.RealPosition[i][iCellReel+1].substring(point+1));

        var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
        var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)
        var newCell = TABLE.rows(iNewRowHtml).insertCell(iNewCellHtml);
        newCell.innerHTML = "&nbsp;"
        //alert(i);
        if(rowSpan != 1) 
        {
          for(j=1; j < rowSpan; j++)
          {
            var k=iCellReel;
            var GoOn = true;
            var iNewRowHtml2 = iNewRowHtml
            while(iNewRowHtml2==iNewRowHtml && k > 0 && GoOn)
            {
              k--;
              var point = this.RealPosition[i+j][k].indexOf('.');
              iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
              var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
              if (iNewRowHtml2 == i+j) GoOn = false;
            }

            var point = this.RealPosition[i+j][k].indexOf('.');
            var iNewRowHtml2 = parseInt(this.RealPosition[i+j][k].substring(0,point));
            var iNewCellHtml2 = parseInt(this.RealPosition[i+j][k].substring(point+1));//juste
            var newCell = TABLE.rows(i+j).insertCell(iNewCellHtml2);

            newCell.innerHTML = "&nbsp;"
          }
        }
        i += rowSpan - 1;
      }
    }
    ShowNoBorder(TABLE)
    return;
  }
  var newCell = TABLE.rows(0).insertCell();
     newCell.style.cssText = "margin: 0px; padding: 0px; height: 1px"
  
  newCell.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
  for (i=1; i < this.RealPosition.length; i++)
  {
    var point = this.RealPosition[i][iCellReel+1].indexOf('.');
    var iNewRowHtml = parseInt(this.RealPosition[i][iCellReel+1].substring(0,point));
    var iNewCellHtml = parseInt(this.RealPosition[i][iCellReel+1].substring(point+1));
    var colSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iNewRowHtml).cells[iNewCellHtml].rowSpan)

    if(colSpan != 1) TABLE.rows(iNewRowHtml).cells[iNewCellHtml].colSpan++;
    else
    {
      var newCell = TABLE.rows(iNewRowHtml).insertCell(iNewCellHtml);
      newCell.innerHTML = "&nbsp;"
        if(rowSpan != 1) 
        {
          for(j=1; j < rowSpan; j++)
          {
            var point = this.RealPosition[i+j][iCellReelDebut+colSpan].indexOf('.');
            var iNewRowHtml2 = parseInt(this.RealPosition[i+j][iCellReelDebut+colSpan-1].substring(0,point));
            var iNewCellHtml2 = parseInt(this.RealPosition[i+j][iCellReelDebut+colSpan-1].substring(point+1));
            var newCell = TABLE.rows(iNewRowHtml+j).insertCell(iNewCellHtml2+1);
            newCell.innerHTML = "&nbsp;"
          }
       }
    }
    i += rowSpan - 1;
  }
  ShowNoBorder(TABLE)
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : DelRow()
  ----------
    DESCRIPTION :
      supprime la line sélectionneé sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function DelRow()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  if (TD.rowSpan > 1)
  {
    alert("Please choose a cell which extends over only one row !");
    return;
  }
  if(this.RealPosition.length == 2)
  {
    TABLE.outerHTML="";
    return;
  }
  var iRow = TR.rowIndex
  var Top = true
  i = 0;
  while(Top && i < this.RealPosition[iRow].length)
  {
    Top = (iRow == 1 || this.RealPosition[iRow][i] != this.RealPosition[iRow-1][i]);
    i++;
  }
  for(i=0; i < this.RealPosition[iRow].length; i++)
  {
    var point = this.RealPosition[iRow][i].indexOf('.');
    var iRowHtml = parseInt(this.RealPosition[iRow][i].substring(0,point));
    var iCellHtml = parseInt(this.RealPosition[iRow][i].substring(point+1));
    
    var colSpan = parseInt(TABLE.rows(iRowHtml).cells[iCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iRowHtml).cells[iCellHtml].rowSpan)
    if(rowSpan > 1)
    {
      TABLE.rows(iRowHtml).cells[iCellHtml].rowSpan--;
      if(Top)
      {
        if(i+colSpan == this.RealPosition[iRow].length)
        {
           var point = this.RealPosition[iRow+1][i+colSpan-1].indexOf('.');
           var iNewCellHtml = parseInt(this.RealPosition[iRow][i+colSpan-1].substring(point+1));
        }
        else
        {
           var point = this.RealPosition[iRow+1][i+colSpan].indexOf('.');
           var iNewCellHtml = parseInt(this.RealPosition[iRow][i+colSpan].substring(point+1));
        }
        var cell1 = TABLE.rows(iRowHtml).cells[iCellHtml]
        var newCell = TABLE.rows(iRowHtml+1).insertCell(iNewCellHtml-1)
        newCell.innerHTML = cell1.innerHTML;
        if(cell1.align != "") newCell.align = cell1.align;
        if(cell1.vAlign != "") newCell.vAlign = cell1.vAlign;
        if(cell1.colSpan != "") newCell.colSpan = cell1.colSpan;
        if(cell1.rowSpan != "") newCell.rowSpan = cell1.rowSpan;
        if(cell1.style.border != "") newCell.style.border = cell1.style.border;
        if(cell1.style.background != "") newCell.style.background = cell1.style.background;
        if(cell1.className != "") newCell.className = cell1.className;
        if(cell1.id != "") newCell.id = cell1.id;
        if(cell1.perso != "") newCell.perso = cell1.perso;
        if(cell1.borderColor != "") newCell.borderColor = cell1.borderColor
        if(cell1.bgColor != "") newCell.bgColor = cell1.bgColor
      }
    }
    i += colSpan - 1;
  }
  var iRowHtml = TR.rowIndex;
  var iCellHtml = TD.cellIndex;
  var iRowReel = TR.rowIndex;
  var iCellReel=0;
  while(iCellReel < this.RealPosition[iRowReel].length && this.RealPosition[iRowReel][iCellReel] != ""+iRowHtml+"."+iCellHtml )
  {
    iCellReel++;
  }
  TABLE.deleteRow(iRow);
  AllColSpan(TABLE);
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : DelCol()
  ----------
    DESCRIPTION :
      supprime la colonne sélectionnée
      
    PARAMETRES :
      auncun
                  
    VALEURS RETURNEES :
      aucune    
*/
function DelCol()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No row selected !')
    return;
  }  
  if (TD.colSpan > 1)
  {
    alert("Please choose a cell which extends over only one column !");
    return;
  }
  if(this.RealPosition[0].length == 1)
  {
    TABLE.outerHTML="";
    return;
  }
  var iRowHtml = TR.rowIndex;
  var iCellHtml = TD.cellIndex;
  var iRowReel = TR.rowIndex;
  var iCellReel=0;
  while(iCellReel < this.RealPosition[iRowReel].length && this.RealPosition[iRowReel][iCellReel] != ""+iRowHtml+"."+iCellHtml )
  {
    iCellReel++;
  }
  var cList = TABLE.all.tags("COL");
  // Supprime un élément <COL>
  var col = eval(cList[iCellReel]);
  cList[iCellReel].removeNode(true);
//  ShowJS();
  for(i=this.RealPosition.length-1; i >=0 ; i--)
  {
    var point = this.RealPosition[i][iCellReel].indexOf('.');
    var iRowHtml = parseInt(this.RealPosition[i][iCellReel].substring(0,point));
    var iCellHtml = parseInt(this.RealPosition[i][iCellReel].substring(point+1));
    var colSpan = parseInt(TABLE.rows(iRowHtml).cells[iCellHtml].colSpan)
    var rowSpan = parseInt(TABLE.rows(iRowHtml).cells[iCellHtml].rowSpan)
    if(colSpan > 1)
    {
      TABLE.rows(iRowHtml).cells[iCellHtml].colSpan--;
    }
    else
    {
      if(TABLE.rows(iRowHtml).cells.length==1)
      {
        for(j=0; j < this.RealPosition[i].length; j++)
        {
          var point = this.RealPosition[i][j].indexOf('.');
          var iRowHtml2 = parseInt(this.RealPosition[i][j].substring(0,point));
          var iCellHtml2 = parseInt(this.RealPosition[i][j].substring(point+1));
          if(TABLE.rows(iRowHtml2).cells[iCellHtml2].rowSpan>1)TABLE.rows(iRowHtml2).cells[iCellHtml2].rowSpan--;
        }
        TABLE.deleteRow(iRowHtml)
      }
      else TABLE.rows(iRowHtml).deleteCell(iCellHtml);
    }
    i -= (rowSpan - 1);
  }
  AllRowSpan(TABLE);
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : ChangeColor(ClassId, Color)
  ----------
    DESCRIPTION :
      Insert une colonne à droite de celle sélectionnée
      
    PARAMETRES :
      ClassId = -1 . La couleur est selectionnée par le color Picker
                 0 . La couleur de fond ou de bordure est effacée
                >0 . Le numéro de la couleur dans le CSS du thème de front du site
      Color = couleur du CSS de thème de front ou de la couleur choisi par le color picker
    VALEURS RETURNEES :
      aucune    
*/
function ChangeColor(ClassId, Color)
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  var oSelType = this.SelType;
  try
  {
    var rSelected = 0;
    while(!document.parentWindow.document.all.colorRadio[rSelected].checked) rSelected++;
    switch(rSelected)
    {
     case 0 :
       // Changement de couleur de fond sur la Table
       var Element = GetElement(oSel.parentElement(),"TABLE");
       //on a efface le fond
       Element.removeAttribute("BGCOLOR", false);
       Element.removeAttribute("CLASSNAME", false);
       //on a une classe de CSS
       if(ClassId > 0)
       {
         Element.className = "Color"+ClassId;
       }
       //on met une couleur en dur
       else if (ClassId == -1)
       {
         Element.bgColor = Color;
       }
       break;
     case 1 :
       // Changement de couleur de fond sur la Cellule
       var Element = GetElement(oSel.parentElement(),"TD");
       //on a efface le fond
       Element.removeAttribute("BGCOLOR", false);
       Element.removeAttribute("CLASSNAME", false);
       //on a une classe de CSS
       if(ClassId > 0)
       {
         Element.className = "Color"+ClassId;
       }
       //on met une couleur en dur
       else if (ClassId == -1)
       {
         Element.bgColor = Color;
       }
       break;
     case 2 :
              //alert(ClassId)

       // Changement de couleur sur la texte
         if (ClassId != "0")
         {
           oSel.execCommand("ForeColor",false,Color);
         }
         else
         {
           oSel.execCommand("ForeColor",false,'');
         }
         //alert(Color)
         //return;
       try
       {
         // on récupère la balise <FONT> (si elle existe);qui englobe la sélection
         if(oSelType == "Text")
         {
           oSel.select();
         }
         else
         {
           oSel.expand("word")
           oSel.select()
         }
         // Suppression de la couleur actuelle
         oSel.execCommand("ForeColor",false,Color);
           var FONT = GetElement(oSel.parentElement(),"FONT");
           FONT.removeAttribute("COLOR", false);
           FONT.removeAttribute("PERSO", false);
         oSel.execCommand("ForeColor",false,"");
         if (ClassId != "0")
         {
           // L'utilisateur a choisi de supprimer la couleur pour cet élément
           oSel.execCommand("ForeColor",false,Color);
           var FONT = GetElement(oSel.parentElement(),"FONT");
           if (ClassId > 0) FONT.perso = "Color"+ClassId;
         }
         if(oSelType == "None")
         {
           oSel.collapse();
         }
       }
       catch(e)
       {
         oSel.execCommand("ForeColor",false,"");
         if(this.PasteTable)
         {
           alert('Please select text within a single cell or with the same style(bold,italic,...) !\n');
         }
         return false;
       }
       return true;

     case 3 :
       // Changement de couleur de bordure sur la Table
       var Element = GetElement(oSel.parentElement(),"TABLE");
       //on a efface la bordure
       Element.removeAttribute("BORDERCOLOR", false);
       Element.removeAttribute("PERSO", false);
       if(Element.border == 0)
       {
         Element.runtimeStyle.border.width = "";
         Element.runtimeStyle.borderColor = "";
         Element.runtimeStyle.borderStyle = "";
         Element.runtimeStyle.borderCollapse = "separate";
         for(j=0;j<Element.getElementsByTagName("TD").length;j++)
         {
           Element.getElementsByTagName("TD")[j].runtimeStyle.borderWidth = "";
           Element.getElementsByTagName("TD")[j].runtimeStyle.borderColor = "";
           Element.getElementsByTagName("TD")[j].runtimeStyle.borderStyle = "";
         }
         Element.rows(0).runtimeStyle.backgroundColor = ""// = Color;
       }
       Element.rows(0).bgColor = Color;
       Element.border = 1;

        //on a une classe de CSS
       if(ClassId > 0)
       {
         Element.perso = "Color"+ClassId;
         Element.borderColor = Color;
       }
       //on met une couleur en dur
       else if (ClassId == -1)
       {
         Element.borderColor = Color;
       }
       else
       {
         Element.border = 0
         for(j=0;j<Element.getElementsByTagName("TD").length;j++)
         {
           Element.getElementsByTagName("TD")[j].runtimeStyle.border = "#BCBCBC 1 dotted";
         }
         Element.runtimeStyle.border = "#BCBCBC dotted 1px";
         Element.runtimeStyle.borderCollapse = "collapse";
         Element.rows(0).runtimeStyle.backgroundColor = "#FFFFFF"// = Color;
       }
     break;
     case 4 :
       // Changement de couleur de bordure sur la cellule
       var Element = GetElement(oSel.parentElement(),"TD");
       var TABLE = GetElement(oSel.parentElement(),"TABLE");
       if(typeof TABLE.borderColor == 'undefined' || TABLE.borderColor == '')
       {
         alert("The table has no border. You can't specify a border for this cell.");
         return;
       }
       //on a efface la bordure
       Element.removeAttribute("BORDERCOLOR", false);
       Element.removeAttribute("PERSO", false);
       //on a une classe de CSS
       if(ClassId > 0)
       {
         Element.perso = "Color"+ClassId;
         Element.borderColor = Color;
       }
       //on met une couleur en dur
       else if (ClassId == -1)
       {
         Element.borderColor = Color;
       }
       break;
    }
  }
  catch(e)
  {
    alert('No table selected ! ')
    return;
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : Format(Symbol,type)
  ----------
    DESCRIPTION :
      Colle un caractère spécial
      
    PARAMETRES :
      Symbol = entité HTML du symbol à insérer
      Type = permet de savoir si on insert en normal, en exposanty ou en index
           1 : normal
           2 : exposant
           3 : index
    VALEURS RETURNEES :
      aucune    
*/
function Format(Symbol,Type)
{
  var obj = eval("document.parentWindow."+this.ObjName)
  if(obj.PasteTable)
  {
    try
    {
     //alert(Sel.htmlText)
      var TABLE = document.parentWindow.GetElement(this.Sel.parentElement(),"TABLE")
      var test = TABLE.name
    }
    catch(e)
    {
      alert("You can't edit text out of a table. Please set the cursor into a table")
      return false;
    }
  }

  switch(Type)
  {
   case 1 :
     this.Sel.select();
     this.Sel.text = (Symbol)

     // On est en indice ?
     // passer en normal
     var subExists = true;
     try{
       var SUB = GetElement(this.Sel.parentElement(),"SUB");
       var tmp = SUB.innerText; }
     catch(e){
       subExists = false; }   
     if(subExists)
     {
       this.Sel.moveStart("character", -1)
       this.Sel.select()        
       this.DoCmd("subscript")
     }

     // On est en exposant
     // passer en normal
     var supExists = true;
     try{
       var SUP = GetElement(this.Sel.parentElement(),"SUP");
       var tmp = SUP.innerText; }
     catch(e){
       supExists = false; }
     if(supExists)
     {
       this.Sel.moveStart("character", -1)
       this.Sel.select()        
       this.DoCmd("superscript")
     }
     this.Sel.collapse(false)
     this.Sel.select()

     break;
   case 2 :
     var subExists = true;
     try{
       var SUB = GetElement(this.Sel.parentElement(),"SUB");
       var tmp = SUB.innerText; }
     catch(e){
       subExists = false; }   
     try
     {
        var SUP = GetElement(this.Sel.parentElement(),"SUP")
        var tmp = SUP.innerText
     }
     catch(e)
     {
       this.Sel.select()
       this.Sel.text = (Symbol)
       this.Sel.moveStart("character", -1)
       this.Sel.select()
       if(subExists)
       {
         this.Sel.select()
         this.DoCmd("subscript")
       }         
       this.DoCmd("superscript")
       this.Sel.collapse(false)
       this.Sel.select()  
       this.DoCmd("superscript")
       return;
     }
     this.Sel.select();
     this.Sel.text = (Symbol)
     break;
   case 3 :
     var supExists = true;
     try{
       var SUP = GetElement(this.Sel.parentElement(),"SUP");
       var tmp = SUP.innerText; }
     catch(e){
       supExists = false; }
     try
     {
        var SUB = GetElement(this.Sel.parentElement(),"SUB")
        var tmp = SUB.innerText
     }
     catch(e)
     {
       this.Sel.select()
       this.Sel.text = (Symbol)
       this.Sel.moveStart("character", -1)
       this.Sel.select()
       if(supExists)
       {
         this.Sel.select()
         this.DoCmd("superscript")
       }       
       this.DoCmd("subscript")
       this.Sel.collapse(false)
       this.Sel.select()  
       this.DoCmd("subscript")
       return;
     }
     this.Sel.select();
     this.Sel.text = (Symbol)
     break;
   }





/*  try
  {
     var SUP = GetElement(this.Sel.parentElement(),"SUP")
     var tmp = SUP.innerText
  }
  catch(e)
  {
     this.Sel.select()
     this.Sel.text = (Symbol)
     this.Sel.moveStart("character", -1)
     this.Sel.select()
     this.DoCmd("superscript")
     this.Sel.collapse(false)
     this.Sel.select()  
     this.DoCmd("superscript")
     return;
  }*/

}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : CreateTable()
  ----------
    DESCRIPTION :
      Ouvre une fenêtre pour créer une table
      
    PARAMETRES :
      aucuns
      
    VALEURS RETURNEES :
      aucune    
*/
function CreateTable()
{
  this.SaveSelection();
    var nb = this.Editor.document.body.children.tags("TABLE").length;
    var isInTable = true;
    // on regarde si on essaye de coller dans un tableau
    try {
      var TABLE = GetElement(this.Sel.parentElement(), "TABLE")
      var tmp = TABLE.border;
    } catch(e){isInTable = false}
    // Si on est pas dans une table
    // et qu'on n'a pas sélectionné une table
    // et qu'il y a déjà une table dans la page
    // et qu'on colle plus d'un tableau, on interdit le collage
    var shouldPaste = true
    if(!isInTable && nb != 0 && this.Sel.htmlText.toLowerCase().indexOf('<table') < 0) 
    {
      alert("You can't have more than one table in a bloc.");
      return false;    
    }
  this.newWin = window.open("EditTableCreate.asp","CreateTable","statusbar=no,toolbar=no,scrollbars=no,width=400,height=370");
  document.parentWindow.win = this.newWin;
  this.newWin.focus();
  
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : EditTable()
  ----------
    DESCRIPTION :
      Ouvre une fenêtre pour créer une table
      
    PARAMETRES :
      aucuns
      
    VALEURS RETURNEES :
      aucune    
*/
function EditTable()
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }  
  this.newWin = window.open("EditTableProp.asp","Edit","statusbar=no,toolbar=no,scrollbars=no,width=200,height=120");
  document.parentWindow.win = this.newWin;
  this.newWin.focus();
  
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : ChangeWidth(pixel)
  ----------
    DESCRIPTION :
      Change la largeur d'une colonne sélectionnée
      Si la cellule a un colSpan supérieur à 1, la taille de chaque colonne de 
      la cellule vaudra : (pixel / colSpan)
      
    PARAMETRES :
      pixel = largeur de la cellule en pixels
      
    VALEURS RETURNEES :
      aucune    
*/
function ChangeWidth(pixel)
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
    this.RedimArray(TABLE);
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }  
  var nbCol = TD.colSpan;
  var outerWidth = 0;
  var iReel = 0;
  var iRowHtml = TR.rowIndex;
  var iCellHtml = TD.cellIndex;
  var iRowReel = TR.rowIndex;
  var iCellReel=0;
  var bordCell = (TABLE.border == 0)?0:2;
  while(iReel < this.RealPosition[iRowReel].length && this.RealPosition[iRowReel][iReel] != ""+iRowHtml+"."+iCellHtml )
  {
    iReel++;
  }
  if(TD.colSpan > 1)
  {
    pixel = pixel - 2*TABLE.border//(this.RealPosition[0] == TD.colSpan)?pixel - 2*TABLE.bord:pixel;
    
  }
  for(i=0; i < TD.colSpan; i++)
  {
    var cList = TABLE.all.tags("COL");
    // Ajoute un élément <COL>
    var newCOL = eval(cList[iReel+i]);
     
    var newWidth = Math.floor((pixel - outerWidth )/nbCol) //- 2 pour supprimer les bords
    //var newCOL = eval(TABLE.rows(0).cells(parseInt(iReel + i)));
    outerWidth += newWidth;

    //alert(newWidth);
    var innerWidth = newWidth - 2 * parseInt(TABLE.cellPadding) - bordCell
//    alert(innerWidth);
    if(!isNaN(innerWidth) && innerWidth > 1) newCOL.width = innerWidth;
    else newCOL.width = 1
    nbCol--;
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/*
  FONCTION : ChangeHeight(pixel)
  ----------
    DESCRIPTION :
      Change la hauteur d'une ligne sélectionnée
      Si la cellule a un rowSpan supérieur à 1, la taille de chaque ligne de
      la cellule vaudra : (pixel / rowSpan)      
    PARAMETRES :
      pixel = hauteur de la cellule en pixels
      
    VALEURS RETURNEES :
      aucune    
*/
function ChangeHeight(pixel)
{
  this.SaveSelection();
  var oSel = eval(this.Sel);
  try
  {
    var TD = GetElement(oSel.parentElement(),"TD")    
    var TR = GetElement(oSel.parentElement(),"TR")    
    var TABLE = GetElement(oSel.parentElement(),"TABLE")
  }
  catch(e)
  {
    alert('No table selected !')
    return;
  }
  var nbRow = TD.rowSpan;
  var outerHeight = 0;
  var bordCell = (TABLE.border == 0)?0:2;
  for(i=0; i < TD.rowSpan; i++)
  {
    var newHeight = Math.floor((pixel - outerHeight )/nbRow) //- 2 pour supprimer les bords
    var newTR = TABLE.rows(parseInt(TR.rowIndex + i))
    outerHeight += newHeight;
    var innerHeight = newHeight - 2 * parseInt(TABLE.cellPadding) - bordCell
    if(!isNaN(innerHeight) && innerHeight > 1) newTR.height = innerHeight;
    else newTR.height = 1
    nbRow--;
  }
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

// Affiche la matrice pour le débuggage
function ShowJS()
{
  var msg ='';
  for (i=0; i < obj.RealPosition.length; i++)
  {
  
    for (j=0; j < obj.RealPosition[i].length; j++)
    {
      msg += '[' +obj.RealPosition[i][j] + '] ';
    }
    msg += '\n';
  } 
  alert(msg);
}

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

// Permet de savoir si on a cliqué qur le header d'un tableau
function IsInHeader()
{

  var obj = eval("document.parentWindow.obj")

  var oldSel = obj.Sel;
  var oSel = obj.Editor.document.selection.createRange();
  try
  {
    var TR = document.parentWindow.GetElement(oSel.parentElement(),"TR")
    if (TR.rowIndex == 0)
    {
      oldSel.select();
      return false
    }
    else return true;
  }
  catch(e)
  {
    return true;
  }
}

function ShowNoBorder(Element)
{
 if (Element.border == 0)
 {
   Element.border = 0
   for(j=0;j < Element.getElementsByTagName("TD").length;j++)
   {
     Element.getElementsByTagName("TD")[j].runtimeStyle.border = "#BCBCBC 1 dotted";
   }
   Element.runtimeStyle.border = "#BCBCBC dotted 1px";
   Element.runtimeStyle.borderCollapse = "collapse";
   Element.rows(0).runtimeStyle.backgroundColor = "#FFFFFF"//"url(TABLE_EDITOR/imgs/fond_tiret.gif)"// = Color;
 }
 
}

function AlignTable(pos)
{
  this.SaveSelection();
  try
  {
    var TABLE = GetElement(this.Sel.parentElement(),"TABLE")
    TABLE.align = pos;
    
    var TABLE2 = this.Editor.document.body.all.tags("TABLE")[0]
    if(TABLE2 == TABLE)
       this.Editor.document.body.background = "TABLE_EDITOR/imgs/bg-"+pos+".gif";
  }
  catch (e) {}
}

function ChangeFont(value)
{
  this.SaveSelection();
  var oSel = this.Sel;
  var oSelType = this.SelType;
  try
  {
    if(value > 0)
    {
      oSel.execCommand("FontSize",false,value);
    }
    if(value == 0)
    {
      oSel.execCommand("removeFormat",false);
    }
  }
  catch(e){}
  this.Editor.focus();
}

function IsOver500Px()
{
  var Tables = this.Editor.document.all.tags("TABLE")
  for(i=0; i < Tables.length; i++)
  {
    var border = parseInt(Tables[i].border);
    var CellPad = parseInt(Tables[i].cellPadding);
    var width = 2 * Tables[i].border;
    var Cols = Tables[i].all.tags("COL")
    //alert(2 * border + parseInt(Tables[i].clientWidth));
    if(2 * border + parseInt(Tables[i].clientWidth) > 500) return true;
    for(j=0; j < Cols.length; j++)
    {

      width += (2 * border + 2 * CellPad + parseInt(Cols[j].width))
      
      if(width > 500)
      {
       return true;
      }
    }
  }
    //alert(width);
  return false;
}

function DoPaste()
{
  var obj = eval("document.parentWindow.obj")
  obj.SaveSelection();
  obj.Paste();
  return false;
}
function DoPaste2()
{
  var obj = eval("document.parentWindow.obj2")
  obj2.SaveSelection();
  obj2.Paste();
  return false;
}

function Paste()
{

  //Initialisation des variables utilisées lors du paste
  this.SaveSelection();
  var oEditor = this.Editor;
  var oTmp = eval(this.Name + "Tmp");
  oEditor.focus();
  var oSel = oEditor.document.selection.createRange();

  if(oSel.parentElement)
  {
    oTmp.focus();
    oTmp.document.execCommand("SelectAll");
    oTmp.document.execCommand("Paste");
    //On teste si on essaie de coller plus d'un tableau
    //Si c'est le cas, on ne colle rien

    //On ne colle pas les balises FONT, juste leur contenu
    for (var i  = oTmp.document.all.tags("FONT").length - 1; i >= 0; i--)
    {
     oTmp.document.all.tags("FONT")[i].outerHTML = oTmp.document.all.tags("FONT")[i].innerHTML
    }

    //On ne colle pas les balises DIV, juste leur contenu
    for (var i  = oTmp.document.all.tags("DIV").length - 1; i >= 0; i--)
    {
     oTmp.document.all.tags("DIV")[i].outerHTML = oTmp.document.all.tags("DIV")[i].innerHTML
    }

    var strPaste = oTmp.document.body.innerHTML;
    var nb = this.Editor.document.body.children.tags("TABLE").length;
    var nbTmp = oTmp.document.body.children.tags("TABLE").length;
    var isInTable = true;
    // on regarde si on essaye de coller dans un tableau
    try {
      var TABLE = GetElement(oSel.parentElement(), "TABLE")
      var tmp = TABLE.border;
    } catch(e){isInTable = false}
    // Si on est pas dans une table
    // et qu'on n'a pas sélectionné une table
    // et qu'il y a déjà une table dans la page
    // et qu'on colle plus d'un tableau, on interdit le collage
    var shouldPaste = true

    if(!isInTable && this.PasteTable) // && this.Sel.htmlText.toLowerCase().indexOf('<table') < 0 && nb > 0 && nbTmp > 1)
    { // On n'est pas dans une table
    
      if(nbTmp == 0)
      {// On essaye de coller que du texte
        alert("You can't paste text out of a table. Please set the cursor into a table")
        return false;
      }
      if (nb == 0)
      { // Il y en pas ...
          if (nbTmp > 1)
          { // on en colle plusieurs, interdire
            shouldPaste = false
          }
      }
      else
      { // Il y en a déjà 1 ...
        if (this.Sel.htmlText.toLowerCase().indexOf('<table') < 0)
        { // et on ne l'a pas sélectionné, interdire
          shouldPaste = false
        }      
        else
        {
          if (nbTmp > 1)
          { // on en colle plusieurs, interdire
            shouldPaste = false
          }
        }
      }
    }
    //Si on ne doit pas coller, message puit annuler le collage
    if(!shouldPaste)
    {
      alert("You can't have more than one table in a bloc.");
      return false;    
    }
    
    // On enlève le style et les classes CSS de chaques éléments
    // Si il s'agit d'un tableau, on lui affecte la couleur de fond N°1 du thème
    for (var i = 0; i < oTmp.document.body.all.length; i++)
    {
     switch(oTmp.document.body.all[i].tagName.toUpperCase())
     {
      case "TABLE" :
      case "TR" :
      case "TD" :
        oTmp.document.body.all[i].bgColor = oTmp.document.body.all[i].style.backgroundColor;
        break;
      default :
        break;
     }
      oTmp.document.body.all[i].removeAttribute("className","",0);
      //oTmp.document.body.all[i].removeAttribute("style","",0);
    }

//--------------------------------------------------------------------------

// Si on est en edition de type text :
    if(!this.PasteTable)
    {
      oSel.text = "";
      oSel.execCommand("RemoveFormat", false)
      var AllBody = oTmp.document.body.all;
      // pour chaque lien du document, lui appliquer le style
      //si c'est un lien vers un fichier, ne pas le coller
      for (var i  = oTmp.document.all.tags("A").length - 1; i >= 0; i--)
      {
        oTmp.document.all.tags("A")[i].className = "LINK"
      }
      
      //Supprimer tous les élément d'un tableau
      var str = oTmp.document.body.innerHTML
      var pattern = "<TABLE[^>]*>|</TABLE>"
      pattern += "|<TD[^>]*>|</TD>"
      pattern += "|<TR[^>]*>|</TR>"
      pattern += "|<TBODY[^>]*>|</TBODY>"
      pattern += "|<THEAD[^>]*>|</THEAD>"
      pattern += "|<TFOOT[^>]*>|</TFOOT>"
      pattern += "|<TH[^>]*>|</TH>"
      pattern += "|<COL[^>]*>|</COL>"
      pattern += "|<IMG[^>]*>"
      var RE1 = new RegExp(pattern, "gi");
      str = str.replace(RE1, "")

/*********************************
/ traitement à faire aussi pour la table
/*********************************/
      str = str.replace("\n", "")

    // On garde les indices
    //var RE1 = new RegExp("<span (?:\\s|[^>])*style=\"(?:\\s|[^>])*mso-text-raise: -(?:\\s|[^>])*>((\\s|[^><])*)</span>", "gi");
    var RE1 = new RegExp("<span (.*|[^>])style=\"(.*|[^>])mso-text-raise: -(.*|[^>])\">((.*|[^><]))</span>", "gi");
    RE1.multiline = true;
    var arr = str.match(RE1);
    if(arr != null)
    {
       for(i=0; i < arr.length ;i++)
       {
          var RE2 = new RegExp('<span (?:\\s|[^>])*>', 'gi');
          var tmp = v.replace(RE2, "<sub>")
          var RE2 = new RegExp('</span>', 'gi');
          tmp = tmp.replace(RE2, "</sub>")
          str = str.replace(arr[i], tmp)
       }
    }
    
   // On garde les exposants
    //var RE1 = new RegExp('<span (?:\\s|[^>])*style="(?:\\s|[^>])*mso-text-raise: [0-9](?:\\s|[^>])*>((\\s|[^><])*)</span>', "gi");
    var RE1 = new RegExp("<span (.*|[^>])style=\"(.*|[^>])mso-text-raise: [0-9](.*|[^>])\">((.*|[^><]))</span>", "gi");
    RE1.multiline = true;
    var arr = str.match(RE1)
    if(arr != null)
    {
       for(i=0; i < arr.length ;i++)
       {
          var RE2 = new RegExp('<span (?:\\s|[^>])*>', 'gi');
          var tmp = arr[i].replace(RE2, "<sup>")
          var RE2 = new RegExp('</span>', 'gi');
          tmp = tmp.replace(RE2, "</sup>")
          str = str.replace(arr[i], tmp)
       }
    }

    var RE2 = new RegExp('<\\w*:[^>]*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('</\\w*:[^>]*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('<[?]xml:namespace[^>]*>', 'gi');
    str = str.replace(RE2, "")
    
    //On ne colle pas les balises SPAN
    var RE2 = new RegExp('<(span|h[0-9])(?:\\s|[^>])*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('</(span|h[0-9])>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('style="(?:\\s|[^>"])*"(?=(?:\\s|[^>])*>)', 'gi');
    str = str.replace(RE2, "")

/*********************************
/ traitement à faire aussi pour la table
/ FIN
/*********************************/

      oSel.pasteHTML(str);
      return false;
    }    
    
//Sinon edition de bloc table
    var oTables = oTmp.document.all.tags("TABLE");
    for(i=0; i < oTables.length; i++)
    {
      // Donner une id au tableau;
      var id = this.TableIdMax;
      oTables[i].id = "t"+id;
      oTables[i].border = 1;
      oTables[i].borderColor = this.Color1;
      oTables[i].perso = "Color1";
      oTables[i].cellPadding = 2;
      oTables[i].cellSpacing = 0;
      
      this.TableIdMax++;

      if(typeof oTables[i].width != "undefined" && oTables[i].width.indexOf("%") >= 0) oTables[i].width = "";

      // Ajouter des éléments col à un élément Table
      
      //Calcul du nombre de colonnes
      var nbCol = 0;
      for(k=0; k<oTables[i].rows(0).cells.length; k++)
      {
        //alert(oTables[i].rows(0).cells[k].colSpan);
        nbCol += oTables[i].rows(0).cells[k].colSpan
      }
      var tRow = oTables[i].rows.length;
      var tCol = nbCol;
      //init du tableau temporaire JS
      var tSize = new Array();
      var tReel = new Array();
      for(j=0; j<tRow; j++)
      {
        tReel[j] = new Array();
      }
      //tReel est le tableau qui permettra le calcul de largeur des colonnes
      var tRow = oTables[i].rows.length;
      var tCol = nbCol;
      for(j=0; j<tRow; j++)
      {
        for(k=0, pos=0; k<oTables[i].rows(j).cells.length; k++)
        {
          if(typeof tReel[j][pos] == "undefined")
          {
            var rSpan = oTables[i].rows(j).cells[k].rowSpan;
            var cSpan = oTables[i].rows(j).cells[k].colSpan;
            for(m=j; m<j+rSpan; m++)
            {
              for(n=pos; n<pos+cSpan; n++)
              {
                tReel[m][n] = ''+j+'.'+k;
              }
            }
            pos += cSpan;
          }
          else { pos++; k--; }
        }
      }    
      //tSize est le tableau qui contient les largeurs de colonnes
      if (tReel.length>0)
      {
        //alert(tReel[0].length)
        for(j=0; j < tReel[0].length; j++)
        {
          tSize[j] = 0;
          var hasColSpan = false
          for(k=0; k < tReel.length; k++)
          {
            var point = tReel[k][j].indexOf('.');
            var iHtml = parseInt(tReel[k][j].substring(0,point));
            var jHtml = parseInt(tReel[k][j].substring(point+1));
            var cell = oTables[i].rows(iHtml).cells[jHtml];
            if (cell.colSpan == 1)
            {
              if(cell.width != 0) tSize[j] = parseInt(cell.width);
              else tSize[j] = 50;
              k = tReel.length;
            }
          }
        }
      }
      // recherche des largeurs qui n'ont pas encore été trouvées :
      for(j=0; j<tSize.length; j++)
      {
        if (tSize[j] == 0)
        {
          for(k=0; k<tReel.length; k++)
          {
            var point = tReel[k][j].indexOf('.');
            var iHtml = parseInt(tReel[k][j].substring(0,point));
            var jHtml = parseInt(tReel[k][j].substring(point+1));
            var cell = oTables[i].rows(iHtml).cells[jHtml];
            if (cell.colSpan == 2)
            {
              if(cell.width == 0) tSize[j] = 50;
              else if (tReel[k][j] == tReel[k][j-1])
              {
                tSize[j] = parseInt(cell.width) - tSize[j-1];
              }
              else
              {
                tSize[j] = parseInt(cell.width) - tSize[j+1];
              }
              k=tReel.length;
             }
          }
        }
      }
      if(oTables[i].all.tags("COLGROUP").length == 0)
      {
        for(k=nbCol-1; k>=0; k--)
        {
          var oElem = oTmp.document.createElement("COL");
          oElem.width = tSize[k];
          oTables[i].insertAdjacentElement("afterBegin",oElem)
        }
        var TR = oTables[i].insertRow(0);
        TR.className = "Color1"
        TR.style.display = 'none';
        for(j=0; j < nbCol ; j++)
        {
          var TD = oTables[i].rows(0).insertCell();
          TD.style.cssText = "margin: 0px; padding: 0px; height: 1px"
          TD.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
          TD.contentEditable = false//TD.onclick = "alert('ert')"
        }
      }
      else
      {
        var TR = oTables[i].rows[0];
        if(TR.style.dysplay != 'none')
        {
			TR = oTables[i].insertRow(0);
			for(j=0; j < nbCol ; j++)
			{
			var TD = oTables[i].rows(0).insertCell();
			TD.style.cssText = "margin: 0px; padding: 0px; height: 1px"
			TD.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
			TD.contentEditable = false//TD.onclick = "alert('ert')"
			}
        }
        else
        {
			for(j=0; j < TR.cells.length ; j++)
			{
			var TD = TR.cells[j];
			TD.style.cssText = "margin: 0px; padding: 0px; height: 1px"
			TD.innerHTML = '<img unselectable="on" src="Imgs/ghost.gif" width="1" height="1">';
			TD.contentEditable = false//TD.onclick = "alert('ert')"
			}
        }     
		TR.className = "Color1"
		TR.style.display='none'
      }
      var oTDs = oTables[i].all.tags("TD")
      for(j=0; j < oTDs.length; j++)
      {
        oTDs[j].removeAttribute("width");
      }
    }
    // Applique le CSS à un lien
    var oLinks = oTmp.document.getElementsByTagName("A");
    for(i=0; i<oLinks.length; i++)
    {
      var href = oLinks[i].href
      oLinks[i].className="LINK"
    }
    if(!isInTable && oTmp.document.body.all.tags("TABLE").length != 0)
    {
      var sHTML = oTmp.document.body.all.tags("TABLE")[0].outerHTML;
    }
    else if(isInTable)
    {
      var sHTML = oTmp.document.body.innerHTML//all.tags("TABLE")[0].outerHTML;
    }
    else
    {
      return false;
    }
    var str = sHTML;
    
    
/*********************************
/ traitement à faire aussi pour le texte
/*********************************/

    // On garde les indices
    var RE1 = new RegExp('<span (?:\\s|[^>])*style="(?:\\s|[^>])*mso-text-raise: -(?:\\s|[^>])*>((\\s|[^><])*)</span>', "gi");
    RE1.multiline = true;
    var arr = str.match(RE1)
    if(arr != null)
    {
       for(i=0; i < arr.length ;i++)
       {
          var RE2 = new RegExp('<span (?:\\s|[^>])*>', 'gi');
          var tmp = arr[i].replace(RE2, "<sub>")
          var RE2 = new RegExp('</span>', 'gi');
          tmp = tmp.replace(RE2, "</sub>")
          str = str.replace(arr[i], tmp)
       }
    }
    
   // On garde les exposants
    var RE1 = new RegExp('<span (?:\\s|[^>])*style="(?:\\s|[^>])*mso-text-raise: [0-9](?:\\s|[^>])*>((\\s|[^><])*)</span>', "gi");
    RE1.multiline = true;
    var arr = str.match(RE1)
    if(arr != null)
    {
       for(i=0; i < arr.length ;i++)
       {
          var RE2 = new RegExp('<span (?:\\s|[^>])*>', 'gi');
          var tmp = arr[i].replace(RE2, "<sup>")
          var RE2 = new RegExp('</span>', 'gi');
          tmp = tmp.replace(RE2, "</sup>")
          str = str.replace(arr[i], tmp)
       }
    }

    //On ne colle pas les balises SPAN

    var RE2 = new RegExp('<\\w*:[^>]*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('</\\w*:[^>]*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('<[?]xml:namespace[^>]*>', 'gi');
    str = str.replace(RE2, "")
    
    //On ne colle pas les balises SPAN
    var RE2 = new RegExp('<(span|h[0-9])(?:\\s|[^>])*>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('</(span|h[0-9])>', 'gi');
    str = str.replace(RE2, "")
    var RE2 = new RegExp('style="(?:\\s|[^>"])*"(?=(?:\\s|[^>])*>)', 'gi');
    str = str.replace(RE2, "")
    
/*********************************
/ traitement à faire aussi pour le texte
/ FIN
/*********************************/
 
    oSel.pasteHTML(str);
    var oTables = this.Editor.document.all.tags("TABLE")
    for(j=0; j < oTables.length; j++)
    {
      oTables[j].rows[0].style.display = 'none';
      oTables[j].rows[0].style.height = '1px';
      oTables[j].rows[0].height = '1';
      for(k=1; k < oTables[j].rows.length; k++)
      {
        for(l=0; l < oTables[j].rows[k].cells.length; l++)
        {
          if(oTables[j].rows[k].cells[l].innerText == "") oTables[j].rows[k].cells[l].innerHTML += "&nbsp;";
        }
      }
    }
    return false;
  }
}

function InsertImage()
{
  this.SaveSelection();
  this.newWin = window.open('EditPictureStep1.asp?FromEditor=1&IdBox=0&Tag=Picture&Type=0','PictureUpload','scrollbars=yes,width=617,height=160');
  this.newWin.focus();
}

function InsertLink(IdSite)
{
  this.SaveSelection();
  this.newWin = window.open('EditLinkUrl.asp?FromEditor=1&IdSite='+IdSite+'&Pos=&IdBox=0&Tag=Url&Type=href','Link','scrollbars=yes,width=617,height=260');
  this.newWin.focus();
}
function InsertLinkFromForum(IdSite,Path)
{
  this.SaveSelection();
  //this.newWin = window.open('http://www.google.fr/','Link','scrollbars=yes,width=617,height=260');
  this.newWin = window.open(Path+'/Web/EditLinkUrlForum.asp','Link','scrollbars=yes,width=617,height=260');
  this.newWin.focus();
}



function DisplaySymbolDivs(Name)
{
   if(typeof Name == "undefined"){ Name = 'obj'}
   var html = ""
html += '     <div id="'+Name+'Special" style="position:absolute; display:none"  onMouseLeave="hide(\''+Name+'\');">'
html += '       <table border="0" bgColor="#000000" cellspacing="1" cellpadding="2" borderColor="#666666" onclick="'+Name+'.Sel.select()" style="font-size:12px">'
html += '          <tr style="cursor:default">'
html += '            <td height="15" bgColor="#FFFFFF" align=center colspan=5>'
html += '                <b>Normal</b>'
html += '            </td>'
html += '            <td height="15" bgColor="#FFFFFF" align=center colspan=5>'
html += '                <b>Superscript</b>'
html += '            </td>'
html += '            <td height="15" bgColor="#FFFFFF" align=center colspan=5>'
html += '                <b>Subscript</b>'
html += '            </td>'
html += '          </tr>'
html += '          <tr>'

var t1 = new Array("&euro;", "&iexcl;", "&cent;", "&pound;", "&curren;")
var t2 = new Array( "2","3","X", "&reg;", "&copy;")
var t3 = new Array( "2","3","X", "&reg;", "&copy;")
for(var i=1;i<=3;i++)
{
  for(var j=0;j<5;j++)
  {
     if(i==1)      var c = eval("t"+i)[j];
     else if(i==2) var c = "<sup>" + eval("t"+i)[j] + "</sup>";
     else if(i==3) var c = "<sub>" + eval("t"+i)[j] + "</sub>";
     html  += "<td height='15' width='15' bgColor='#FFFFFF' align=center onmouseenter=\"displaySymbol('"+c+"','"+Name+"')\" "
     if(i==1)      html  += "onclick=\""+Name+".Format('" + eval("t"+i)[j] + "',1);\" ";
     else if(i==2) html  += "onclick=\""+Name+".Format('" + eval("t"+i)[j] + "',2);\" ";
     else if(i==3) html  += "onclick=\""+Name+".Format('" + eval("t"+i)[j] + "',3);\" ";
     html  += "onmouseover=\"this.bgColor='#CCCCCC'; this.style.color='#FF0000'\" ";
     html  += "onmouseout=\""+Name+".SaveSelection(); this.bgColor='#FFFFFF'; this.style.color=''\" ";
     html  += "style=\"cursor:hand\">&nbsp;" + c + "&nbsp;</td>"
  }
}

html += '          </tr>'
html += '          <tr>'
html += '            <td height="15" bgColor="#FFFFFF" align=center colspan=15 style="cursor:hand" onclick="showMore(\''+Name+'\')">'
html += '                More symbols'
html += '            </td>'
html += '          </tr>'
html += '        </table>'
html += '   </div>'
html += '   <div id="'+Name+'More" style="position:absolute; display:none" onMouseLeave="hideMore(\''+Name+'\');">'
html += '      <table border="0" bgColor="#000000" cellspacing="1" cellpadding="2" borderColor="#666666" style="font-size:12px">'
           var s1 = new Array("&quot;","&lt;", "&amp;", "&gt;", "&euro;", "&iexcl;", "&cent;", "&pound;", "&curren;", "&yen;")
           var s2 = new Array("&brvbar;", "&sect;", "&uml;", "&copy;", "&ordf;", "&laquo;", "&not;", "&shy;", "&reg;", "&macr;")
           var s3 = new Array("&deg;", "&plusmn;", "&sup2;", "&sup3;", "&acute;", "&micro;", "&para;", "&middot;", "&cedil;", "&sup1;")
           var s4 = new Array("&ordm;", "&raquo;", "&frac14;", "&frac12;", "&frac34;", "&iquest;", "&Agrave;", "&Aacute;", "&Acirc;", "&Atilde;")
           var s5 = new Array("&Auml;", "&Aring;", "&AElig;", "&Ccedil;", "&Egrave;", "&Eacute;", "&Ecirc;", "&Euml;", "&Igrave;", "&Iacute;")
           var s6 = new Array("&Icirc;", "&Iuml;", "&ETH;", "&Ntilde;", "&Ograve;", "&Oacute;", "&Ocirc;", "&Otilde;", "&Ouml;", "&times;")
           var s7 = new Array("&Oslash;", "&Ugrave;", "&Uacute;", "&Ucirc;", "&Uuml;", "&Yacute;", "&THORN;", "&szlig;", "&agrave;", "&aacute;")
           var s8 = new Array("&acirc;", "&atilde;", "&auml;", "&aring;", "&aelig;", "&ccedil;", "&egrave;", "&eacute;", "&ecirc;", "&euml;")
           var s9 = new Array("&igrave;", "&iacute;", "&icirc;", "&iuml;", "&eth;", "&ntilde;", "&ograve;", "&oacute;", "&ocirc;", "&otilde;")
           var s10 = new Array("&ouml;", "&divide;", "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", "&uuml;", "&yacute;", "&thorn;", "&yuml;")

           for(var i=1;i<=10;i++)
             {
             html  += "<tr>"
             for(var j=0;j<9;j++)
               {
                html  += "<td height='15' width='15' bgColor='#FFFFFF' align=center onmouseenter=\"displaySymbol('"+eval("s"+i)[j]+"','"+Name+"')\"  onclick=\""+Name+".Format('" + eval("s"+i)[j] + "',1);\" ";
                html  += "onmouseover=\"this.bgColor='#CCCCCC'; this.style.color='#FF0000'\" ";
                html  += "onmouseout=\"this.bgColor='#FFFFFF'; this.style.color=''\" ";
                html  += "style=\"cursor:hand\">&nbsp;" + eval("s"+i)[j] + "&nbsp;</td>"
               }
             html += "</tr>"
             }
           html += "</table>"
html += '    </div>'
html += '    <div id="'+Name+'Preview" style="position:absolute; display:none"  onMouseLeave="hidePreview(\''+Name+'\');">'
html += '       <table bgColor="#000000" border="0" cellpadding="0" cellspacing="1" width="30" height="30">'
html += '          <tr>'
html += '            <td bgColor="#FFFFFF" width="28" height="28"  align="center" valign="middle">'
html += '                <span id="'+Name+'SymbolPreview" style="font-size:20px">&nbsp;</span>'
html += '            </td>'
html += '          </tr>'
html += '       </table>'
html += '    </div>'


document.write(html)

}


  function showSpecial(x,y, Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var xMousePos = x + document.body.scrollLeft;
    var yMousePos = y + document.body.scrollTop;
    var xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
    var yMousePosMax = document.body.clientHeight + document.body.scrollTop;
    //var msg = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
    //alert(xMousePos + 370 > xMousePosMax)
    //alert(yMousePos + 70 > yMousePosMax)
    
    var Left = (xMousePos + 370 > xMousePosMax)? xMousePosMax - 370 : xMousePos;
    var Top = (yMousePos + 70 > yMousePosMax)? yMousePosMax - 70 : yMousePos;
    var Special = eval("document.all."+Name+"Special")
    Special.style.top = Top;
    Special.style.left = Left;
    Special.style.display="";
  }
  function hide(Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var Special = eval("document.all."+Name+"Special")
    var Preview = eval("document.all."+Name+"Preview")
//    alert("document.all."+Name+"Preview")
    Special.style.display="none";
    Preview.style.display="none";
  }  
  function hideMore(Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var More = eval("document.all."+Name+"More")
    var Preview = eval("document.all."+Name+"Preview")
    More.style.display="none";
    Preview.style.display="none";
  }  

  function showMore(Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var More = eval("document.all."+Name+"More")
    var Special = eval("document.all."+Name+"Special")
    More.style.top = Special.style.top;
    More.style.left = Special.style.left;
    Special.style.display="none";
    More.style.display="";
  }
  
  function displaySymbol(symbol, Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var Special = eval("document.all."+Name+"Special")
    var Preview = eval("document.all."+Name+"Preview")
    var SymbolPreview = eval("document.all."+Name+"SymbolPreview")
     SymbolPreview.innerHTML = symbol;
     Preview.style.top = parseInt(Special.style.top) - 30 ;
     Preview.style.left = parseInt(Special.style.left) - 30 ;
     Preview.style.display = '';
  }
  
// Bloc Table
  function showColors(x,y)
  {
    var xMousePos = x + document.body.scrollLeft;
    var yMousePos = y + document.body.scrollTop;
    var xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
    var yMousePosMax = document.body.clientHeight + document.body.scrollTop;
    //var msg = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
    //alert(xMousePos + 370 > xMousePosMax)
    //alert(yMousePos + 70 > yMousePosMax)
    
    var Left = (xMousePos + 370 > xMousePosMax)? xMousePosMax - 370 : xMousePos;
    var Top = (yMousePos + 70 > yMousePosMax)? yMousePosMax - 70 : yMousePos;
    document.all.ColorPicker.style.top = Top;
    document.all.ColorPicker.style.left = Left;
    document.all.ColorPicker.style.display="";
  }
  function hideColors()
  {
    document.all.ColorPicker.style.display="none";
  }
  
  function hideSpecial(Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    var Special = eval("document.all."+Name+"Special")
    Special.style.display="none";
  }  

  function hide2(Name)
  {
    if(typeof Name == "undefined"){ Name = 'obj'}
    hideSpecial(Name);
    hideColors();
  }
  