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 = '=';
var bo_several_checked=false;

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 Desactive_Bouton(theform,btn,texte_replace)
{
	if (document.all || document.getElementById)
	{
		btn.disabled = true;
		
		
		if (document.all)
		{
			if (eval(theform.id + ".bo_form_soumis"))
				{eval(theform.id + ".bo_form_soumis.value='true';");}
		}
		else
		{
			if (document.getElementById('bo_form_soumis'))
			{
				document.getElementById('bo_form_soumis').value='true';
			}
		}
		theform.submit();
	}
}

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'";	Unite_Pixel = "px";}else {	if (isNav)
	{		h=".left";		v=".top";
		dS="document.";		sD="";
		appComp = "true";
		Hauteur = ".document.height";		VISIBLE = ".visibility='show'";
		Unite_Pixel = "px";
	}	else	{
		h=".pixelLeft";		v=".pixelTop";
		dS="";		sD=".style";
		appComp = "true";
		Hauteur = ".offsetHeight";
		ECRIRE = ".innerHTML=";
		VISIBLE = ".visibility='visible'";		Unite_Pixel = "";	}}

function AfficheLayer(Layer,x,y)
{
	eval(dS+Layer+sD+v+Egale+y);
	eval(dS+Layer+sD+h+Egale+x);
}

function efface(text_defaut,ctrl)
{
	
	if (text_defaut.value==ctrl.value)
	{
		ctrl.value='';
		ctrl.focus();
	}
}

function RTB_ClearMSWord(editor)
{
	editor = editor.contentWindow ? editor.contentWindow : editor;
	
	editor.focus();

	//on vire tous les CSS
	var body = editor.document.body //? editor.document.body ;
	var TagsArray = body.all ? body.all : body.getElementsByTagName("*");
	
	for (var index = 0; index < TagsArray.length; index++)
	{
		tag = TagsArray[index];
		tag.removeAttribute("className","",0);
		tag.removeAttribute("class","",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, "");
	
	//gestion des tags mozilla
	html = html.replace(/\<!--.+--\>/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|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, "<ul><li>$3</li></ul>");	
	html = html.replace(/<\/ul>\s*<ul>/gi, "");	
	
	
	//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;
										
}

function Mozilla_OnPaste_Handler(e,editor)
{
	var oEvent = (window.event) ? window.event : e;
	var nKeyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0;
	var sChar = String.fromCharCode(nKeyCode).toLowerCase();
	var bCtrlPressed = (oEvent.ctrlKey) ? oEvent.ctrlKey : oEvent.modifiers & 2 > 0;
	
	if (bCtrlPressed && sChar=="v")
	{
		setTimeout("RTB_ClearMSWord(editor);",50);
	}
	
}								

function checkall(ctrl)
{
	var bo_checked = ctrl.checked ? true : false;
	var field = document.forms[0].chk_commande;
	if (typeof(field[0])!="undefined")
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = bo_checked;
		}
	}
	else
	{
		field.checked = bo_checked;
	}
}

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;
}


/* fonctions qui aident dans la vie */
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

