var isNav = navigator.appName.indexOf("Netscape") !=-1;var isN6 = ((isNav) && (document.getElementById));
var isMac = navigator.appVersion.indexOf("Macintosh") !=-1;
var isIE = document.all;
var isIEPC = ((isIE) && (!(isMac)))
var Egale = '=';

function OuvreFenetre(URL,NomControle,Largeur,Hauteur,AffScrollBars)
{
	if (AffScrollBars!="no") AffScrollBars='yes';
	Top = screen.height/2-Hauteur/2 
	Gauche = screen.width/2-Largeur/2
	var popup = window.open(URL, NomControle, "toolbar=no,status=no,menubar=no,scrollbars=" + AffScrollBars + ",resizable=no,directories=no,location=no,width=" + Largeur + ",height=" + Hauteur +",top=" + Top + ",left=" + Gauche)
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function HiLite(imgN,PathImage2,Extension)
{
		eval("document [imgN].src = \"/images/" + PathImage2 + imgN + "_" + Extension + ".gif\"");
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



ValeurMax=-1;

if (isN6){	h=".left";	v=".top";	dS="document.getElementById('";	sD="').style";
	appComp = "true";
	Hauteur = "').offsetHeight";
	ECRIRE = "').innerHTML=";
	VISIBLE = ".visibility='visible'";}else {	if (isNav)
	{		h=".left";		v=".top";
		dS="document.";		sD="";
		appComp = "true";
		Hauteur = ".document.height";		VISIBLE = ".visibility='show'";
	}	else	{
		h=".pixelLeft";		v=".pixelTop";
		dS="";		sD=".style";
		appComp = "true";
		Hauteur = ".offsetHeight";
		ECRIRE = ".innerHTML=";
		VISIBLE = ".visibility='visible'";	}}

function AfficheLayer(Layer,x,y)
{
	eval(dS+Layer+sD+v+Egale+y);
	eval(dS+Layer+sD+h+Egale+x);
}


function RTB_ClearMSWord(editor)
{
	editor.focus();
	
	//on vire tous les CSS
	var body = editor.document.body;
	
	for (var index = 0; index < body.all.length; index++)
	{
		tag = body.all[index];
		tag.removeAttribute("className","",0);
		tag.removeAttribute("style","",0);
	}

	// Regex based cleaning
	
	var html = editor.document.body.innerHTML;
	
	//gestion des tags ms-word
	html = html.replace(/<o:p>&nbsp;<\/o:p>/gi, "");
	html = html.replace(/<st1:.*?>/gi, "");


	html = html.replace(/<(\/)?((DIV)|(SPAN)|(O:P)|(FONT))( (([^>])+)>|>)/gi, "");

	//gestion des paragraphes
	html = html.replace(/<P>(&nbsp;)*<\/P>/gi, "");
		
	//gestion des entêtes
	/*html = html.replace(/<H(1|2)( (([^>])+)>|>)/gi, "<p><b>");
	html = html.replace(/<H(3|4|5|6)( (([^>])+)>|>)/gi, "<p><b>");*/
	html = html.replace(/<H(1|2|3|4|5|6)( (([^>])+)>|>)/gi, "<p><b>");
	html = html.replace(/<\/H(1|2|3|4|5|6)( (([^>])+)>|>)/gi, "</b></p>");
	
	//gestion des tags IE
	html = html.replace(/<(\/)?(STRONG)( (([^>])+)>|>)/gi, "<$1B>");
	html = html.replace(/<(\/)?(EM)( (([^>])+)>|>)/gi, "<$1I>");
	
	//gestion des bullets
	html = html.replace(/<p>(·|Ø|§|-)(&nbsp;)*(([^>])+)<\/p>/gi, "<li>$3</li>");	
	
	//gestion des italiques inutiles
	html = html.replace(/<U>(&nbsp;)*<\/U>/gi, "");
	
	//gestion des paragraphes inutiles créés 
	//lors des remplacements des headers ou autres
	html = html.replace(/<P>(<[^>]*>)*(&nbsp;)*(<[^>]*>)*<\/P>/gi,"");
	
	editor.document.body.innerHTML = html;
										
}

