﻿var linkArea	=	"";
var uploadNumber=	0;
var Format	=	"html"
var leHidden	=	"";
var to		=	null;
var iframeName	=	"edit1";
var blocStyle	=	"";
var ongletClass		=	"";
var ongletSelClass	=	"";
var divHTML		=	"";
var divSource		=	"";

var cols	=	0;				// Pour insertion d'une table
var rows	=	0;				// Pour insertion d'une table

var selectedTD		=	null;	// La cellule selectionnee
var selectedTable	=	null;	// La table selectionnee
var selectedImage	=	null;	// La table selectionnee
var selectedLink	=	null; 	// Le lien sélectionné
var selectedTarget	=	null;	// Le target sélectionné
var editorMenus		=	null;
var saveStyle		=	"";		// 1.1.8 : le style css de la zone editable

// E-dito 1.1 : Empecher les messages d'erreur JavaScript
function handleError() {
	return true;
}

window.onerror = handleError;

// E-dito 1.1 : Définir les menus de l'editeur (menus est un array)
function setEditorMenu(menus) {
	editorMenus		=	menus;
}

function setIframeName(n) {
	iframeName	= n;
	// E-dito 1.1 : Traiter les evenements pour actualiser le menu	
	// e-dito 1.1.3 - 06/05/06 - empecher double retour a la ligne
	eval(iframeName + ".document.onmouseup  = updateMenuState;");
	//eval(iframeName + ".document.onkeydown    = handleEditorEvents;");
	eval(iframeName + ".document.onkeyup    = KeyCheck;");

}

// 1.2.2 : mettre a jour le menu qui si on appuie sur les fleches ou touche ctrl
function KeyCheck(e) {
	var KeyID = eval(iframeName + ".event.keyCode");
	switch(KeyID) {
		case 17:
	      updateMenuState(); // ctrl
	      break;
	   case 37:
	      updateMenuState(); // gauche
	      break;
	   case 38:
	      updateMenuState(); // haut
	      break;	  
		case 39:
	      updateMenuState(); // droit
	      break;
	   case 40:
	      updateMenuState(); // bas
	      break;
	  }
}

// e-dito 1.1.3 - 14/06/06 - laisser les P comme retour a la ligne et jouer sur le css
function handleEditorEvents() {
	/*if (eval(iframeName + ".event.keyCode") == 13) {
    	doInsertHTML("<BR/>");
        return false;
	}*/
	return true;
}

// Desactiver les icones qui ne peuvent pas être cliquées
// e-dito 1.1.6 : flash - audio - video
function updateMenuCmdSupported(menus) {
		var enableCmd	=	new Array();
		
		// 1.2.2
		enableCmd.push("saveicn");
		enableCmd.push("cancelicn");
		
		// Icones qui ne doivents jamais être désactivées
		enableCmd.push("save");enableCmd.push("new");enableCmd.push("del");	enableCmd.push("back");enableCmd.push("xsltswap");enableCmd.push("zoomp");
		enableCmd.push("objProp");enableCmd.push("cssProperties");
		// Si la selection est du texte
		if (!isImage())	{
			// Afficher copier et couper que si du texte est selectionne
			eval("var edit = " + iframeName + ".document.selection.createRange();");
			if ((edit.text) && (edit.text.length > 0)) {
				enableCmd.push("xsltcut");enableCmd.push("xsltcopy");
			}
			
			// Afficher : tout sauf topMenuCadre (taille du cadre, type de cadre, type de ligne, couleur de cadre, propriété de cellule, ajouter, supprimmer cellule, ligne ou colonne, propriété de l'image)
			enableCmd.push("xsltstyle");enableCmd.push("xsltsize");enableCmd.push("xsltbold");enableCmd.push("xsltitalic");enableCmd.push("xsltunderline");enableCmd.push("xsltleft");
			enableCmd.push("xsltcenter");enableCmd.push("xsltright");enableCmd.push("xsltjustified");enableCmd.push("xsltinvtab");enableCmd.push("xslttab");
			enableCmd.push("xsltPuce");enableCmd.push("xsltList");enableCmd.push("xsltanchor");enableCmd.push("xsltimage");enableCmd.push("xsltlink");enableCmd.push("xsltunlink");
			enableCmd.push("flash");enableCmd.push("video");enableCmd.push("audio");enableCmd.push("xsltfile");enableCmd.push("xslttable");enableCmd.push("xsltbackground");enableCmd.push("xsltforeground");
			
			enableCmd.push("xsltpaste");enableCmd.push("xslrss");
			// 1.2.3 : HR
			enableCmd.push("xsltHR");
		} else {
			// Si la selection est une image
			// Afficher que insérer un lien, insérer un fichier, infos sur les cadres et propriété de l'image
			enableCmd.push("xsltlink");enableCmd.push("xsltunlink");enableCmd.push("xsltfile");enableCmd.push("flash");enableCmd.push("video");enableCmd.push("audio");
			enableCmd.push("cadreTaille");enableCmd.push("cadre");enableCmd.push("cadreType");enableCmd.push("cadreColor");enableCmd.push("impProp");
			enableCmd.push("xsltcut");enableCmd.push("xsltcopy");
		}

		// Si la selection est une table
			// Afficher les propriétés de la table 
			//enableCmd.push("cadreProperties");

		// Si on est dans un cellule
		if (inCell()) {
			// Afficher les infos sur les cadres + propriétés de la table + ajouter/supprimmer cellule, cadres... + 
			enableCmd.push("cadreTaille");enableCmd.push("cadre");enableCmd.push("cadreType");enableCmd.push("cadreColor");enableCmd.push("cadreProperties");
			enableCmd.push("deleteCell");enableCmd.push("FctaddCell");enableCmd.push("FctaddCol");enableCmd.push("FctaddRow");
		}

	for (nbCounter=0; nbCounter < menus.length; nbCounter++) {
		menu			=	menus[nbCounter];
		menu.disableMenu();

		for (x=0; x < enableCmd.length; x++) {
			menu.changeItemState(enableCmd[x], true);
		}
			
		menu.updateMenu();
	}

}

function updateMenuState() {
	// En mode source, laisser le menu desactivé
	if (Format == "Text")
		return;

	eval("var edit = " + iframeName + ".document.selection.createRange();");
	returnValue = true;
	
	// Desactiver les icones qui ne peuvent pas être cliquées
	updateMenuCmdSupported(editorMenus);	

	// Actualiser le(s) menu(s)
	for (counter=0; counter < editorMenus.length; counter++) {
		var count		=	editorMenus[counter].itemCount;
		
		for (j = 0; j < count; j++) {
			if ((editorMenus[counter].items[j].commandName != "") && (editorMenus[counter].items[j] != "separator") && (editorMenus[counter].items[j].type == "item")) {
				// cas particulier pour justify
				if (editorMenus[counter].items[j].commandName == "Justify") {
					// Si pas autorisé, alors griser la case
					if (isJustify()) {
						document.images[editorMenus[counter].items[j].name].className="topMenuOver";
						document.images[editorMenus[counter].items[j].name].onmouseover="";
						document.images[editorMenus[counter].items[j].name].onmouseout="";
					} else {
						document.images[editorMenus[counter].items[j].name].onmouseover=function anonymous() {this.className="topMenuOver"};
						document.images[editorMenus[counter].items[j].name].onmouseout=function anonymous() {this.className="topMenu"};
						document.images[editorMenus[counter].items[j].name].className="topMenu";
					}
				} else {
						if (edit.queryCommandState(editorMenus[counter].items[j].commandName)) {
							// Cette commande est executée sur la selection
							document.images[editorMenus[counter].items[j].name].className="topMenuOver";
							document.images[editorMenus[counter].items[j].name].onmouseover="";
							document.images[editorMenus[counter].items[j].name].onmouseout="";
						} else {
							// Cette commande n'est pas executée sur la selection
							document.images[editorMenus[counter].items[j].name].className="topMenu";
							document.images[editorMenus[counter].items[j].name].onmouseover=function anonymous() {this.className="topMenuOver"};
							document.images[editorMenus[counter].items[j].name].onmouseout=function anonymous() {this.className="topMenu"};
						}
				}
			}
			// Cas particuliers des listes déroulantes
			if ((editorMenus[counter].items[j].commandName != "") && (editorMenus[counter].items[j] != "separator") && (editorMenus[counter].items[j].type == "list")) {
				// cas pour les cadres
				if (editorMenus[counter].items[j].commandName == "cadreTaille") {
					//alert("ici");
				} else
				if ((editorMenus[counter].items[j].commandName == "zoom") || (editorMenus[counter].items[j].commandName == "zoomPage")) {
					// cas particulier pour le zoom
					eval("var zoomVal = " + iframeName + ".document.body.style.zoom");
					if (zoomVal == "25%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=0;
					if (zoomVal == "50%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=1;
					if (zoomVal == "75%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=2;
					if (zoomVal == "100%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=3;
					if (zoomVal == "125%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=4;
					if (zoomVal == "150%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=5;
					if (zoomVal == "175%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=6;
					if (zoomVal == "200%")
						document.all(editorMenus[counter].items[j].name).selectedIndex=7;
				} else
					// e-dito 1.1.3 - 11/06/2006 - ignorer "queryCommandValue" sit font-size
					if ((edit.queryCommandValue(editorMenus[counter].items[j].commandName)) || (editorMenus[counter].items[j].commandName == "FontSize")) {
						if (editorMenus[counter].items[j].commandName == "FontSize") {
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "1")
								document.all(editorMenus[counter].items[j].name).selectedIndex=1;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "2")
								document.all(editorMenus[counter].items[j].name).selectedIndex=2;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "3")
								document.all(editorMenus[counter].items[j].name).selectedIndex=3;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "4")
								document.all(editorMenus[counter].items[j].name).selectedIndex=4;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "5")
								document.all(editorMenus[counter].items[j].name).selectedIndex=5;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "6")
								document.all(editorMenus[counter].items[j].name).selectedIndex=6;
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "7")
								document.all(editorMenus[counter].items[j].name).selectedIndex=7;
							/*fontSize	=	getFontSize();
							
							if (fontSize == "0")
								document.all(editorMenus[counter].items[j].name).selectedIndex=0;
							if (fontSize == "8px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=1;
							if (fontSize == "9px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=2;
							if (fontSize == "10px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=3;
							if (fontSize == "11px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=4;
							if (fontSize == "12px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=5;
							if (fontSize == "14px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=6;
							if (fontSize == "16px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=7;
							if (fontSize == "18px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=8;
							if (fontSize == "20px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=9;
							if (fontSize == "22px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=10;
							if (fontSize == "24px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=11;
							if (fontSize == "26px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=12;
							if (fontSize == "28px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=13;
							if (fontSize == "36px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=14;
							if (fontSize == "48px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=15;
							if (fontSize == "72px")
								document.all(editorMenus[counter].items[j].name).selectedIndex=16;*/

						}
						if (editorMenus[counter].items[j].commandName == "FontName") {
							if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Arial")
								document.all(editorMenus[counter].items[j].name).selectedIndex=1;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Times New Roman")
								document.all(editorMenus[counter].items[j].name).selectedIndex=2;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Verdana")
								document.all(editorMenus[counter].items[j].name).selectedIndex=3;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Tahoma")
								document.all(editorMenus[counter].items[j].name).selectedIndex=4;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Georgia")
								document.all(editorMenus[counter].items[j].name).selectedIndex=5;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Comic Sans MS")
								document.all(editorMenus[counter].items[j].name).selectedIndex=6;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Amelia BT")
								document.all(editorMenus[counter].items[j].name).selectedIndex=7;
							else if (edit.queryCommandValue(editorMenus[counter].items[j].commandName) == "Courier New")
								document.all(editorMenus[counter].items[j].name).selectedIndex=8;
							else
								document.all(editorMenus[counter].items[j].name).selectedIndex=0;
						}
					}
			}
		}
	}
	return returnValue;
}

function handleLineBreak() {
         if (eval(iframeName + ".event.keyCode") == 13) {
            doInsertHTML("<BR/>");
            return false;
         }
         return true;
}

function doFormat(command) {
  execCommand(command,arguments[1]);
}

function doUnorderedList() {
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.execCommand('insertunorderedlist', false, null); 
}

// 1.2.3
function doHR() {
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.execCommand('InsertHorizontalRule'); 

}
function doOrderedList() {
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.execCommand('insertorderedlist', false, null); 
}

function execCommand(command) {
	if (Format=="html") {
		eval("var edit = " + iframeName + ".document.selection.createRange();");
		
		//var edit=document.getElementById(iframeName);
		//var oSel=edit.getSelection();
	
		if (arguments[1]==null)
			edit.execCommand(command);
		else
			edit.execCommand(command,false, arguments[1]);
		edit.select();
		eval(iframeName + ".focus();");
	}
}
  
// Afficher la fenetre pour choisir la taille de la table à inserer
function showTable() {
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	
	document.getElementById(divTable).style.width = '106';
	document.getElementById(divTable).style.height = '106';

	document.getElementById(divBgTable).style.width = '106';
	document.getElementById(divBgTable).style.height = '106';

	document.getElementById(divSelection).style.width = '0';
	document.getElementById(divSelection).style.height = '0';

	document.getElementById(divTable).style.display = '';
	document.getElementById(divBgTable).style.display = '';
	document.getElementById(divSelection).style.display = '';

	//document.getElementById(divTable).style.top = document.body.scrollTop + 50;
	//document.getElementById(divBgTable).style.top = document.body.scrollTop + 50;
	//document.getElementById(divSelection).style.top = document.body.scrollTop + 50;
}

// Cacher la table
function hideTable(sel){
		if ((sel) && (cols>0) && (document.getElementById(divTable).style.display != 'none')) {
				//alert(document.getElementById(divTable).style.display);
			selectTableSize();
		}
		document.getElementById(divTable).style.display = 'none';
		document.getElementById(divBgTable).style.display = 'none';
		document.getElementById(divSelection).style.display = 'none';

}

// Inserer du Text ou du Html l'emplacement du curseur  
function doInsertHTML(what){
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(what);
}

// Inserer une division non éditable pour inserer un champ
function doInsertDIV(nom,desc,type,mw,mh,w,h) {
	setFocus();
	eval ("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	if ((type == "textField") || (type == "textArea") || (type == "date")) {
		edit.pasteHTML("<SPAN ID='" + nom + "' contentEditable=false unselectable='on'>" + desc + "</SPAN>");
	}
	if (type == "input") {
		edit.pasteHTML("<INPUT TYPE='text' ID='" + nom + "' NAME='" + nom + "' contentEditable=false unselectable='off' VALUE='' maxLength='" + mw + "'>");
	}
	// edito 1.1.6 : comentaire client
	if (type == "textarea") {
		edit.pasteHTML("<TEXTAREA ID=" + nom + " NAME=" + nom + " contentEditable=false unselectable='off' maxLength='" + mw + "'></TEXTAREA>");
	}
	if (type == "select") {
		edit.pasteHTML("<SELECT ID='" + nom + "' NAME='" + nom + "' contentEditable=false unselectable='off'></SELECT>");
	}	
	if (type == "checkbox") {
		edit.pasteHTML("<INPUT TYPE='checkbox' ID='" + nom + "' contentEditable=false unselectable='off' VALUE=''>");
	}
	if (type == "password") {
		edit.pasteHTML("<INPUT TYPE='password' ID='" + nom + "' contentEditable=false unselectable='off' VALUE=''>");
	}
	if (type == "button") {
		edit.pasteHTML("<INPUT TYPE='submit' ID='" + nom + "' contentEditable=false unselectable='off' VALUE='" + desc + "'>");
	}
	if (type == "image") {
		html	= "<IMG ID='" + nom + "' SRC='images/selimage.gif' unselectable='off' STYLE='border-color:black;border-style:solid;border-width:2px;' ALT='" + desc + "' onclick=parent.selImage(this) ";
		if (w != 0)
			html	+= " width = " + w;
		else
			html	+= " width = \"undefined\" ";
		if (h != 0)
			html	+= " height = " + h;
		else
			html	+= " height = \"undefined\" ";
		html += ">";
		edit.pasteHTML(html);
	}
	if (type == "link") {
		window.open("selectlink.php?type=link&desc=" + desc + "&nom=" + nom + "&language=" + mw,"selectLink","width=450, height=230");
	}
	if (type == "mail") {
		edit.pasteHTML("<A HREF='mailTo:{" + nom.toUpperCase() + "}'>"+ desc + "</A>");
	}
	if (type == "portletlink") {
		doInsertLink(nom,"",nom);
	}
	
	if (type == "file") {
		window.showModalDialog("selectlink.php?type=file&desc=" + desc + "&nom=" + nom + "&language=" + mw,"selectLink","width=450, height=230");
	}
}

// retrouver le lien actuel
function getSelectedLink() {
	// Get the editor selection
	var linkInformation = null;

	eval("var thelink = " + iframeName + ".document.selection.createRange();");	

if (isA()) {
		linkInformation = new Object();
		linkInformation["href"] = selectedLink;		
		linkInformation["target"] = selectedTarget;	
		linkInformation["rel"] = selectedRel;	
}
/*	if (thelink) {
		if (isImage()) {
			thelink = selectedImage;
		}
		
		thelink = thelink.parentElement;
		if (!/^a$/i.test(thelink.tagName)) {
			thelink = null;
		}
	}

	if (thelink != null) {
		linkInformation = new Object();
		var linkUri = thelink.href;
		linkInformation["href"] = linkUri;		
		linkInformation["name"] = thelink.name;
		linkInformation["target"] = thelink.target;	
	}*/

	return linkInformation;
}

// Insertion d'un lien
function doInsertLink(url,target,label) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

    eval("var Link = " + iframeName + ".document.createElement('<A>'); ");

	if ((url.toUpperCase().indexOf("MAILTO:") == 0) || (url.indexOf("http://") == 0) || (url.indexOf("#") == 0))
		linkSource	= url;
	else
		linkSource	= "http://" + url;

    edit.execCommand("CreateLink",false,linkSource);

	if (isImage()) {
			Link 	= 	selectedImage.parentElement;
	} else {
			Link	=	edit.parentElement();
	}
		
	if (target.length > 0)
		Link.target	= target;
	else
		Link.target	= "_self";

	setFocus();
}

// Insertion d'un lien vers un fichier
function doInsertLinkFile(url,target,label) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

    eval("var Link = " + iframeName + ".document.createElement('<A>'); ");

	linkSource	= "./objects/" + url;

    edit.execCommand("CreateLink",false,linkSource);

	setFocus();
}

// Insertion d'une ancre
function doInsertAnchor(label) {
	nom			= prompt(label,label);
	if (nom != null) {
		linkString	= "<A NAME='" + nom + "'></A>";
		setFocus();
		eval("var edit = " + iframeName + ".document.selection.createRange();");
		edit.collapse();
		edit.pasteHTML(linkString);
	}
}

// 1.2.0 : Insertion d'un fils RSS
function doInsertRSS(site,url,nb,desc,dt) {
	rssString = " &nbsp;\r\n<DIV id=rss> \r\n<SCRIPT language='JavaScript' type='text/javascript' src='"+site+"admin/rss2javascript.php?url="+url+"&nbItems="+nb+"&showDescription="+desc+"&showDate="+dt+"'></SCRIPT>\r\n</DIV> ";
	
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(rssString);
}

// Insertion d'une image
 function doInsertImage(imgSrc) {
 	imgString="<img src='"+imgSrc+"' border='0' style='border-width:none;' onClick='parent.selImage(this)'/>"; 
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(imgString);
}

// Insertion d'une image nouvelle version 1.1.1
// 1.1.8 : ajout de la fonction zoom
 function doInsertImage111(imgSrc,width,height,marginleft,marginright,margintop,marginbottom,align,zoom) {
  	imgString		=	"";
	
	if  (zoom == 1) {
		imgString	+=	"<A HREF='"+imgSrc+"' rel=lightbox>";
	}
	
	imgString		+=	"<img src='"+imgSrc+"' border='0' style='border-width:none;";
  	if (width != "")
		imgString	+=	"width:" + width + ";";
	if (height != "")
		imgString	+=	"height:" + height + ";";

	if (marginleft != "")
		imgString	+=	"margin-left:" + marginleft + ";";
	if (marginright != "")
		imgString	+=	"margin-right:" + marginright + ";";
	if (margintop != "")
		imgString	+=	"margin-top:" + margintop + ";";
	if (marginbottom != "")
		imgString	+=	"margin-bottom:" + marginbottom + ";";
				
	imgString		+=	"' onClick='parent.selImage(this)'";
 	imgString		+=	" align=\"" + align + "\"";
  	imgString		+=	" />"; 
	
	if  (zoom == 1) {
		imgString	+=	"</A>"; 
	}
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(imgString);
}

// Insertion d'une image pour internet explorer 6 (choix des parametres)
 function doInsertImage6(imgSrc,width,height,hspace,vspace,align,valign,alt) {
  	imgString		=	"<img src='"+imgSrc+"' border='0' style='border-width:none;";
  	if (width != "")
		imgString	+=	"width:" + width + ";";
	if (height != "")
		imgString	+=	"height:" + height + ";";
	if (hspace != "")
		imgString	+=	"margin-left:" + hspace + ";margin-right:" + hspace + ";";
	if (vspace != "")
		imgString	+=	"margin-top:" + vspace + ";margin-bottom:" + vspace + ";";
		imgString		+=	"' onClick='parent.selImage(this)'";
  	imgString		+=	" align=\"" + align + "\"";
  	imgString		+=	" valign=\"" + valign + "\"";
  	imgString		+=	" alt=\"" + alt + "\"";
  	imgString		+=	" />"; 
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(imgString);
}

// Insertion d'un lien vers un fichier
function doInsertFrontFile(url,label,target) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

    eval("var Link = " + iframeName + ".document.createElement('<A>'); ");

	linkSource	= url;

    edit.execCommand("CreateLink",false,linkSource);

	setFocus();
}

// 1.1.6 : Insertion d'une annimation flash
function doInsertFlash(url,mime,width,height,controls,autostart,loop) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

	edit.collapse();
	edit.pasteHTML("<embed src='" + url + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' menu='"+controls+"' loop='"+loop+"' play='"+autostart+"' />");
	setFocus();
}

// 1.1.6 : Insertion d'une video
function doInsertVideo(url,mime,width,height,controls,autostart,loop) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

	edit.collapse();
	// Prendre en compte les cas particulier pour real et quicktime
	if (mime == "audio/x-pn-realaudio-plugin") {
		edit.pasteHTML("<EMBED SRC='" + url + "' type='" + mime + "' SHOWCONTROLS='"+controls+"' CONTROLS='imagewindow' CONSOLE='video' LOOP='"+loop+"' AUTOSTART='"+autostart+"'  HEIGHT='" + height + "' WIDTH='" + width + "' BORDER='0'/>");
	} else if (mime == "video/quicktime") {
		edit.pasteHTML("<EMBED SRC='" + url + "' type='" + mime + "' SHOWCONTROLS='"+controls+"' CONTROLS='"+controls+"' CONTROLLER='"+controls+"' LOOP='"+loop+"' AUTOSTART='"+autostart+"' AUTOPLAY='"+autostart+"' HEIGHT='" + height + "' WIDTH='" + width + "' BORDER='0'/>");
	} else {
		edit.pasteHTML("<EMBED SRC='" + url + "' type='" + mime + "' SHOWCONTROLS='"+controls+"' CONTROLS='"+controls+"' LOOP='"+loop+"' AUTOSTART='"+autostart+"' HEIGHT='" + height + "' WIDTH='" + width + "' BORDER='0'/>");	
	}
	
	setFocus();
}

// 1.1.6 : Insertion d'audio
function doInsertAudio(url,mime,width,height,controls,autostart,loop) {
	eval("var edit = " + iframeName + ".document.selection.createRange();");

	edit.collapse();
	edit.pasteHTML("<EMBED SRC='" + url + "' type='" + mime + "' CONTROLS='"+controls+"' controller='"+controls+"' LOOP='"+loop+"' AUTOSTART='"+autostart+"' HEIGHT='" + height + "' WIDTH='" + width + "' BORDER='0'/>");

	setFocus();
}

// Supprimer un lien
function unlink() {
	if (isA()) {
		execCommand("Unlink"); 
	}
}

// Tester si le curseur est à l'interieur d'une cellule d'une table
function isA() {
	try {
		// 1.1.8 : retrouver le lien sur l'image s'il existe
		var tag,oRange;
		eval("var sel = " + iframeName + ".document.selection;");
		if (sel.type=="Control") {
			oRange = sel.createRange();
			for (i=0;i<oRange.length;i++){
				if (oRange(i).parentNode){
					tag=oRange(i).parentNode;
					break;
				}
			}
			while (tag&&tag.nodeName!="A") 
				tag=tag.parentNode;
		} else{
			eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
			while ((tag.tagName != "BODY") && (tag.tagName != "A")) {
				tag = tag.parentElement;
			}
		}

		if (tag.tagName == "A") {
			selectedLink			= 	tag;
			selectedTarget			=	tag.target;
			if (tag.rel)
				selectedRel			=	tag.rel;
			else
				selectedRel			=	"";
			return true;
		} else
			return false;		
	} catch (err)
	{}

	return false;
}

function isImage() {
	setFocus();
	retValue	=	false;
	eval ("var oControlRange = " + iframeName + ".document.selection.createRange();");
    	for (i = 0; i < oControlRange.length; i++) {
			if (oControlRange(i).tagName == "IMG") {
				selectedImage =	oControlRange(i);
				return true;
			}
		}
	return retValue;
}

function isForm() {
	setFocus();
	retValue	=	false;
	eval("var oControlRange = " + iframeName + ".document.selection.createRange();");
    	for (i = 0; i < oControlRange.length; i++) {
		if (oControlRange(i).tagName == "INPUT") {
			selectedForm 	=	oControlRange(i);
			retValue	=	true;
		}
	}

	return retValue;
}

function selImage(obj) {
	selectedImage	= obj;
	window.open("/admin/imageproperties.php?language=de&type=table","imageProperties","width=430, height=434");
}

// Zoomer la page d'edition
function zoomPage(z) {
	eval(iframeName + ".document.body.style.zoom = z");
	updateMenuState();
}

// Tester si le curseur est à l'interieur d'une cellule d'une table
function inCell() {
	setFocus();
	eval("var oControlRange = " + iframeName + ".document.selection.createRange();");

	try {
		eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
		//while ((tag.tagName != "BODY") && (tag.tagName != "TD") && (tag.tagName != "TABLE")) {
		while ((tag.tagName != "BODY") && (tag.tagName != "TD")) {
			tag = tag.parentElement;
		}
		
		if ((tag.tagName == "TD") || (tag.tagName == "TABLE")) {
			selectedTD			= tag;
			while ((tag.tagName != "BODY") && (tag.tagName != "TABLE")) 
				tag				= tag.parentElement;

			if (tag.tagName == "TABLE")
				selectedTable	= tag;
			return true;
		} else
			return false;		
	} catch (err)
	{}

	return false;
}

// Methodes pour choisir le cadre d'une cellule ou d'une image
function selFrame() {
	document.getElementById("frame").style.left = 138;
	document.getElementById("frame").style.top = document.body.scrollTop + 50;
	document.getElementById("frame").style.display = "";	
}

function hideFrame() {
	document.getElementById("frame").style.display = "none";	
}

function doFrame(left,top,right,bottom) {
	if (isForm()) {
		if ((selectedForm.style.borderWidth == "none") || (selectedForm.style.borderWidth == ""))
			selectedForm.style.borderWidth = "1px";
		if ((!left) && (!top) && (!right) && (!bottom))
			selectedForm.style.borderStyle = "none";
		if (left)
			selectedForm.style.borderLeftStyle = "solid";
		if (top)
			selectedForm.style.borderTopStyle = "solid";
		if (right)
			selectedForm.style.borderRightStyle = "solid";
		if (bottom)
			selectedForm.style.borderBottomStyle = "solid";
	}
		
	if (isImage()) {
		if ((selectedImage.style.borderWidth == "none") || (selectedImage.style.borderWidth == ""))
			selectedImage.style.borderWidth = "1px";

		if ((!left) && (!top) && (!right) && (!bottom))
			selectedImage.style.borderStyle = "none";
		if (left)
			selectedImage.style.borderLeftStyle = "solid";
		if (top)
			selectedImage.style.borderTopStyle = "solid";
		if (right)
			selectedImage.style.borderRightStyle = "solid";
		if (bottom)
			selectedImage.style.borderBottomStyle = "solid";
	}

	if (inCell()) {
		if ((!left) && (!top) && (!right) && (!bottom))
			selectedTD.style.borderStyle = "none";
			
		if (left)
			selectedTD.style.borderLeftStyle = "solid";
		if (top)
			selectedTD.style.borderTopStyle = "solid";
		if (right)
			selectedTD.style.borderRightStyle = "solid";
		if (bottom)
			selectedTD.style.borderBottomStyle = "solid";
	}
	hideFrame();
}

// Supprimer une cellule de la table
function delCell() {
	if (inCell()) {
		var selectedTD = null;
		setFocus();		
		eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
		while ((tag.tagName != "BODY") && (tag.tagName != "TABLE")) {
			if (tag.tagName == "TD")
				selectedTD	=	tag;
			tag = tag.parentElement;
		}
		
		if (tag.tagName == "TABLE") {
			for (i=0; i < tag.rows.length; i++)
			        for (j=0; j < tag.rows(i).cells.length; j++) 
            				if (tag.rows(i).cells(j) == selectedTD)
            					tag.rows(i).deleteCell(j);
		}
	}
}

// Ajouter une cellule de la table
function addCell() {
	if (inCell()) {
		var selectedTR = null;
		setFocus();		
		eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
		while ((tag.tagName != "BODY") && (tag.tagName != "TABLE")) {
			if (tag.tagName == "TR")
				selectedTR	=	tag;
			tag = tag.parentElement;
		}

		if (tag.tagName == "TABLE") {
			selectedTR.insertCell(-1);
		}
	}
}

// Ajouter une colonne en fin de table
function addCol() {
	if (inCell()) {
		var selectedTD = null;
		setFocus();		
		eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
		while ((tag.tagName != "BODY") && (tag.tagName != "TABLE"))
			tag = tag.parentElement;
		
		if (tag.tagName == "TABLE") {
			for (i=0; i < tag.rows.length; i++)
            			tag.rows(i).insertCell(tag.rows(i).cells.length);
		}
	}
}

// Ajouter une Ligne en bas de table
function addRow() {
	if (inCell()) {
		var selectedTD = null;
		setFocus();		
		eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
		while ((tag.tagName != "BODY") && (tag.tagName != "TABLE"))
			tag = tag.parentElement;
		
		if (tag.tagName == "TABLE") {
			maxCell = 0;
			for (i=0; i < tag.rows.length; i++)
				if (tag.rows(i).cells.length > maxCell)
					maxCell	= tag.rows(i).cells.length;
			tag.insertRow();
			for (i=0; i < maxCell; i++)
				tag.rows(tag.rows.length-1).insertCell(-1);
		}
	}
}

// Methodes pour choisir le style de cadre pour une cellule ou une image
function selFrameStyle() {
	/*document.styleSheets.edit.rules[7].style.left = 160;
	document.styleSheets.edit.rules[7].style.top = document.body.scrollTop + 50;
	document.styleSheets.edit.rules[7].style.display = "";*/
	
	document.getElementById("frameStyle").style.left = 160;
	document.getElementById("frameStyle").style.top = document.body.scrollTop + 50;
	document.getElementById("frameStyle").style.display = "";
}

function hideFrameStyle() {
	document.getElementById("frameStyle").style.display = "none";
}

function doFrameStyle(style) {
	if (isForm()) {
		if ((style == "solid") || (style == "dashed"))
			selectedForm.style.borderWidth = "1";
		else
			selectedForm.style.borderWidth = "4";
		
		if (selectedForm.style.borderRightStyle != "none")
			selectedForm.style.borderRightStyle = style;
		
		if (selectedForm.style.borderLeftStyle != "none")
			selectedForm.style.borderLeftStyle = style;
		
		if (selectedForm.style.borderTopStyle != "none")
			selectedForm.style.borderTopStyle = style;
		
		if (selectedForm.style.borderBottomStyle != "none")
			selectedForm.style.borderBottomStyle = style;
	}
	if (isImage()) {
		if ((style == "solid") || (style == "dashed"))
			selectedImage.style.borderWidth = "1";
		else
			selectedImage.style.borderWidth = "4";
		
		if (selectedImage.style.borderRightStyle != "none")
			selectedImage.style.borderRightStyle = style;
		
		if (selectedImage.style.borderLeftStyle != "none")
			selectedImage.style.borderLeftStyle = style;
		
		if (selectedImage.style.borderTopStyle != "none")
			selectedImage.style.borderTopStyle = style;
		
		if (selectedImage.style.borderBottomStyle != "none")
			selectedImage.style.borderBottomStyle = style;
	}

	if (inCell()) {
		if ((style == "solid") || (style == "dashed"))
			selectedTD.style.borderWidth = "1";
		else
			selectedTD.style.borderWidth = "4";
		
		if (selectedTD.style.borderRightStyle != "none")
			selectedTD.style.borderRightStyle = style;
		
		if (selectedTD.style.borderLeftStyle != "none")
			selectedTD.style.borderLeftStyle = style;
		
		if (selectedTD.style.borderTopStyle != "none")
			selectedTD.style.borderTopStyle = style;
		
		if (selectedTD.style.borderBottomStyle != "none")
			selectedTD.style.borderBottomStyle = style;
	}
	hideFrameStyle();
}

// Methode pour choisir la largeur du cadre pour une cellule ou une image
function doFrameWidth(width) {
	if (isForm()) 
		selectedForm.style.borderWidth = width;
		
	if (isImage()) 
		selectedImage.style.borderWidth = width;

	if (inCell())
		selectedTD.style.borderWidth = width;
}

// Methodes pour choisir la couleur du cadre pour une cellule ou une image
function selColor(x,y,m) {
	if (m=="setBackgroundColor") {
		eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
		var iClr	=	Laselection.queryCommandValue("BackColor");
	}
	if (m=="setForegroundColor") {
		eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
		var iClr	=	Laselection.queryCommandValue("ForeColor");
	}	

	mapalette	=	generateMap(m);
	
	document.getElementById("palette").innerHTML	= mapalette;
	document.getElementById("palette").style.left	= x;
	document.getElementById("palette").style.top	= document.body.scrollTop + y;
	document.getElementById("palette").style.display= "";
	
	if (iClr) {
		var codeR = (iClr & 0xFF).toString(16);
		var codeG = ((iClr & 0xFF00)>>8).toString(16);
		var codeB = ((iClr & 0xFF0000)>>16).toString(16);
		
		if (codeR.length <2)
			codeR	=	"0"+codeR;
		if (codeG.length <2)
			codeG	=	"0"+codeG;
		if (codeB.length <2)
			codeB	=	"0"+codeB;
		document.getElementById("codeColor").value = "#"+codeR+codeG+codeB;
		document.getElementById('previewZone').style.backgroundColor = document.getElementById("codeColor").value;
	}
	
}

function hideFrameColor() {
	document.getElementById("palette").style.display = "none";
}

function showFrameColor() {
	document.getElementById("palette").style.display = "";
}

function doFrameColor(color) {
	if (isForm()) {
		if (selectedForm.style.borderRightStyle != "none")
			selectedForm.style.borderRightColor = color;
		
		if (selectedForm.style.borderLeftStyle != "none")
			selectedForm.style.borderLeftColor = color;
		
		if (selectedForm.style.borderTopStyle != "none")
			selectedForm.style.borderTopColor = color;
		
		if (selectedForm.style.borderBottomStyle != "none")
			selectedForm.style.borderBottomColor = color;
	}
	
	if (isImage()) {
		if (selectedImage.style.borderRightStyle != "none")
			selectedImage.style.borderRightColor = color;
		
		if (selectedImage.style.borderLeftStyle != "none")
			selectedImage.style.borderLeftColor = color;
		
		if (selectedImage.style.borderTopStyle != "none")
			selectedImage.style.borderTopColor = color;
		
		if (selectedImage.style.borderBottomStyle != "none")
			selectedImage.style.borderBottomColor = color;
	}
	if (inCell()) {
		if (selectedTD.style.borderRightStyle != "none")
			selectedTD.style.borderRightColor = color;
		
		if (selectedTD.style.borderLeftStyle != "none")
			selectedTD.style.borderLeftColor = color;
		
		if (selectedTD.style.borderTopStyle != "none")
			selectedTD.style.borderTopColor = color;
		
		if (selectedTD.style.borderBottomStyle != "none")
			selectedTD.style.borderBottomColor = color;
	}
	hideFrameColor();
}

// Definir la couleur de fond
function setBackgroundColor(color) {
	if (isForm())
		selectedForm.style.backgroundColor = color;
	else 
		if (inCell())
			selectedTD.style.backgroundColor = color;
		else
			execCommand("BackColor",color);
	hideFrameColor();
}

// Definir la couleur de texte
function setForegroundColor(color) {
	if (isForm())
		selectedForm.style.color = color;
	else 
		execCommand("ForeColor",color);

	hideFrameColor();
}

// Justifier le texte
function doJustify(){
	if (!isJustify()) {
		eval("LaSelection=" + iframeName + ".document.selection.createRange();");
		LaSelection.expand("sentence");
		LaSelection.collapse();
		LaSelection.pasteHTML("<p align='justify'>");
		updateMenuState();
	}
}

// est-ce que le texte est Justifié
function isJustify(){
	eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
	if (tag) {
		while ((tag.tagName != "BODY")) {
			if ((tag.tagName != "BR") && (tag.tagName != "TABLE") && (tag.tagName != "TR") && (tag.tagName != "TBODY") && (tag.tagName != "IMG")) {
				// soit "align=justify", soit "style='...text-align:justify...'"
				if ((tag.getAttribute("align")) && (tag.getAttribute("align").toUpperCase().indexOf("JUSTIFY") >= 0))
					return true;
		
				if ((tag.getAttribute("style")) && (tag.style.textAlign.toUpperCase().indexOf("JUSTIFY") >= 0))
					return true;
			}
			tag = tag.parentElement;
		}
	}
	return false;
}

// Tabulation vers la droite
function addTab() {
	eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
	Laselection.execCommand("Indent");
}

// Tabulation inverse vers la gauche
function delTab() {
	eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
	Laselection.execCommand("Outdent");
}

// définir le style d'écriture de la sélection
function setFont(font) {
	if (isForm()) {
		selectedForm.style.fontFamily = font;
	} else {
		eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
		Laselection.execCommand("FontName",false,font);
	}
}

// définir le taille d'écriture de la sélection
function setFontSize(size) {
	if (isForm()) {
		selectedForm.style.fontSize = size;
	} else {
		eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
		if (Laselection.text.length == 0) {
			Laselection.expand("word");
		}
		Laselection.execCommand("FontSize",false,size);
	}
}

// e-dito 1.1.3 - 10/06/2006 - modifications bug changement de taille
/*function setFontSize(size) {
	if (isForm()) {
		selectedForm.style.fontSize = size;
	} else {
	
		eval("Laselection	=	" + iframeName + ".document.selection.createRange();");
		if (Laselection.text.length == 0) {
			Laselection.expand("word");
		}

		LeTexte		=	Laselection.htmlText;
		
		tag			=	"";
		if (LeTexte.toUpperCase().lastIndexOf("<FONT") != -1)	{
			LeTexte		=	LeTexte.substring(LeTexte.toUpperCase().lastIndexOf("<FONT"),LeTexte.toUpperCase().indexOf("</FONT>",LeTexte.toUpperCase().lastIndexOf("<FONT"))+7);
			
			// Retrouver le dernier Tag "<FONT ...>"
			tag = LeTexte.substring(LeTexte.toUpperCase().lastIndexOf("<FONT"),LeTexte.indexOf(">",LeTexte.toUpperCase().lastIndexOf("<FONT"))+1);
			
			// Un Style est déjà associé à ce Tag
			if (tag.toUpperCase().indexOf("STYLE=") != -1) {
				if (tag.toUpperCase().indexOf("FONT-SIZE") != -1){
					tag	=	tag.substring(0,tag.toUpperCase().indexOf("FONT-SIZE") + 11) + size + tag.substring(tag.indexOf("px"));
				} else {
					tag	=	tag.substring(0,tag.toUpperCase().indexOf("STYLE=") + 7) + "font-size:" + size + "px;" + tag.substring(tag.toUpperCase().indexOf("STYLE=") + 7);
				}
				
			} else {
				// Pas de Style associé à ce Tag, on l'ajoute dans la balise FONT
				//LeTexte	=	LeTexte.substring(LeTexte.indexOf(">",LeTexte.toUpperCase().lastIndexOf("<FONT"))+1);
				tag =	tag.substring(0,tag.length-1) + " STYLE=\'font-size:" + size + "px;\'>";
			}
			
			tag = LeTexte.substring(0,LeTexte.toUpperCase().lastIndexOf("<FONT") )
			+ tag + LeTexte.substring(LeTexte.indexOf(">",LeTexte.toUpperCase().lastIndexOf("<FONT"))+1);
			
			eval(iframeName + ".document.selection.clear();");
			Laselection.pasteHTML(tag);
			
		} else {
				tag	=	"<FONT STYLE=\'font-size:" + size + "px;\'>";
				eval(iframeName + ".document.selection.clear();");
				Laselection.pasteHTML(tag + LeTexte + "</FONT>");
		}
		
	}
}*/

// retrouver taille du texte
function getFontSize(){	
	eval("var tag = " + iframeName + ".document.selection.createRange().parentElement();");
	
	if (tag) {
		while (tag.tagName != "BODY") {
			if ((tag.getAttribute("style")) && (tag.style.fontSize))
				return tag.style.fontSize;
			tag = tag.parentElement;
		}
	}
	return 0;
}

function doAddLink(ID,TYPE) {
	left="";right="";
	LeTexte=linkArea.text;
	linkArea.pasteHTML(left+"<A HREF=\'http://sports.tf1.fr/index.cf	m?CO_ID="+ID+"\'class=noir>"+LeTexte+"</a>"+right);
}

// Mettre le focus dans la zone d'edition
function setFocus() {
	eval(iframeName + ".focus();");
}

// Passer du mode apercu aux code source et inversement
function swapToHtml() {
	Format="html";
	setFocus();
	eval(iframeName + ".document.body.innerHTML = " + iframeName + ".document.body.innerText;");
	//eval(iframeName + ".document.body.style = saveStyle;");
	eval("var s = " + iframeName + ".document.body.createTextRange();");
	s.collapse(false);
	s.select();
}

function swapToSource() {
  	eval("saveStyle = " + iframeName + ".document.body.style;");
	eval(iframeName + ".document.body.innerText = " + iframeName + ".document.body.innerHTML;");
	/*eval(iframeName + ".document.body.style.fontFamily = 'monospace';");
	eval(iframeName + ".document.body.style.fontSize = '10pt';");
	eval(iframeName + ".document.body.style.color = 'black';");
	eval(iframeName + ".document.body.style.backgroundColor = 'white';");*/
	Format="Text";
	setFocus();
	eval("var s = " + iframeName + ".document.body.createTextRange();");
	s.collapse(false);
	s.select();
}

function swapModes() {
	if (Format=="html") {
		// En mode texte, les menus doivent etre grise !
		for (countArgs=0; countArgs<swapModes.arguments.length;countArgs++){ 
			swapModes.arguments[countArgs].disableMenu();
			swapModes.arguments[countArgs].changeItemState("xsltswap", true);
			swapModes.arguments[countArgs].updateMenu();
		} 
		swapToSource();
	} else {
		for (countArgs=0; countArgs<swapModes.arguments.length;countArgs++){ 
			swapModes.arguments[countArgs].enableMenu();
		} 
		swapToHtml();
	}
}

// Initialisation de l'editeur
function initEditor() {
	if ((eval(iframeName + ".document.designMode") != 'On') && (eval(iframeName + ".document.designMode") != 'on')) {
		eval(iframeName + ".document.designMode='On';");
		setTimeout("swapToHtml()",1000);
	}
}

// Definir le code HTML du document à modifier
function pasteEditor(){
	eval(iframeName + ".document.body.innerHTML = leHidden;");
}

function testPosition(x,y) {
	var left = document.getElementById(divTable).style.left;
	if (left.indexOf("px") > 0)
		left	=	parseInt(left.substring(0,left.length-2));
	else
		left	=	parseInt(left);
	x = x - left;
	
	var top = document.getElementById(divTable).style.top;
	if (top.indexOf("px") > 0)
		top	=	parseInt(top.substring(0,top.length-2));
	else
		top	=	parseInt(top);
	// 1.1.9 : position fixe en desous du menu
	//y = y - top;
	y = y - 50;
	
	cols	=	Math.ceil(x/20);
	rows	=	Math.ceil(y/20);
	if (cols > 15)
		cols = 15;
	if (rows > 15)
		rows = 15;

	document.getElementById(divSelection).style.width = cols*20;
	document.getElementById(divSelection).style.height = rows*20;
	document.getElementById(divSelection).style.display = '';
	if (cols*20 >= 100) {
		document.getElementById(divTable).style.width = cols*20+6;
		document.getElementById(divBgTable).style.width = cols*20+6;
	}
	if (rows*20 >= 100) {
		document.getElementById(divTable).style.height = rows*20+6;
		document.getElementById(divBgTable).style.height = rows*20+6;
	}
}

// inserer une Table de la taille definie par l'utilisateur
function selectTableSize() {
	document.getElementById(divTable).style.display  = 'none';
	document.getElementById(divSelection).style.display = 'none';
	
	var html		=	"<TABLE BORDER='0' WIDTH='100%' CELLSPACING=1 CELLPADDING=0><TBODY>";
	for (y=0;y<rows;y++) {
		html		+=	"<TR>";
		for (x=0;x<cols;x++)
			html	+=	"<TD>&nbsp;</TD>";
		html		+=	"</TR>";
	}
	html			+=	"</TBODY></TABLE>";
	doInsertHTML(html);

}

// Editer les propriétés d'une table ou d'une cellule
function tablePropertie(language) {
	if (inCell()) {
		window.open("tableproperties.php?language=" + language + "&type=table","tableProperties","width=450, height=230");
	}

}

// Afficher les propriétés de l'image selectionnee
function imageProperties() {
	if (isImage()) {
		selImage(selectedImage);
	}
}

// Afficher les propriétés du bloc, de la liste de pages ou du portlet sélectionné
function objectProperties() {
	setFocus();
	eval ("var oControlRange = " + iframeName + ".document.selection.createRange();");
	if ((oControlRange.length>0) && (oControlRange(0).getAttribute("onmousedown"))) {
		//alert(oControlRange(0).tagName);
		var toDo = oControlRange(0).getAttribute("onmousedown");
		toDo = toDo.substr(7)
		eval(toDo);
		

	}
	//selectedImage =	oControlRange(i);
}

function pasteFromWord (html){
	html=html.replace(/<\/?SPAN[^>]*>/gi, "");
	html=html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
	html=html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3");
	html=html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
	html=html.replace(/<\\?\?xml[^>]*>/gi, "");
	html=html.replace(/<\/?\w+:[^>]*>/gi, "");
	html=html.replace(/&nbsp;/, " ");
	var re=new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi");
	html=html.replace(re, "<div$2</div>");
	setFocus();
	eval("var edit = " + iframeName + ".document.selection.createRange();");
	edit.collapse();
	edit.pasteHTML(html);
}

function GetClipboardHTML() {
	var oDiv=document.getElementById('___EditoHiddenDiv');
	if (!oDiv) {
		var oDiv=document.createElement('DIV');
		oDiv.id='___EditoHiddenDiv';
		oDiv.style.visibility='hidden';
		oDiv.style.overflow='hidden';
		oDiv.style.position='absolute';
		oDiv.style.width=1;
		oDiv.style.height=1;
		document.body.appendChild(oDiv);
	}
	oDiv.innerHTML='';
	var oTextRange=document.body.createTextRange();
	oTextRange.moveToElementText(oDiv);
	oTextRange.execCommand('Paste');
	var sData=oDiv.innerHTML;
	oDiv.innerHTML='';
	return sData;
}

