//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
// SCRIPTS JAVASCRIPT DE BASE
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------

var tinyMce = false;
var hideMask = true;
var loadBoxOver = false;
var loadSlider = false;
var loadRgbPicker = false;
var floatWindow = true;
var cursorPosition = false;
var sliderFactorValue = 1;
var sliderUpdateCheck = false;
var browserName = navigator.appName;
var browserVersion = navigator.appVersion.substring(0, 3);
var ns40 = (browserName == 'Netscape' && browserVersion >= '3.0' && browserVersion < '4.8' ) ? 1:0;
var ns6 = (browserName == 'Netscape' && browserVersion > '4.7' ) ? 1:0;
var ie4 = (browserName == 'Microsoft Internet Explorer' && browserVersion >= '4.0' ) ? 1:0;
var ie = (browserName == 'Microsoft Internet Explorer') ? 1:0;

var tabButton = new Array();	// Table des boutons
var indButton = 0;
var debugPopup = '';

var mainContentBg = '';

// Désactivation des fonctions de sélection et de menus contextuels ----------------------------
function disableselect(e){
	if(!localDebug)			return false;
	else					return true;
}
function reEnable(){
	return true;
}

//if IE4+
if(!localDebug)
{
	document.onselectstart=new Function ("return false");
	document.oncontextmenu=new Function ("return false");
}

function roadster(evt) 
{
	if (!ie)
	{
		if(localDebug)			return false;
		else
		if(evt.which != 3) 		return true;
	}
	if(!localDebug)				return false;
	else						return true;
}
function trap() 
{
 if(document.images)
 {
   if(!ie)
   {
     for(i=0;i<document.images.length;i++)
	 {
       document.images[i].onmousedown = roadster;
       document.images[i].oncontextmenu = roadster;
	 }
   }
   else
   {
     for(i=0;i<document.images.length;i++)
       document.images[i].oncontextmenu = roadster;
   }
 }
}

// Variable servant à contrôler la position basse du menu flottant ------------------------
var footerTopImgTop 		= 0;
function getFooterTopImgTop() {
	footerTopImgTop 		= document.getElementById('footer').offsetTop;
	//alert("footerTopImgTop="+footerTopImgTop);
}

// ----------------------------------------------------------------------------------------------
function MM_setTextOfTextfield(objName,x,newText) 
{ //v3.0
  var obj = MM_findObj(objName); 
  if (obj) obj.value = newText;
}
function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
    	d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
  	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}

function MM_showHideLayers() 
{ //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		if ((obj=MM_findObj(args[i]))!=null) 
		{ 
			v=args[i+2];
			if (obj.style) 
			{ 
				obj=obj.style; 
				v=(v=='show')?'visible':(v='hide')?'hidden':v; 
			}
			obj.visibility=v; 
		}
	}
}

function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

// Test appartenance d'un nombre à une rangée -----------------------------------------
function inRange(inputStr, lo, hi)
{
	num = parseInt(inputStr, 10);
	if (num < lo || num > hi) { return false; }
	return true;
}

function SetCookie(name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;

	var expireTime=(argc > 2) ? argv[2] : null;
	var today = new Date();
	var expires = new Date();
 	if (expireTime==null || expireTime==0) expireTime=1;
	expires.setTime(today.getTime() + 3600000*24*expireTime);

	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		("; expires="+expires.toUTCString())+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) {
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
                        return getCookieVal (j);
                i=document.cookie.indexOf(" ",i)+1;
                        if (i==0) break;}
	return null;
}

function toolsOff(layerName) {
  if(layerName == 'tools_help_01') { MM_showHideLayers('tools_help_01','','hide'); }
  if(layerName == 'tools_help_02') { MM_showHideLayers('tools_help_02','','hide'); }
  if(layerName == 'tools_help_03') { MM_showHideLayers('tools_help_03','','hide'); }
  if(layerName == 'tools_help_04') { MM_showHideLayers('tools_help_04','','hide'); }
  if(layerName == 'tools_help_05') { MM_showHideLayers('tools_help_05','','hide'); }
  if(layerName == 'tools_help_06') { MM_showHideLayers('tools_help_06','','hide'); }
}

var helpWindow = '';
function popupHelp(prog, field)
{
	var url = "/admin/php/help_onLine.php#"+prog+"__"+field;
	if (!helpWindow.closed && helpWindow.location)
	{
		helpWindow.location.href = url;
	}
	else
	{
		helpWindow=window.open(url,'name','height=400,width=500,top=10,left=10,scrollbars=yes');
		if (!helpWindow.opener) helpWindow.opener = self;
	}
	if (window.focus) {helpWindow.focus()}
	return false;
}

function imageTitle(str)
{
	var titleStr    = '';
    if(ie)
		titleStr	= str;
	else
		titleStr	= "cssbody=[boxOverBodyAlone] header=[] body=["+str+"] delay=[0] fade=[off]";

	return titleStr;
}

function checkOnlineEditFields()
{
	if(self.opener.document.forms['onlineEditFields'].ole_refresh.value == "1")
	{
	    alert("ole_refresh = 1");
		self.opener.document.forms['onlineEditFields'].ole_refresh.value == "0";
		window.history.go(0);
	}
}

// Gestion des boutons : Insertion dans la page ---------------------------------------------------------
function doNothing(e)
{
	return false;
}
function toolsButton(bName, bFunction, bProp1, bProp2, bTitle, bSrc, bOver)
{
//    addDebug("toolsButton");
	var argv		= toolsButton.arguments;
	var argc		= toolsButton.arguments.length;
	var bTypeButton	= (argc > 5) ? argv[5] : null;
	var bSrc		= (argc > 6) ? argv[6] : null;
	var bSrcOver	= (argc > 7) ? argv[7] : null;

	var i;
	var bObj;
	var bFound		= false;
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bFound										= true;
			this.id										= bObj.id;
			this.nom									= bObj.nom;
			this.fonction								= bObj.fonction;
			this.fonctionActive							= bObj.fonctionActive;
			if(bObj.prop1 != bProp1)	bObj.prop1		= bProp1;
			this.prop1									= bObj.prop1;
			if(bObj.prop2 != bProp2)	bObj.prop2		= bProp2;
			this.prop2									= bObj.prop2;
			this.action     							= bObj.action;
			this.typeButton    							= bObj.typeButton;
			this.title	    							= bObj.title;
			this.state	    							= bObj.state;
			this.src	    							= bObj.src;
			this.srcOver    							= bObj.srcOver;
			//addDebug("toolsButton - bouton "+bObj.id+" trouvé - prop1="+bObj.prop1+" - prop2="+bObj.prop2+" - fonction="+bObj.fonction);
		}
	}
	if(!bFound)
	{
		//addDebug("toolsButton - bouton "+bName+" créé !");
		this.id											= bName;
		this.nom										= bName;
		this.fonction									= bFunction;
		this.fonctionActive								= bFunction;
		this.prop1										= bProp1;
		this.prop2										= bProp2;
		this.action     								= 'on';
		this.typeButton    								= bTypeButton;
		this.title	    								= bTitle;
		this.state	    								= "ACTIVE";
		this.src	    								= bSrc;
		if(bOver)
		{
			if(this.src.indexOf('_off')!=-1)
				this.srcOver 							= this.src.replace('_off', '_over');
			else
				this.srcOver 							= this.src.replace('_on', '_over');
		}
		else
		    this.srcOver                                = '';
		tabButton [indButton] 							= this;
		indButton++;
		//addDebug("toolsButton - bouton "+bName+" - fonction="+this.fonction+", title="+bTitle);
		//addDebug("toolsButton - bouton "+bName+" créé - prop1="+bProp1+" - prop2="+bProp2+" - fonction="+bFunction);
	}
	
	return this;
}
function changeButtonSrc(bName, bNewSource)
{
	var i;
	var bObj;
	var bFound		= false;
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bFound										= true;
			bObj.src	    							= bNewSource;
			document.getElementById(bObj.id).src        = bNewSource;
			//addDebug("changeButtonSrc - bouton "+bObj.id+", bNewSource="+bNewSource);
		}
	}

	return;
}
function changeButtonProp(bName, bProp1, bProp2)
{
    // addDebug("changeButtonProp - bOldName="+bOldName+" - bNewName="+bNewName+" - bProp1="+bProp1+" - bProp2="+bProp2);

	var i;
	var bObj;
	var bFound		= false;
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bFound										= true;
			bObj.prop1									= bProp1;
			bObj.prop2									= bProp2;
			tabButton [i]								= bObj;
			//addDebug("changeButtonProp - bouton "+bName+" trouvé - prop1="+bObj.prop1+" - prop2="+bObj.prop2);
		}
	}
}
function buttonMouseOut(bImgId)
{
	var i;
	var bObj;
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bImgId)
		{
			document.getElementById(bImgId).src 		= bObj.src;
//			addDebug("buttonMouseOut - bouton "+bObj.id+", bObj.src="+bObj.src);
		}
	}
}
function desactiveButton(bName)
{
//	if(ie)  return false;
	addDebug("desactiveButton - bouton "+bName);
	var i;
	var bObj, bFunction, bReturn, newSrc;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bFunction									= bObj.fonction;
			//addDebug("desactiveButton - bouton "+bName+" - fonction="+bObj.fonction);
			document.getElementById(bName).style.cursor	= "default";
			if(bObj.typeButton=="PUSH")
			{
				newSrc									= document.getElementById(bName).src.replace('_unpushed', '_off');
				newSrc									= newSrc.replace('_pushed', '_off');
			}
			else
				newSrc									= document.getElementById(bName).src.replace('_on', '_off');
			document.getElementById(bName).src			= newSrc;
			document.getElementById(bName).title        = '';
			document.getElementById(bName).boxOverTitle = '';
			eval("removeEvent(document.getElementById(bName), 'click', "+bFunction+")");
			bObj.action     							= 'off';
			bObj.state	     							= 'INACTIVE';
		}
	}
	return false;
}
function activeButton(bName)
{
//	if(ie)  return false;
	var argv					= activeButton.arguments;
	var argc					= activeButton.arguments.length;
	var newStatus				= (argc > 1) ? argv[1] : '';
	var newTitle				= (argc > 2) ? argv[2] : '';

	//addDebug("activeButton - bouton "+bName+" - newTitle="+newTitle+", newStatus="+newStatus);

	var i;
	var bObj, bFunction, bReturn, newSrc;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bFunction									= bObj.fonction;
			document.getElementById(bName).style.cursor	= "pointer";
			if(bObj.typeButton=="PUSH")
				if(newStatus == "PUSHED")
				{
					newSrc								= document.getElementById(bName).src.replace('_off', '_pushed');
					newSrc								= newSrc.replace('_unpushed', '_pushed');
				}
				else
				{
					newSrc								= document.getElementById(bName).src.replace('_off', '_unpushed');
					newSrc								= newSrc.replace('_pushed', '_unpushed');
				}
			else
				newSrc									= document.getElementById(bName).src.replace('_off', '_on');
			document.getElementById(bName).src			= newSrc;
			eval("addEvent(document.getElementById(bName), 'click', "+bFunction+")");
			bObj.action     							= 'on';
			bObj.fonction                               = bObj.fonctionActive;
			if(newTitle!='')            bObj.title      = newTitle;
			document.getElementById(bName).boxOverTitle = bObj.title;
			document.getElementById(bName).title        = bObj.title;
			//addDebug("activeButton - bouton "+bName+" - fonction="+bObj.fonction+", title="+document.getElementById(bName).title+", boxOverTitle="+document.getElementById(bName).boxOverTitle);
			bObj.state	     							= 'ACTIVE';
		}
	}
	return false;
}
function switchButton(bName, bState)
{
//	addDebug("switchButton - bouton "+bName);
	var i;
	var bObj, bFunction, bReturn, newSrc;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			if(bState == 'on' || bState == 'pushed')
			{
				if(bObj.typeButton=="PUSH")
					newSrc									= document.getElementById(bName).src.replace('_pushed', '_unpushed');
				else
					newSrc									= document.getElementById(bName).src.replace('_on', '_off');
				document.getElementById(bName).src			= newSrc;
				bObj.action     							= 'off';
			}
			else
			{
				if(bObj.typeButton=="PUSH")
					newSrc									= document.getElementById(bName).src.replace('_unpushed', '_pushed');
				else
					newSrc									= document.getElementById(bName).src.replace('_off', '_on');
				document.getElementById(bName).src			= newSrc;
				bObj.action     							= 'on';
			}
		}
	}
	return false;
}
function supButton(bName)
{
	var i;
	var bObj, bFunction, bReturn;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
		{
			bObj.fonction								= '';
			bObj.id										= '';
			bObj.action     							= '';
			bObj.nom									= '';
			bObj.prop1									= '';
			bObj.prop2									= '';
		}
	}
	return false;
}
function isActiveButton(bName)
{
//	if(ie)  return false;
//	addDebug("activeButton - bouton "+bName);
	var i;
	var bObj;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                							= tabButton [i];
		if(bObj.id == bName)
			if(bObj.state=='INACTIVE')					return false;
			else										return true;
	}
	return false;
}
function desactiveEveryButtons()
{
//	if(ie)  return false;
	var i;
	var bName, bFunction, bObj, bReturn;
	// Désactivation de tous les boutons mémorisés en table -----------------------------
	for(var i=0; i<indButton; i++)
	{
		bObj                = tabButton [i];
		bName				= bObj.id;
		bFunction			= bObj.fonction;
		if(bObj.action == 'on') {
			document.getElementById(bName).style.cursor = "default";
			eval("removeEvent(document.getElementById(bName), 'click', "+bFunction+")");
			bObj.action     							= 'off';
			bObj.fonction                               = bObj.fonctionActive;
			bObj.state	     							= 'INACTIVE';
		}
	}
	return false;
}
function activeEveryButtons()
{
//	if(ie)  return false;
	var i;
	var bName, bFunction, bObj;
	// Réactivation de tous les boutons mémorisés en table -----------------------------
	for(i=0; i<indButton; i++)
	{
		bObj                = tabButton [i];
		bName				= bObj.id;
		bFunction			= bObj.fonction;
		if(bObj.action == 'off') {
			document.getElementById(bName).style.cursor = "pointer";
			eval("addEvent(document.getElementById(bName), 'click', "+bFunction+")");
			bObj.action     = 'on';
			bObj.state	    = 'ACTIVE';
		}
	}
    return false;
}
function addButton(bName, bImg, bFunction, bTitle)
{
	var argv		= addButton.arguments;
	var argc		= addButton.arguments.length;

	var bSource 	= (argc > 4) ? argv[4] : null;
	var bProp1		= (argc > 5) ? argv[5] : null;
	var bProp2		= (argc > 6) ? argv[6] : null;
	var bReadOnly	= (argc > 7) ? argv[7] : null;
	var bTypeButton	= (argc > 8) ? argv[8] : null;
	var bWidth		= (argc > 9) ? argv[9] : "28";
	var bHeight		= (argc > 10) ? argv[10] : "28";
	var bOver		= (argc > 11) ? argv[11] : false;

	//addDebug("addButton - bouton "+bName+"-bProp1="+bProp1+"-bProp2="+bProp2);

	var styleStr 	= 'cursor: pointer;';
	if(bFunction=="dummyFunction" || bReadOnly=="readonly")
        styleStr 		= 'cursor: default;';
	if(ie) {
		styleStr 		= 'cursor: pointer; position: relative; left: 10px;';
		if(bFunction=="dummyFunction" || bReadOnly=="readonly")
    	    styleStr 	= 'cursor: default; position: relative; left: 10px;';
	}

	document.write('<div id="'+bName+'_div" style="text-align: center; position: relative;" class="IEDiv">');
	var onClickFunc = '';
	if(ie && bFunction)
	{
	    onClickFunc = 'onClick="'+bFunction+'(window.event); return false;" ';
	}
	if(bSource)
	{
		if(bOver)
		{
			var srcOver 	= '';
			if(bSource.indexOf('_off')!=-1)
				srcOver 	= bSource.replace('_off', '_over');
			else
				srcOver 	= bSource.replace('_on', '_over');
		    var onOver  	= ' onmouseover="this.src=\''+srcOver+'\'" onmouseout="buttonMouseOut(\''+bName+'\')"';
			//addDebug("addButton - bouton "+bName+"-bSource="+bSource+"-srcOver="+srcOver);
		}
		else
		    var onOver  	= '';
	    if(bReadOnly!="readonly")
	    {
			document.write('<img id="'+bName+'" src="'+bSource+'" width="'+bWidth+'" height="'+bHeight+'" border="0" alt="image" title="'+imageTitle(bTitle)+'" style="'+styleStr+'" '+onClickFunc+' '+bReadOnly+' '+onOver+' class="pngfix" />');
			//addDebug('<img id="'+bName+'" src="'+bSource+'" width="'+bWidth+'" height="'+bHeight+'" border="0" alt="image" title="'+imageTitle(bTitle)+'" style="'+styleStr+'" '+onClickFunc+' '+bReadOnly+' '+onOver+'/>');
		}
		else
			document.write('<img id="'+bName+'" src="'+bSource+'" width="'+bWidth+'" height="'+bHeight+'" border="0" alt="image" title="" style="'+styleStr+'" '+bReadOnly+' '+onOver+' class="pngfix" />');
	}
	else
	    if(bReadOnly!="readonly")
			document.write('<img id="'+bName+'" src="/glob/img/but/'+bImg+'.png" width="'+bWidth+'" height="'+bHeight+'" border="0" alt="image" title="'+imageTitle(bTitle)+'" style="'+styleStr+'" '+onClickFunc+' '+bReadOnly+' class="pngfix" />');
		else
			document.write('<img id="'+bName+'" src="/glob/img/but/'+bImg+'.png" width="'+bWidth+'" height="'+bHeight+'" border="0" alt="image" title="" style="'+styleStr+'" '+bReadOnly+' class="pngfix" />');

	if(bFunction && !ie)
		eval("addEvent(document.getElementById(bName), 'click', "+bFunction+")");

	document.write('</div>');

	var bObj                = '';
	bTitle                  = imageTitle(bTitle);
	bObj 					= new toolsButton(bName, bFunction, bProp1, bProp2, bTitle, bTypeButton, bSource, bOver);
}

// Largeur et hauteur d'une fenêtre -------------------------------------------------------------------
function windowsWidth()
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
function windowsHeight()
{
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function windowsScrollTop()
{
  var scrolledDown = 0;
  if( typeof( window.scrollY ) == 'number' ) {
    //Non-IE
    scrolledDown = window.scrollY;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    scrolledDown = document.body.parentNode.scrollTop;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    scrolledDown = document.body.scrollTop;
  }
  return scrolledDown;
}

// Affichage d'un objet ---------------------------------------------------------------------------
function displayObject(id) {
	document.getElementById(id).style.visibility='visible';
}
function hideObject(id) {
	document.getElementById(id).style.visibility='hidden';
}
// Gestion de la communication AJAX : Création d'un objet HTTP ------------------------------------
function getHTTPObject() {
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       xmlhttp = false;
      }
     }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
    }
    if(!xmlhttp) alert('Impossible de créer une instance XMLHttpRequest avec ce navigateur !');
    return xmlhttp;
}

//***Cross browser attach event function. For 'evt' pass a string value with the leading "on" omitted
function addEvent(obj,evt,fnc){
//	alert("addEvent");
	var useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	}
	else
		return true;
//		return obj.attachEvent("on"+evt,fnc);
}

function removeEvent(obj,evt,fnc)
{
	var useCapture=false;
	if (obj.removeEventListener){
		obj.removeEventListener(evt,fnc,useCapture);
		return true;
	}
	else
		return true;
//		return obj.detachEvent("on"+evt,fnc);
}

function speedSwitch(speedVal, url)
{
	var today 	= new Date();
	var timeExpire 	= new Date();
	var nDays	= 365;
 	timeExpire.setTime(today.getTime() + (3600000*24*nDays));

 	if(speedVal=="fast")
 	{
		SetCookie('mi_speed','slow',timeExpire,'/');
	}
	else
 	{
		SetCookie('mi_speed','fast',timeExpire,'/');
	}

	return false;
}


//-- Explosion / implosion de tables ------------------------------
function explode(theSep, theString)
{
	var m					= 0;
	var theTable            = new Array();
	var element             = '';
	for(var i=0; i<theString.length; i++)
	{
		if(theString.substr(i, 1) == theSep)
		{
			if(element)
			{
				theTable[m]			= element;
				element				= '';
				m++;
			}
		}
		else
			element			    	= element+theString.substr(i, 1);
	}
	if(element)
	{
		theTable[m]					= element;
	}

	return theTable;
}
function implode(theSep, theTable)
{
	var m					= 0;
	var theString           = '';
	var element             = '';
	for(var i=0; i<theTable.length; i++)
	{
	    if(theTable[i] != '')
	    {
			if(i>0)	theString	= theString+"-"+theTable[i];
			else    theString   = theTable[i];
		}
	}
	return theString;
}

//-- Formattage de zones numériques ------------------------------------
function numFormat(numVal, numLen)
{
	var numChar             = numVal.toString();
	var numReturn           = '';
	for(var i=1; i<=numLen; i++)
	    numReturn           = numReturn + "0";
	    
	if(numChar.length < numLen)
    	numReturn			= numReturn.substr(0, numLen-numChar.length) + numChar;
	else
	    numReturn           = numChar;
	    
	return numReturn;
}

function isset(varname)  {
	if(typeof(window[varname]) != "undefined") 
		return true;
	else 
		return false;
}

//-- Debug -------------------------------------------------------------------------------------------
var debugPopup = '';
function addDebug(str)
{
	if(debugActive) {
		if(isObject(debugPopup.document.getElementById("debugField")))
		{
			var popupText = debugPopup.document.getElementById("debugField");
			popupText.innerHTML = popupText.innerHTML + str + "<br />";
		}
	}
}

if(debugActive) {
	debugPopup = window.open("/jsdebug.html", "mi_debug", "width=450,height=800,top=50,left=50,scrollbars=yes,status,resizable");
	window.self.focus();
}


function convertAccent(str)
{
	str			= str.replace("é", "e");
	str			= str.replace("è", "e");
	str			= str.replace("ê", "e");
	str			= str.replace("ë", "e");
	str			= str.replace("à", "a");
	str			= str.replace("ù", "u");
	str			= str.replace("û", "u");
	str			= str.replace("ô", "o");
	str			= str.replace("î", "i");
	str			= str.replace("ï", "i");
	str			= str.replace("ç", "c");
	
	return str;
}

//-- Gestion de l'affichage des messages d'erreur et d'information -------------------------------------------
var global_focusedField = '';
var glob_redirect 		= '';
function dialMsgDisplay(titre, text)
{
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	if(!ie7)
	{
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
	
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo('slow',0.8);	
	}
	
	document.getElementById("dialMsgDivHeader").innerHTML 	= titre;
	document.getElementById("dialMsgDivBody").innerHTML 	= text+"<br /><br /><br />";
	
	var scroll 												= getScrollXY();
	var top 												= scroll[1]+100;

	document.getElementById("dialMsgDiv").style.top 		= top+"px";
	document.getElementById("dialMsgDiv").style.display 	= "block";
	document.getElementById("dialMsgDiv").style.visibility = "visible";
}
function dialMsgHide()
{
	document.getElementById("dialMsgDiv").style.display 	= "none";
	document.getElementById("dialMsgDiv").style.visibility = "hidden";
	
	$('#mask').hide();
}
function confirmMsgDisplay(titre, text)
{
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	
	//transition effect		
	$('#mask').fadeIn(1000);	
	$('#mask').fadeTo('slow',0.8);	

	document.getElementById("confirmMsgDivHeader").innerHTML 	= titre;
	document.getElementById("confirmMsgDivBody").innerHTML 	= text+"<br /><br /><br />";
	
	var scroll 												= getScrollXY();
	var top 												= scroll[1]+100;

	document.getElementById("confirmMsgDiv").style.top 		= top+"px";
	document.getElementById("confirmMsgDiv").style.display 	= "block";
	document.getElementById("confirmMsgDiv").style.visibility = "visible";
}
function confirmMsgHide()
{
	document.getElementById("confirmMsgDiv").style.display 	= "none";
	document.getElementById("confirmMsgDiv").style.visibility = "hidden";
	
	$('#mask').hide();
}
function errorMsgDisplay(titre, text)
{
	var argv												= errorMsgDisplay.arguments;
	var argc												= errorMsgDisplay.arguments.length;

	var focusedField										= (argc > 2) ? argv[2] : null;
	var redirect											= (argc > 3) ? argv[3] : null;
	glob_redirect											= redirect;

	//transition effect	
	if(!ie7)
	{
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
	
		$('#mask').fadeIn(100);	
		$('#mask').fadeTo('slow',0.8);	
	}	

	document.getElementById("errorMsgDivHeader").innerHTML 	= titre;
	document.getElementById("errorMsgDivBody").innerHTML 	= text;
	
	var scroll 												= getScrollXY();
	var top 												= scroll[1]+100;

	document.getElementById("errorMsgDiv").style.top 		= top+"px";
	document.getElementById("errorMsgDiv").style.display 	= "block";
	document.getElementById("errorMsgDiv").style.visibility = "visible";
	
	global_focusedField										= focusedField;
}

function errorMsgHide()
{
	document.getElementById("errorMsgDiv").style.display 	= "none";
	document.getElementById("errorMsgDiv").style.visibility = "hidden";
	
	if(hideMask) $('#mask').hide();

	if(global_focusedField)
		global_focusedField.focus();		
	global_focusedField										= '';

	if(glob_redirect)
		document.location.href 								= glob_redirect;
	glob_redirect											= '';
}
//-- Gestion de l'image d'arrière-plan du contenu principal --------------------------------------------------
function mainContentBgChange()
{
	if(mainContentBg != '')
	{
		document.getElementById('mainContent').style.backgroundImage = "url('/glob/img/bg/bg_maincontent_"+mainContentBg+".gif')";
	}
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function isFunction(o) {
	return ('function' == typeof o);
}
function isObject(o) {
	return ((o && 'object' == typeof o) || isFunction(o));
}
function isset() {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FremyCompany
    // +   improved by: Onno Marsman
    // *     example 1: isset( undefined, true);
    // *     returns 1: false
    // *     example 2: isset( 'Kevin van Zonneveld' );
    // *     returns 2: true
   
    var a=arguments; var l=a.length; var i=0;
   
    if (l==0) {
        throw new Error('Empty isset');
    }
   
    while (i!=l) {
        if (typeof(a[i])=='undefined' || a[i]===null) {
            return false;
        } else {
            i++;
        }
    }
    return true;
}
// Gestion des erreurs dans les formulaires -----------------------------------------------------------------
var tabFld				= new Array();
var tabFldClass			= new Array();
var iFld				= 0;
function putFieldInError(fld)
{
	addDebug("putFieldInError fld="+fld);
	var argv												= putFieldInError.arguments;
	var argc												= putFieldInError.arguments.length;

	var err													= (argc > 1) ? argv[1] : null;

	if(fld)
	{
		var theField			= fld;
		tabFld [iFld]			= theField;
		tabFldClass [iFld]		= document.getElementById(theField).className;
		iFld++;
		document.getElementById(theField).className = "inputFieldInError";
		document.getElementById(theField).focus();
	}

	if(err)
	{
		var theRow				= theField+"_ERROR_Row";
		document.getElementById(theRow).className = "displayErrorMsg";
	
		var theCell				= theField+"_ERROR_Cell";
		document.getElementById(theCell).innerHTML = err;
	}
	return;
}
function putLittleFieldInError(fld)
{
	addDebug("putLittleFieldInError fld="+fld);
	var argv												= putLittleFieldInError.arguments;
	var argc												= putLittleFieldInError.arguments.length;

	var err													= (argc > 1) ? argv[1] : null;

	if(fld)
	{
		var theField			= fld;
		tabFld [iFld]			= theField;
		tabFldClass [iFld]		= document.getElementById(theField).className;
		iFld++;
		document.getElementById(theField).className = "inputLittleFieldInError";
		document.getElementById(theField).focus();
	}

	if(err)
	{
		var theRow				= theField+"_ERROR_Row";
		document.getElementById(theRow).className = "displayErrorMsg";
	
		var theCell				= theField+"_ERROR_Cell";
		document.getElementById(theCell).innerHTML = err;
	}
	return;
}
function putLineFieldInError(fld)
{
	addDebug("putLineFieldInError fld="+fld);
	var argv												= putLineFieldInError.arguments;
	var argc												= putLineFieldInError.arguments.length;

	var err													= (argc > 1) ? argv[1] : null;

	if(fld)
	{
		var theField			= fld;
		document.getElementById(theField).className = "inputLittleFieldInError";
		document.getElementById(theField).focus();
	}

	if(err)
	{
		errorMsgDisplay(str242, err, document.getElementById(fld));
	}
	return;
}
function putTextareaFieldInError(fld)
{
	addDebug("putTextareaFieldInError fld="+fld);
	var argv												= putTextareaFieldInError.arguments;
	var argc												= putTextareaFieldInError.arguments.length;

	var err													= (argc > 1) ? argv[1] : null;

	if(fld)
	{
		var theField			= fld;
		tabFld [iFld]			= theField;
		tabFldClass [iFld]		= document.getElementById(theField).className;
		iFld++;
		document.getElementById(theField).className = "textareaFieldInError";
		document.getElementById(theField).focus();
	}

	if(err)
	{
		var theRow				= theField+"_ERROR_Row";
		document.getElementById(theRow).className = "displayErrorMsg";
	
		var theCell				= theField+"_ERROR_Cell";
		document.getElementById(theCell).innerHTML = err;
	}
	return;
}
function restoreField(i)
{
	addDebug("restoreField i="+i+", tabFld[i]="+tabFld[i]);
	document.getElementById(tabFld [i]).className = tabFldClass [i];
	var theRow				= tabFld [i]+"_ERROR_Row";
	document.getElementById(theRow).className = "hiddenErrorMsg";
	var theCell				= tabFld [i]+"_ERROR_Cell";
	document.getElementById(theCell).innerHTML = '';
	tabFld [i]				= '';
	tabFldClass [i]			= '';
}
function putFieldsInNormal()
{
	addDebug("putFieldsInNormal--------------------------------------");
	for(var i=0; i<iFld; i++)
	{
		if(tabFld [i]) 			restoreField(i)
	}
}
function putFieldInNormal(id)
{
	addDebug("putFieldInNormal-(id="+id+")----------------------------");
	for(var i=0; i<iFld; i++)
	{
		if(tabFld [i] == id)	restoreField(i);
	}
}
function affFields()
{
	addDebug("affFields----------------------------------------------");
	for(var i=0; i<iFld; i++)
	{
		addDebug("affFields - field="+tabFld [i]+" - class="+tabFldClass [i]);
	}
}

// Gestion du chronomètre ---------------------------------------------------------------------------------
function chronometer(variableName, hours, minutes, seconds, milliseconds, upOrDown, speed, separator, alternateSeparator, yourPrintFunction, yourEndFunction, showMilliseconds)
{
    this.variableName = variableName;
    this.hours = parseFloat(hours) ? Math.abs(parseFloat(hours)) : 0;
    this.minutes = parseFloat(minutes) ? Math.abs(parseFloat(minutes)) : 0;
    this.seconds = parseFloat(seconds) ? Math.abs(parseFloat(seconds)) : 0;
    this.milliseconds = parseFloat(milliseconds) ? Math.abs(parseFloat(milliseconds)) : 0;
    this.originalTime = hours + ":" + minutes + ":" + seconds + ":" + milliseconds;
    this.upOrDown = upOrDown ? 1 : 0;
    this.endTime = this.hours * 60 * 60 * 1000 + this.minutes * 60 * 1000 + this.seconds * 1000 + this.milliseconds;
    this.date = new Date;
    if (this.upOrDown) {
        this.hours = 0;
        this.minutes = 0;
        this.seconds = 0;
        this.milliseconds = 0;
    }
    this.date.setHours(this.hours);
    this.date.setMinutes(this.minutes);
    this.date.setSeconds(this.seconds);
    this.date.setMilliseconds(this.milliseconds);
    this.endTime = this.upOrDown ? this.date.getTime() + this.endTime : this.date.getTime() - this.endTime;
    this.speed = parseFloat(speed) ? parseFloat(speed) : 1000;
    this.speed = this.speed > 1000 || this.speed < 100 ? 1000 : this.speed;
    this.yourEndFunction = yourEndFunction;
    this.yourPrintFunction = yourPrintFunction;
    this.separator = separator ? separator : ":";
    this.alternateSeparator = alternateSeparator ? alternateSeparator : ":";
    this.showMilliseconds = showMilliseconds ? 1 : 0;
    this.result = "";
    this.odds = 0;
    this.timer = 0;
    this.executeUP = function () {
		this.hours = this.date.getHours();
		this.minutes = this.date.getMinutes();
		this.seconds = this.date.getSeconds();
		this.milliseconds = this.date.getMilliseconds();
		this.hours = this.hours < 10 ? "0" + this.hours : this.hours;
		this.minutes = this.minutes < 10 ? "0" + this.minutes : this.minutes;
		this.seconds = this.seconds < 10 ? "0" + this.seconds : this.seconds;
		var separate = !this.odds ? this.separator : this.alternateSeparator;
		this.odds = !(this.odds % 2) ? 1 : 0;
		var millis = "";
		if (this.showMilliseconds) {
			this.milliseconds = this.milliseconds < 10 ? "000" + this.milliseconds : this.milliseconds < 100 ? "00" + this.milliseconds : this.milliseconds < 1000 ? "0" + this.milliseconds : this.milliseconds;
			millis = separate + this.milliseconds;
		}
		this.result = this.hours + separate + this.minutes + separate + this.seconds + millis;
		if (this.yourPrintFunction) {
			if (typeof this.yourPrintFunction == "function") {
				this.yourPrintFunction(this.result);
			}
			else {
				this.yourPrintFunction.value = this.result;
			}
		}
		if (this.date.getTime() >= this.endTime) {
			this.stop();
			if (this.yourEndFunction) {
				this.yourEndFunction();
			}
		}
		this.date.setTime(this.date.getTime() + this.speed);return this.result;
		};
	this.executeDOWN = function () {
		this.hours = this.date.getHours();
		this.minutes = this.date.getMinutes();
		this.seconds = this.date.getSeconds();
		this.milliseconds = this.date.getMilliseconds();
		this.hours = this.hours < 10 ? "0" + this.hours : this.hours;
		this.minutes = this.minutes < 10 ? "0" + this.minutes : this.minutes;
		this.seconds = this.seconds < 10 ? "0" + this.seconds : this.seconds;
		var separate = !this.odds ? this.separator : this.alternateSeparator;
		this.odds = !(this.odds % 2) ? 1 : 0;
		var millis = "";
		if (this.showMilliseconds) {
			this.milliseconds = this.milliseconds < 10 ? "000" + this.milliseconds : this.milliseconds < 100 ? "00" + this.milliseconds : this.milliseconds < 1000 ? "0" + this.milliseconds : this.milliseconds;
			millis = separate + this.milliseconds;
		}
		this.result = this.hours + separate + this.minutes + separate + this.seconds + millis;
		if (this.yourPrintFunction) {
			if (typeof this.yourPrintFunction == "function") {
				this.yourPrintFunction(this.result);
			}
			else {
				this.yourPrintFunction.value = this.result;
			}
		}
		if (this.date.getTime() <= this.endTime) {
			this.stop();
			if (this.yourEndFunction) {
				this.yourEndFunction();
			}
		}
		this.date.setTime(this.date.getTime() - this.speed);
		return this.result;
	};
    this.run = function () {
		this.stop();
		if (this.date.getTime() >= this.endTime && this.upOrDown || this.date.getTime() <= this.endTime && !this.upOrDown) {
			return false;
		}
		var whichFunction = this.upOrDown ? ".executeUP()" : ".executeDOWN()";
		eval(this.variableName + whichFunction);
		this.timer = setInterval(this.variableName + whichFunction, this.speed);
		return true;
	};
    this.stop = function () {
		clearInterval(this.timer);
	};
	/* keep this comment to reuse freely: http://www.unitedscripters.com */
}

function timerEndAlert()
{
	alert("Session utilisateur terminée !!!");
};

function refreshPage()
{
	window.history.go(0);
	return false;
}
function setNewTimeOut()
{
	var newTimeOut				= 1000*3600;
	setTimeout("refreshPage()", newTimeOut);
	addDebug("Nouveau time-out dans "+newTimeOut+" millisecondes !!!");
}

function suivant(enCours, suivant, limite) 
{ 
	if(enCours.value.length == limite)
		document.getElementById(suivant).focus();
}

