/****************************************************
/* Bibliothèque de fonctions JavaScript utilitaires *
/****************************************************
/*	
/*	Fonctions générales
/*	----------------------
/*
/*	BrowserInfo			Informations sur le navigateur
/*	position			Position de la souris
/*
/*	Gestion d'objet & fonctions MM
/*	----------------------
/*	findObj					Recherche d'objet
/*	MM_preloadImages		Préchargement d'image
/*	MM_swapImgRestore		Gestion d'image survolée
/*	MM_swapImage
/*	MM_jumpMenu				Menu de reroutage
/*	showHideLayers			Affichage : masquage de couche
/*	getElementsByClassName	Recherche d'objet par nom de classe
/*	aClasse					Teste l'association d'une classe à un objet
/*	ajouteClasse			Ajoute une classe à un objet
/*	enleveClasse			Enlève une classe d'un objet
/*
/*	Chaînes de caractères
/*	----------------------
/*	trim
/*	ltrim
/*	rtrim
/*
/*	Formulaires
/*	-----------
/*	DecaleDate				Décale une date par rapport à une autre
/*	filtre					Filtre sur la saisie de caractères
/*	formate					Formatage de champs à la sortie du champ (n° tél, ...)
/*	controleSaisie			Contrôle de saisie pour validation formulaire
/*	groupeControleSaisie	Validation d'un groupe de contrôles de saisie pour validation formulaire
/*	testeFichierImage		Vérifie qu'une fichier image est du bon type
/*	AddTags					Ajoute des tags dans un textarea
/*	doGetCaretPosition		Récupère la position du curseur dans un textarea
/*	doSetCaretPosition		Définit la position du curseur dans un textarea
/*	soumet					Soumet un formulaire ou affiche un message d'erreur
/*	OrdonneTable			Change l'ordre des champs dans une table ordonnée
/*	Punaise					Gestion de punaise cliquable
/*
/*	Gestion de tables de type "liste"
/*	---------------------------------
/*	ChargeListe				
/*	ValideListe				
/*	EffaceListe				Efface une entrée de liste
/*	OrdonneListe
/*	basculeListe			Bascule entre "Select" et "Text"
/*	sauveListe
/*	enleveListeMultiple		Gestion des listes à choix multiple
/*	ajouteListeMultiple
/*
/*	Gestion ascenseur
/*	------------
/*	moveLayerH				Déplacement ascenseur horizontal
/*	majAscenseurH			Démarrage ascenseur horizontal
/*	moveLayerV				Déplacement ascenseur vertical
/*	majAscenseurV			Démarrage ascenseur vertical
/*
/*	Gestion DHTML_Suite
/*	-------------------
/*	Gestion AJAX
/*	------------
/*	createXHR				création de la communication
/*	MajAjax					échange avec le serveur
/****************************************************/

function BrowserInfo()
{
	this.agent = navigator.userAgent.toLowerCase();
	this.name = navigator.appName;
	this.codename = navigator.appCodeName;
	this.version = navigator.appVersion.substring(0,4);
	this.platform = navigator.platform;
	this.javaEnabled = navigator.javaEnabled();
	this.screenWidth = screen.width;
	this.screenHeight = screen.height;
	this.name = (this.agent.indexOf('msie') != -1) ? "msie" :
				((this.agent.indexOf('firefox') != -1) ? "firefox" :
				((this.agent.indexOf('chrome') != -1) ? "chrome" :
				((this.agent.indexOf('opera') != -1) ? "opera" :
				((this.agent.indexOf('safari') != -1) ? "safari" : "autre"))));
	if (this.name == "msie") this.version = parseInt(this.agent.substring(this.agent.indexOf('msie ') + 5));
}
var navigateur = new BrowserInfo();
var xSouris,ySouris;	// Position de la souris
var jQueryActif = typeof(jQuery)!='undefined';	// Présence de jQuery

//////////////////////////////////
// Fonctions TRIM
//////////////////////////////////
var regExpBeginning = /^\s+/;
var regExpEnd       = /\s+$/;

// Supprime les espaces inutiles en début et fin de la chaîne passée en paramètre.
function trim(aString)
{
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

// Supprime les espaces inutiles en début de la chaîne passée en paramètre.
function ltrim(aString)
{
    return aString.replace(regExpBeginning, "");
}
 
// Supprime les espaces inutiles en fin de la chaîne passée en paramètre.
function rtrim(aString)
{
    return aString.replace(regExpEnd, "");
}

//////////////////////////////////
// Recherche d'objet
//////////////////////////////////
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

//////////////////////////////////
// Bascule d'image
//////////////////////////////////
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=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
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];}}
}

//////////////////////////////////
// Recherche d'objet par nom de classe
//////////////////////////////////
function getElementsByClassName(classe, tag, elm)	// tag : type d'élément - elm : parent
{
//	var testClass = new RegExp("(^|s)" + classe + "(s|$)");
	var testClass = new RegExp(classe);
	tag = tag || "*";
	elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		nomClasse = current.className.split(" ");
//		if(testClass.test(nomClasse[0])){
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}
//////////////////////////////////
// Affiche / Masque objet
//////////////////////////////////
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
//        if(visStr == 'show') visStr = 'visible';
//        else if(visStr == 'hide') visStr = 'hidden';
//      }
//      obj.visibility = visStr;
        if(visStr == 'show') visStr = '';
        else if(visStr == 'hide') visStr = 'none';
      }
      obj.display = visStr;
    }
  }
}

//////////////////////////////////
// Menu de reroutage
//////////////////////////////////
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


//////////////////////////////////
// Gestion de classe
//////////////////////////////////
function aClasse (element, className)
{
	if (element == "" || !(element = $(element))) return;
	var elementClassName = element.className;
	return (elementClassName.length > 0 && (elementClassName == className ||
	new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
}

function ajouteClasse(element, className)
{
	if (element == "" || !(element = $(element))) return;
	if (!aClasse(element, className))
	element.className += (element.className ? ' ' : '') + className;
}

function enleveClasse (element, className)
{
	if (element == "" || !(element = $(element))) return;
	element.className = element.className.replace(
	new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
}
//////////////////////////////////
// Gestion de l'ascenseur|
//////////////////////////////////
var Timer;
function moveLayerV(sens,id,parent,enfant) {
	var pas = 5;
	Objet=findObj(enfant);
    if(parseInt(Objet.style.top) + (pas*sens)>0)
	{
		clearTimeout(Timer);
		showHideLayers(id+"Haut",'','hide');
	}
	else if(parseInt(Objet.style.top) + (pas*sens)<-(Objet.offsetHeight-document.getElementById(parent).offsetHeight))
	{
		clearTimeout(Timer);
		showHideLayers(id+"Bas",'','hide');
	}
    else
	{
        Objet.style.top = (parseInt(Objet.style.top) + (pas*sens)) + "px";
		showHideLayers(id+"Haut",'','show',id+"Bas",'','show' );
	}
	Timer = setTimeout("moveLayerV("+sens+",'"+id+"','"+parent+"','"+enfant+"');", 30);
}
function majAscenseurV(id,parent,enfant)
{
	// Rafraichit l'ascenseur après mise à jour du contenu
	objP=findObj(parent);
	objE=findObj(enfant);	objE.style.top = 0;
	showHideLayers(id+"Haut",'','hide',id+"Bas",'',(objE.offsetHeight>objP.offsetHeight+6 ? 'show' : 'hide'));
}
function moveLayerH(sens,id,parent,enfant) {
	var pas = 7;
	Objet=findObj(enfant);
    if(parseInt(Objet.style.left) + (pas*sens)>0)  {
		clearTimeout(Timer);
		showHideLayers(id+"Gauche",'','hide');
	}
	else if(parseInt(Objet.style.left) + (pas*sens)<-(Objet.offsetWidth-document.getElementById(parent).offsetWidth)) {
		clearTimeout(Timer);
		showHideLayers(id+"Droit",'','hide');
	}
    else {
        Objet.style.left = (parseInt(Objet.style.left) + (pas*sens)) + "px";
		showHideLayers(id+"Gauche",'','show',id+"Droit",'','show' );
	}
	Timer = setTimeout("moveLayerH("+sens+",'"+id+"','"+parent+"','"+enfant+"');", 30);
}
function majAscenseurH(id,parent,enfant,fin)
{
	// Rafraichit l'ascenseur après mise à jour du contenu
	objP=findObj(parent);
	objE=findObj(enfant);	objE.style.left = 0;
	objF=findObj(fin);		objE.style.width=objF.offsetLeft + 10 + "px";
	showHideLayers(id+"Gauche",'','hide',id+"Droit",'',(objE.offsetWidth>objP.offsetWidth ? 'show' : 'hide'));
}

//////////////////////////////////
// Position de la souris
//////////////////////////////////
function position(e)
{
	xSouris = (!document.all) ? e.pageX : event.x+document.body.scrollLeft;
	ySouris = (!document.all) ? e.pageY : event.y+document.body.scrollTop;
}

//////////////////////////////////
// Gestion de la punaise
//////////////////////////////////
function Punaise (coche,check)
{
	chk = findObj(check);
	chk.checked = !chk.checked;
	if (chk.checked)
	{
		ajouteClasse(coche,'coche');
	}
	else
	{
		enleveClasse(coche,'coche');
	}
}

//////////////////////////////////
// Décalage de date
//////////////////////////////////
function DecaleDate(champ_date,champ_dest,delai)
{	// Calcule la date d'expiration de l'actualité
	obj=findObj(champ_date);
	date = escape(obj.value);
	MajAjax(ressources+"php/FonctionsAjax.php","action=DecaleDate&champ="+champ_dest+"&decale="+delai+"&date="+date);
}

//////////////////////////////////
// Filtre sur saisie de caractères
//////////////////////////////////
function filtre (e,type) {
  e = (e) ? e : ((window.event) ? window.event : null);
	switch (navigateur.name)
	{
		case 'firefox':
			charCode = (e.charCode) ? e.charCode : 0;
			keyCtrl = charCode==0 || e.ctrlKey;
			break;
		case 'msie':
		case 'chrome':
			charCode=e.keyCode;
			keyCtrl = false;
			break;
		default:
			charCode=e.keyCode;
			keyCtrl = false;
			break;
	}
  keyNum = (charCode>=48 && charCode<=57);
  keyFloat = keyNum || charCode==44 || charCode==46;
  keyTel = keyNum || charCode==32;
  keyHexa = keyNum || (charCode>=65 && charCode<=70) || (charCode>=97 && charCode<=102);
  keyAlpha = keyNum || (charCode>=65 && charCode<=90) || (charCode>=97 && charCode<=122) || (charCode>=224 && charCode<=252) || charCode==32;

  if (!keyCtrl && ((type=="num" && !keyNum) || (type=="float" && !keyFloat) || (type=="tel" && !keyTel) || (type=="hexa" && !keyHexa) || (type=="alpha" && !keyAlpha)))
  {
  	switch (navigateur.name)
	{
		case 'firefox':
			e.preventDefault();
			break;
		case 'msie':
		case 'chrome':
			e.returnValue = false;
			break;
		default:
			e.returnValue = false;
			break;
	}
    return false;
  }
}

//////////////////////////////////
// Formatage de champs
//////////////////////////////////
function formate (champ,type)
{
	var reg=new RegExp("( )", "g");
	valeur=champ.value.replace(reg,"");
  	switch (type)
	{
		case 'siret':
			var reg=new RegExp("([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{5})");
			if (valeur.length==14) champ.value=valeur.replace(reg,"$1 $2 $3 $4");
			break;
		case 'tel':
			var reg=new RegExp("([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})");
			if (valeur.length>=10) champ.value=valeur.replace(reg,"$1 $2 $3 $4 $5");
			break;
		case 'float':
			champ.value = isNaN (parseFloat(champ.value)) ? "" : parseFloat(champ.value).toFixed(2);
			break;
	}
}

//////////////////////////////////
// Contrôle de saisie pour validation formulaire
//////////////////////////////////
function controleSaisie()
{
	var i, args = controleSaisie.arguments;
	
	if (!args[0]) return true;
	var champ=args[0];
	var parent="";
	var ok = true;
	mail = /^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;

	for (i=1; i<args.length; i++)
	{
		switch (args[i])
		{
			case 'vide':	// champ nom vide
				ok = ok && champ.value.length>0;
				break;
			case 'mail':	// mail correct
				if (champ.value.length>0) ok = ok && mail.test(champ.value);
				break;
			case 'liste':	// élément de liste sélectionné
				ok = ok && champ.value!=0;
				break;
			case 'check':	// case à cocher
				ok = ok && champ.checked;
				parent=champ.parentNode;
				break;
			case 'radio':	// radio bouton sélectionné
				ok2 = false;
				for (var j=0; j<champ.length;j++)
				{
					if (champ[j].checked) ok2=true;
				}
				ok = ok && ok2;
				parent=champ[0].parentNode;
				break;
			case 'image':	// champ fichier image de type image
				if(champ.value.length!=0)
				{
					ext=champ.value.substring(champ.value.lastIndexOf(".")).toLowerCase();
					if (ext!=".jpeg"&&ext!=".jpg"&&ext!=".gif"&&ext!=".png")
					{
						alert ("Type de fichier image incorrect (formats acceptés : JPEG, GIF, PNG)");
						ok = false;
					}
					parent=args[args.length-1];
				}
				break;
			default:		// longueur de champ imposée
				if (!isNaN(args[i]) && champ.value.length>0) ok = ok && trim(champ.value).length==args[i];
				break;
		}
	}
	obj = (parent!="") ? parent : champ;			
	if (!ok)
	{
		// Champ en erreur : mise en évidence
		ajouteClasse(obj,'erreur');
		return false;
	}
	else
	{
		// pas d'erreur
		enleveClasse(obj,'erreur');
		return true;
	}
}
//////////////////////////////////
// Validation d'un groupe de contrôle de saisie pour validation formulaire
//////////////////////////////////
function groupeControleSaisie(ok,parent)
{
	obj = findObj(parent);			
	if (!ok)
	{
		// Champ en erreur : mise en évidence
		obj.className = 'erreur';
		return false;
	}
	else
	{
		// pas d'erreur
		obj.className = '';
		return true;
	}
	return ok;
}
//////////////////////////////////
// Vérifie qu'un fichier image est au bon format
//////////////////////////////////
function testeFichierImage(fic)
{
	if(fic.length!=0)
	{
		ext=fic.substring(fic.lastIndexOf(".")).toLowerCase();
		return (ext==".jpeg"||ext==".jpg"||ext==".gif"||ext==".png");
	}
	else
	{
		return (true);
	}
}
//////////////////////////////////
// Gestion de liste : ajout d'un élément dans un formulaire de saisie
//////////////////////////////////
function ChargeListe(liste,enreg,multiLangue,modifie)
{
	sel=findObj("liste_"+liste);
	if (enreg>0)
	{
		// affichage des données de la liste
		obj=findObj("liste_"+liste);		argu="&enreg="+obj.options[obj.selectedIndex].value+"&liste="+liste;
//		if (obj=findObj("btEfface_"+liste))		obj.className = 'visible';
//		if (obj=findObj("btNouveau_"+liste))	obj.className = 'visible';
		showHideLayers("btEfface_"+liste,"","show","btNouveau_"+liste,"","show");
		// modifie est VRAI pour la page de gestion des listes, FAUX pour l'appel de la liste dans un formulaire
		MajAjax(ressources+"php/FonctionsAjax.php","action=ChargeListe"+argu+"&modifie="+(modifie ? 1 : 0));
	}
	else
	{
		// effacement des champs
		sel.selectedIndex = sel.size>0 ? -1 : 0;
		showHideLayers("btEfface_"+liste,"","hide","btNouveau_"+liste,"","hide");
		if (multiLangue)
		{
			obj=getElementsByClassName('ch_'+liste);
			for (i=0;i<obj.length;i++)
			{
				obj[i].value="";
			}
			if (obj.length>0) obj[0].focus();
		}
		else
		{
			obj=findObj("ch_"+liste);	obj.value="";	obj.focus();
		}
	}
}
function ValideListe(liste,multiLangue)
{
	obj=findObj("liste_"+liste);
	argu="&enreg="+(obj.selectedIndex>=0 ? obj.options[obj.selectedIndex].value : 0)+"&liste="+liste;
	if (multiLangue)
	{
		obj=getElementsByClassName('ch_'+liste);
		for (i=0;i<obj.length;i++)
		{
			argu += "&nom"+obj[i].id.substring(obj[i].id.lastIndexOf('_'))+"="+escape(obj[i].value);
		}
		if (obj[0].value.length>0)
		{
			MajAjax(ressources+"php/FonctionsAjax.php","action=ValideListe"+argu);
		}
		else
		{
			alert("Intitulé français obligatoire !");
		}
	}
	else
	{
		obj=findObj("ch_"+liste);
		argu+="&nom="+escape(obj.value);
		if (obj.value.length>0)
		{
			MajAjax(ressources+"php/FonctionsAjax.php","action=ValideListe"+argu);
		}
		else
		{
			alert("Intitulé manquant !");
		}
	}
}
function EffaceListe(liste,multiLangue)
{
	if (confirm("Voulez-vous effacer cet élément ?"))
	{
		obj=findObj("liste_"+liste);
		MajAjax(ressources+"php/FonctionsAjax.php","action=EffaceListe&enreg="+obj.options[obj.selectedIndex].value+"&liste="+liste);
	}
}
function OrdonneListe(liste,sens)
{
	var obj = findObj("liste_"+liste);
	var index;
	if ((index = obj.selectedIndex) >=0)
	{
		var nb = obj.length;
		autre = sens>0 ? Math.min(index+1,nb-1) : Math.max(index-1,0);
		if (autre!=index)
		{
			tmpval=obj.options[index].value;
			tmptxt=obj.options[index].text;
			obj.options[index].value=obj.options[autre].value;
			obj.options[index].text=obj.options[autre].text;
			obj.options[autre].value=tmpval;
			obj.options[autre].text=tmptxt;
			obj.selectedIndex=autre;
			
			// enregistrement de l'ordre
			var uid = "";
			var rang = "";
			for (i=0;i<obj.length;i++)
			{
				uid += obj[i].value + ",";
				rang += i + ",";
			}
			MajAjax(ressources+"php/FonctionsAjax.php","action=OrdonneListe&enreg="+uid+"&rang="+rang+"&liste="+liste);
		}
	}
}
function basculeListe(liste,langue)
{
	showHideLayers("bt_"+liste,"","hide","liste_"+liste,"","hide","ch_"+liste+langue,"","show");
	obj=findObj("ch_"+liste+langue);	obj.focus();
}

function sauveListe(liste,langue)
{
	var enreg=0;
	obj=findObj("liste_"+liste);
	// Mono-langue ou FR : ajout d'un enregistrement
	if (langue!="" && langue!='_FR')
	{	// mise à jour d'une autre langue d'un enregistrement existant
		enreg=(obj.selectedIndex>=0 ? obj.options[obj.selectedIndex].value : 0);
	}
	argu="&enreg="+enreg+"&liste="+liste;
	obj=findObj("ch_"+liste+langue);	argu+="&nom"+langue+"="+escape(obj.value);
	showHideLayers("bt_"+liste,"","show","liste_"+liste,"","show","ch_"+liste+langue,"","hide");
	
	if (obj.value.length>0)
	{
		MajAjax(ressources+"php/FonctionsAjax.php","action=ValideListe"+argu);
	}
}

//////////////////////////////////
// Gestion de liste à sélection multiple : bascule d'une liste vers l'autre
//////////////////////////////////
function ajouteListeMultiple(id,index)
{
	if (index>0)
	{
		lstAvant=findObj("liste_"+id);
		lstApres=findObj("liste_apres_"+id);
		hfApres=findObj("hf_apres_"+id);
		
		var o=new Option(lstAvant.options[index].text,lstAvant.options[index].value);
		lstApres.options[lstApres.options.length]=o;
		lstAvant.options[index]=null;
	
		hfApres.value = "";
		for (i=0;i<lstApres.options.length;i++)
		{
			hfApres.value += lstApres.options[i].value+",";
		}
	}
}

function enleveListeMultiple(id,index)
{
	if (index>=0)
	{
		lstAvant=findObj("liste_"+id);
		lstApres=findObj("liste_apres_"+id);
		hfApres=findObj("hf_apres_"+id);
		
		
		var o=new Option(lstApres.options[index].text,lstApres.options[index].value);
		lstAvant.options[lstAvant.options.length]=o;
		lstApres.options[index]=null;
		
		hfApres.value = "";
		for (i=0;i<lstApres.options.length;i++)
		{
			hfApres.value += lstApres.options[i].value+",";
		}
	}
}

//////////////////////////////////
// Changement de l'ordre des champs d'une table
//////////////////////////////////
function OrdonneTable(liste,sens,table,pref)
{
	var obj = findObj(liste);
	var index;
	if ((index = obj.selectedIndex) >=0)
	{
		var nb = obj.length;
		autre = sens>0 ? Math.min(index+1,nb-1) : Math.max(index-1,0);
		if (autre!=index)
		{
			// Inversion des lignes du select
			tmpval=obj.options[index].value;
			tmptxt=obj.options[index].text;
			obj.options[index].value=obj.options[autre].value;
			obj.options[index].text=obj.options[autre].text;
			obj.options[autre].value=tmpval;
			obj.options[autre].text=tmptxt;
			obj.selectedIndex=autre;
			// enregistrement de l'ordre
			var uid = "";
			var rang = "";
			for (i=0;i<obj.length;i++)
			{
				uid += obj[i].value + ",";
				rang += i + ",";
			}
			MajAjax(ressources+"php/FonctionsAjax.php","action=OrdonneTable&enreg="+uid+"&rang="+rang+"&table="+table+"&pref="+pref);
		}
	}
}

//////////////////////////////////
// Submit avec affichage image d'attente
//////////////////////////////////
function soumet(docu)
{
	var args=soumet.arguments;
	var top = (args.length > 1 ? args[1] : true);
	if (top)
	{
		showHideLayers('wait','','show');
		docu.submit();
	}
	else
	{
		alert(args[2]);
	}
}

//////////////////////////////////
// Ajout de balises (gras, ...) dans un textarea
//////////////////////////////////
function AddTags(f, ch, balise, multiLangue)
{
	var str_deb="["+balise+"]";
	var str_fin="[/"+balise+"]";
	if (multiLangue)
	{
		obj=findObj('hf_langue');
		ch = ch+"_"+obj.value;
	}
	message = f.elements[ch];
   
   if (navigator.userAgent.indexOf('MSIE') != -1)
   {
      f.elements[ch].focus();
		var txt = document.selection.createRange().text;
		var rng = document.selection.createRange();
      if (txt=="")
			rng.text= str_deb + str_fin;
		else
			rng.text= str_deb + rng.text + str_fin;
		rng.moveEnd("character", -str_fin.length);
		rng.select();
   }
   else if (message.selectionStart != null)
   {
      objectValue = message.value;
      objectValueDeb = objectValue.substring(0, message.selectionStart);
      objectValueFin = objectValue.substring(message.selectionEnd, message.textLength);
      objectSelected = objectValue.substring(message.selectionStart, message.selectionEnd);
      message.value = objectValueDeb + str_deb + objectSelected + str_fin + objectValueFin;
      message.focus();
      message.selectionStart = message.value.length - objectValueFin.length;
      message.selectionEnd = message.selectionStart;
   }
   else
   {
      message.value += str_deb + str_fin;
   }
   doSetCaretPosition(message,doGetCaretPosition(message)-str_fin.length);
}
//////////////////////////////////
// Ajout de balises (gras, ...) dans un textarea : récupération position curseur
//////////////////////////////////
function doGetCaretPosition (oField) {
 // Initialize
 var iCaretPos = 0;
 // IE Support
 if (document.selection) { 
   // Set focus on the element
   oField.focus ();
   // To get cursor position, get empty selection range
   var oSel = document.selection.createRange ();
   // Move selection start to 0 position
   oSel.moveStart ('character', -oField.value.length);

   // The caret position is selection length
   iCaretPos = oSel.text.length;
 }
 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0')
   iCaretPos = oField.selectionStart;
 // Return results
 return (iCaretPos);
}
//////////////////////////////////
// Ajout de balises (gras, ...) dans un textarea : positionnement du curseur
//////////////////////////////////
function doSetCaretPosition (oField, iCaretPos) {
/* Sets the caret (cursor) position of the specified text field.
   Valid positions are 0-oField.length. */

 // IE Support
 if (document.selection) { 
   // Set focus on the element
   oField.focus ();
   // Create empty selection range
   var oSel = document.selection.createRange ();
   // Move selection start and end to 0 position
   oSel.moveStart ('character', -oField.value.length);
   // Move selection start and end to desired position
   oSel.moveStart ('character', iCaretPos);
   oSel.moveEnd ('character', 0);
   oSel.select ();
 }
 // Firefox support
 else if (oField.selectionStart || oField.selectionStart == '0') {
   oField.selectionStart = iCaretPos;
   oField.selectionEnd = iCaretPos;
   oField.focus ();
 }
}

//////////////////////////////////
// Fonctions DHTML_Suite : gestion du calendrier
//////////////////////////////////
function pickDate(inputObject)
{
	calendrier.setCalendarPositionByHTMLElement(inputObject,0,inputObject.offsetHeight+2);	// Position the calendar right below the form input
	calendrier.setInitialDateFromInput(inputObject,'dd/mm/yyyy');	// Specify that the calendar should set it's initial date from the value of the input field.
	calendrier.addHtmlElementReference('myDate',inputObject);		// Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
	if(calendrier.isVisible())
	{
		calendrier.hide();
	}
	else
	{
		calendrier.resetViewDisplayedMonth();	// This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
		calendrier.display();
	}		
}	

function getDateFromCalendar(inputArray)
{
	var references = calendrier.getHtmlElementReferences(); // Get back reference to form field.
	references.myDate.value = inputArray.day + '/' + inputArray.month + '/' + inputArray.year;
	calendrier.hide();
}
//////////////////////////////////
// Fonctions SPRY : slide panel
//////////////////////////////////
var observer = {};
observer.nextEffect = false;
observer.onPostEffect = function(e){
	if (this.nextEffect)
	{
		var eff = this.nextEffect;
		setTimeout(function(){eff.start();}, 10);
	}
	this.nextEffect = false;
}

function sprySlide (currentPanel)
{
    // The list of all the panels that need sliding
	var opened = -1;

	// Let's check if we have an effect for each of these sliding panels
	if (typeof effects == 'undefined')
		effects = {};

	for (var i=0; i < sprySlidePanels.length; i++)
	{
		if (typeof effects[sprySlidePanels[i]] == 'undefined'){
			effects[sprySlidePanels[i]] = new Spry.Effect.Slide(sprySlidePanels[i], {from: '0%', to: '100%', toggle: true});
			effects[sprySlidePanels[i]].addObserver(observer);
		}
		 
		if (effects[sprySlidePanels[i]].direction == Spry.forwards && currentPanel != sprySlidePanels[i])
			opened = i;

		//prevent too fast clicks on the buttons
		if (effects[sprySlidePanels[i]].direction == Spry.backwards && effects[sprySlidePanels[i]].isRunning)
		{
			observer.nextEffect = effects[currentPanel];
			return;
		}
	}

	if (opened != -1)
	{
		observer.nextEffect = effects[currentPanel];
		effects[sprySlidePanels[opened]].start();
	} 
	else if (effects[currentPanel].direction != Spry.forwards)
	{
		effects[currentPanel].start();
	}
}

//////////////////////////////////
// Fonctions DHTML : contenu glissant
//////////////////////////////////
/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/	
var slideTimeBetweenSteps = 30;	// General speed variable (Lower = slower)	
var scrollingContainer = false;
var scrollingContent = false;
var containerHeight;
var contentHeight;	

var contentObjects = new Array();
var originalslideSpeed = false;
function slideContent(containerId)
{
	var topPos = contentObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,'');
	topPos = topPos - contentObjects[containerId]['slideSpeed'];
	if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight'];
	contentObjects[containerId]['objRef'].style.top = topPos + 'px';
	setTimeout('slideContent("' + containerId + '")',slideTimeBetweenSteps);
}

function stopSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = 0;	
}

function restartSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = contentObjects[containerId]['originalSpeed'];
}
function initSlidingContent(containerId,slideSpeed)
{
	scrollingContainer = document.getElementById(containerId);
	scrollingContent = scrollingContainer.getElementsByTagName('DIV')[0];
	
	scrollingContainer.style.position = 'relative';
	scrollingContainer.style.overflow = 'hidden';
	scrollingContent.style.position = 'relative';
	
	scrollingContainer.onmouseover = stopSliding;
	scrollingContainer.onmouseout = restartSliding;
	
	originalslideSpeed = slideSpeed;
	
	scrollingContent.style.top = '0px';
	
	contentObjects[containerId] = new Array();
	contentObjects[containerId]['objRef'] = scrollingContent;
	contentObjects[containerId]['contentHeight'] = scrollingContent.offsetHeight;
	contentObjects[containerId]['containerHeight'] = scrollingContainer.clientHeight;
	contentObjects[containerId]['slideSpeed'] = slideSpeed;
	contentObjects[containerId]['originalSpeed'] = slideSpeed;
	
	slideContent(containerId);
}

//////////////////////////////////
// AJAX - création de la communication
//////////////////////////////////
function createXHR() 
{
    var request = false;
	try
	{
		request = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (err2)
	{
		try
		{
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (err3)
		{
			try
			{
				request = new XMLHttpRequest();
			}
			catch (err1) 
			{
				request = false;
			}
		}
	}
    return request;
}

//////////////////////////////////
// AJAX - échange avec le serveur
//////////////////////////////////
function MajAjax(url,contenu)
{ 
	var xhr = createXHR();
	
	xhr.onreadystatechange  = function()
	{ 
		if(xhr.readyState  == 4)
		{
			showHideLayers('wait','','hide');
			if(xhr.status  == 200)
			{
				try
				{
					eval(xhr.responseText); 
				}
				catch(err)
				{
					alert ("Erreur retour XMLHttpRequest :\n\n"+err.name+"\n"+err.message+"\n"+contenu);
				}
			}
			else 
				alert("Erreur transfert " + xhr.status+"\n"+xhr.statusText);
		}
	};
	
	showHideLayers('wait','','show');
	xhr.open("POST", url, true);		
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(contenu); 
} 

