/***************************************************************************************/
/*          DEBUT - FONCTIONS GENERALES                                                */
function writeTextInOpener(fieldName, value, divName, text)
{
  opener.document.forms[0].elements[fieldName].value = value;
  opener.writeText(divName, text);
  self.close();
}

function writeText(divName, text)
{
   // Locate the target DIV block
   myTarget = document.getElementById(divName);
   
   // Store the values extracted from the script
   if(myTarget != null) {
	   myTarget.innerHTML = text;
   }
}	

function writeTextInField(fieldName1, value1, fieldName2, value2)
{
  opener.document.forms[0].elements[fieldName1].value = value1;
  opener.document.forms[0].elements[fieldName2].value = value2;
  self.close();
}

function putValue(formName, fieldName, value) {
	document.forms[formName].elements[fieldName].value=value;
}

function newWindow(url, windowName, width, height)
{
	openNewWindow(url, windowName, 0, 0, width, height, "");
}

//x et y sont les coordonnées de positionnement de la fenêtre :
function openNewWindow(url, windowName, x, y, width, height, options) {
	var left="";
	var top="";
	if (options == "") {
		options = "menubar,scrollbars,resizable";
	}
	if (x != 0) {
		left="left="+x+",";
	}
	if (y != 0) {
		top="top="+y+",";
	}
	window.open(url, windowName, top+left+"width="+width+",height="+height+","+options);
}

function openPopupCentree(url, windowName, width, height,options) {
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
  openNewWindow(url, windowName, left, top, width, height,options);
}

  function openMessage(field, url, windowName, width, height, options) {
  	if (field.checked==true) {
  		openPopupCentree(url, windowName, width, height, options)
  	}
  }

function putFocusInto(fieldName)
{
	document.forms[0].elements[fieldName].focus();
}

function validateForm(keycode)
{
	//la touche Entr a le code 13 : 
	if(keycode==13)
	{
		document.forms[0].submit();
	}
}

//fonctions submit
function setNextMethodAndGo(theForm, nextAction)
{
	document.forms[theForm].elements['method'].value = nextAction;
	document.forms[theForm].submit();
	return false;
}

function selectAndGo(theForm, nextAction, liste)
{
	selectAll(liste);
	setNextMethodAndGo(theForm, nextAction);

 	return false;
}

// Ajoute une valeur dans un champ select
function list_addValue( selectField , sVal , bool) {
        
	n = selectField.options.length;
	selectField.options.length = n + 1;
	selectField.options[n].text = sVal;		
	selectField.options[n].value = sVal;
	selectField.options[n].selected = bool;
        
}
	
// Renvoie la valeur d'un champ select
function getSelectVal( tSelectList ) {
	nSelected = 0;
	tSelected ="";
	nOptions = tSelectList.length;
	
	for(i=0; i < nOptions; i++) {
		if( tSelectList.options[i].selected ){
			nSelected = i;
			break;
		}
	}
	return tSelectList[nSelected].text ;
}
	
// Supprime les éléments sélectionnés d'un select
function list_removeValues(tSelectList) {
	tmpLength = tSelectList.options.length;
	toDelete = new Array();
	k=0;
	for ( i = 0; i < tSelectList.options.length; i++ ) {
		if ( tSelectList.options[i].selected )  {
			toDelete[k]=i;
			k++;
		}
	}
        
	for ( j = toDelete.length ; j >= 0; j-- ) {
		tSelectList.options[toDelete[j]] = null;
	}
}
	
// Tri les éléments d'un select
function list_sortList (arrayIn) {
	for (i = 0; i <= arrayIn.length; i++) {
		j = i;
		for (k = i; k < arrayIn.length; k++) {
			if (arrayIn[k].value < arrayIn[j].value) {
				j = k;
			}
		}
		if (j > i) {
			l = arrayIn[i].value;
			arrayIn[i].text = arrayIn[j].value;
			arrayIn[j].text = l;
		}
	}
}
	
// Compte le nombre d'éléments sélectionnés dans un select
function list_countSelected(tSelectList){
	n=0;
	tmpLength = tSelectList.options.length;
	for ( i = 0; i < tSelectList.options.length; i++ ) {
		if ( tSelectList.options[i].selected )  {
			n++;
		}
	}		
	return n;				
}

// Vérifie qu'une valeur n'existe pas déjà dans la liste
function list_isInList( selectField , sVal) {
       
	bool = false;
	tmpList = selectField;
	tmpLength = tmpList.options.length;
       
	for ( i = 0; i < tmpLength; i++ ) {			
		if (tmpList.options[i].text == sVal) {
			bool = true;
			break;
		}
	}
	return bool;
}
        
// Supprime et copie dans un champ input d'une valeur d'un select
function list_edit(inputSourceField, selectDestinationField,msgErr,msgErr2) {
	var l_bool;
	var l_count;

	l_bool = true ;
	l_count = list_countSelected(selectDestinationField);
	if(inputSourceField.value !="" && l_count != 0) {
		l_bool = confirm(msgErr2);
	}
	
	if(l_bool) {
		if (l_count != 0) {
			if(	l_count != 1) {
				alert(msgErr);
			} else {
					inputSourceField.value = getSelectVal(selectDestinationField);
					list_removeValues(selectDestinationField);	
					list_sortList(selectDestinationField);	
			}
		}	
	}		
}
	

// Sélectionne tous les éléments d'un select
//si la liste est null ou ne contient pas d'élement on selectionne une option à ""
function list_selectAll(tSelectList) {
	if (tSelectList == null) {
		tSelectList = new Select();
	}
	nOptions = tSelectList.length;
	if(nOptions!=0) {
		for(i=0; i < nOptions; i++) {
			tSelectList.options[i].selected = true;
		}
	}

	else {
		var blankOption = new Option();
		blankOption.value="";
		blankOption.selected="true";
		tSelectList.options[0]=blankOption;
	}
}






// Supprime tous les éléments d'un select
function list_deleteSelected(selectDestinationField) {
	list_removeValues(selectDestinationField);
	list_sortList(selectDestinationField);
}

function addRemove(object1, object2)
{
	var i = 0;
	var value1="";
 	while (i < object1.length) {
  		if (object1.options[i].selected) {
			value1 = object1.options[i].value;
			if (value1 == null || value1=="") {
				value1 = object1.options[i].text;
			}
   			opt = new Option(object1.options[i].text, value1, false, false);
   			object2.options[object2.length] = opt;
   			object1.options[i] = null;
  		}
  		else i++;
 	}

 	return false;
}

function razSelect(object1)
{
 	while (object1.length > 0) {
   		object1.options[0] = null;
 	}

 	return false;
}

function setSelectWithOption(object1, object2)
{
	var i = 0;

	razSelect(object2);
	var value1="";
 	while (i < object1.length) {
  		if (object1.options[i].selected) {
			value1 = object1.options[i].value;
			if (value1 == null || value1=="") {
				value1 = object1.options[i].text;
			}
   			opt = new Option(object1.options[i].text, value1, false, false);
   			object2.options[object2.length] = opt;
   			break;
  		}
  		i++;
 	}

 	return false;
}

function removeWithRaz(object1, object2, object3)
{
	var i = 0;
	var value1="";
 	while (i < object1.length) {
  		if (object1.options[i].selected) {
   			if ( (object3.length > 0) && (object1.options[i].text == object3.options[0].text) ) {
   				razSelect(object3);
   			}
			value1 = object1.options[i].value;
			if (value1 == null || value1=="") {
				value1 = object1.options[i].text;
			}
   			opt = new Option(object1.options[i].text, value1, false, false);
   			object2.options[object2.length] = opt;
   			object1.options[i] = null;
  		}
  		else i++;
 	}

 	return false;
}

function selectAll(liste)
{
	var i;

 	for (i = 0; i < liste.length; i++) {
  		liste.options[i].selected = true;
 	}

 	return false;
}

//WEB337
//permet de remplacer les caractères windows non gérés en ascii (caractères entre 127 et 160 exclus) par leur référence valide :
//ces caractères non valides sont récupérés en javascript avec le code %uXXXX ou XXXX et le numéro unicode en hexadécimal
//et la référence valide est soit &#YYYY; avec YYYY le numéro unicode en décimal soit &#xYYYY le numéro en hexadécimal (x indiquant hexadécimal).
//malheureusement, le numéro est hexadécimal n'est pas interprété dans l'éditeur de Lotus Notes ==> on utilise le code décimal.
function encodeWindowsChar(texte) {
	var prefixe = "%u";
	var temp=escape(texte);
	var index=temp.indexOf(prefixe);
	var result= "";
	var nbHexadecimal = 0;
	while(index != -1){
		nbHexadecimal = eval("0x"+temp.substring(index+2, index+6)); // 0x : suffixe qui indique que le nbre est en hexadecimal
		result=result+temp.substring(0, index)+"&#"+nbHexadecimal.toString(10)+";";
		temp=temp.substring(index+6);	//6 : nb de caractères pour le code javascript d'une lettre :
		index=temp.indexOf(prefixe);
	}
	result=result+temp;

	return unescape(result);
}
/*********************************
méthodes utilisées pour gérer le mouse-over sur les images servant de boutons (page sommaire, bandeau...)
********************************/
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_findObj(n, d) { //v3.0
  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); return x;
}
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];}
}


/*          FIN - FONCTIONS GENERALES                                                  */
/***************************************************************************************/


/***************************************************************************************/
/*          DEBUT - FONCTIONS COOKIES                                                */
// cookies.js from http://www.webreference.com/js/column8/functions.html

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

/*          FIN - FONCTIONS COOKIES                                                  */
/***************************************************************************************/