gDesModifs = false;
gMouseMove = false;
gSourisX = null;
gSourisY = null;
//_____________________________________________________________________________
//
//  INITIALISATIOn - REDIRECTION
//_____________________________________________________________________________

var gLibOnglet = new Array;
gLibOnglet[0] = 'Recherche';
gLibOnglet[1] = 'Liste';
gLibOnglet[2] = 'Ajout';
gLibOnglet[3] = 'Modification';
gLibOnglet[4] = 'Mise à jour';


var tabLiensOnglet = new Array;

// Mise à jour des informations affichées dans la frame bandeau
// string titre Titre de la rubrique
// string nomUser Nom de l'utilisateur
// array  tabLibOnglet Tableau contenant les libellés des onglets à créer
// array  tabLienOnglet Tableau contenant les pages cibles des onglets
// string libOngletActif Libellé de l'onglet actif par défaut
function dkjs_majBandeau(titre, nomUser, tabLibOnglet, tabLienOnglet, libOngletActif) {
	var doc = parent.bandeau.document;
	// mise à jour du titre de la rubrique
	try {
		doc.getElementById('blc_titre').innerHTML = '&nbsp;'+titre;
	} catch(e) {}
	// récupération de la date et de l'heure
	var d = new Date();
	var moisEnCours = d.getMonth()+1;
	if (moisEnCours < 10) moisEnCours = '0'+moisEnCours;
	var anEnCours = d.getFullYear();
	var jourEnCours = d.getDate();
	if (jourEnCours < 10) jourEnCours = '0'+jourEnCours;
	
	// mise à jour de la cellule contenant les onglets
	var tableOnglet = '<table cellpadding="0" cellspacing="0" width="100%" border="0"><tr><td width="5" class="traitBas">&nbsp;</td>';
	var nbOnglet = tabLibOnglet.length;
	var classtd='';
	
	for (var i=0; i<nbOnglet; i++) {
		if (libOngletActif == tabLibOnglet[i]) classtd = 'celluleOngletActif';
		else if (tabLienOnglet[i] != '') classtd = 'celluleOngletInactif';
			else classtd = 'celluleOngletInactif2';
		tableOnglet += '<td class="'+classtd+'" '
			+((tabLienOnglet[i] != '') ? 'onClick="dkjs_submitOnglet(\''+tabLienOnglet[i]+'\')">' : '>')
		    + tabLibOnglet[i]+'</td><td width="5" class="traitBas">&nbsp;</td>';
	}

	// mise à jour de la date et de l'heure
	tableOnglet += '<td class="celluleHeure">'+nomUser+'&nbsp;'+jourEnCours+'/'+moisEnCours+'/'+anEnCours;
	tableOnglet += '</td></tr></table>';
	
	try {	
		doc.getElementById('blc_onglets').innerHTML = tableOnglet;
	} catch(e) {}
}

function dkjs_submitOnglet(vLop) {
	var F = parent.principale.document.forms[0];
	F.elements['Lop'].value = vLop;
	try {
		F.submit();
	}
	catch (e) {}
}

//_____________________________________________________________________________
function fpjs_initPage() {
	fpjs_msg(0);
	try {
		gBlocErreur = new xDhtml('blcErreur');
	}catch(e) {	}
	try {
		gObjEvent = new xEvent();
	}catch(e) {	}

	fpjs_setSaisie();

    if (gMouseMove) gObjEvent.add('mousemove', fpjs_getSourisXY);
}

//calcule la position de la souris
function fpjs_getSourisXY(e) {
    gSourisX = gObjEvent.pageX(e);
    gSourisY = gObjEvent.pageY(e);
}
//_____________________________________________________________________________
function fpjs_quitter() {
	if (gPopUpWin != null && !gPopUpWin.closed) gPopUpWin.close();
}
//_____________________________________________________________________________
// Gestion des redirections
function fpjs_redirect(sUrl, sParam) {
	var F = document.forms[0];
	if (sUrl != null) {
		if (sUrl == 'X') {  
			// Redirection sur une page appelante
			// on remet les différents zones cachées de la page appelante
			// qui était stockée dans la zone X sous la forme
			// lib=url|ID|Z=valeur|Z=valeur|....
			sParam = F.X.value;
			var i = sParam.indexOf('|');
			sUrl = sParam.substring(sParam.indexOf('=') + 1, i);
			i = sParam.indexOf('|', i + 1);
			sParam = sParam.substring(i + 1);
		}	
		F.action = sUrl;
	}
	if (sParam != null) {
		// sParam est une chaînes de la forme
		// Z=valeur|Z=valeur|....
		// Z est le nom d'une zone de formulaire (1 seul caractère)
		// valeur est la valeur de la zone
		var Params = sParam.split('|');
		var iMax = Params.length;
		for (var i = 0; i < iMax; i++) {
			if (Params[i] != '') {
				F.elements[Params[i].substring(0,1)].value = Params[i].substring(2);
			}
		}
	}
	try { 
        F.submit();
    } catch (e) { }
}

function dkjs_selfRedirect(sUrl, sParam, sCible) {
	document.forms[0].elements['Lop'].value = sCible;
	fpjs_redirect(sUrl, sParam);
}

function dkjs_redirect(cible) {
	document.forms[0].Lop.value = cible;
	document.forms[0].submit();
}
//_____________________________________________________________________________
// Positionne le curseur dans la première zone de saisie d'un formulaire
function fpjs_setSaisie() {
	if (document.forms.length == 0) return;
	var E = document.forms[0].elements
	var iMax = E.length;
	for (var i = 0; i < iMax; i++) {
		if (E[i].disabled) continue;
		if (E[i].readOnly) continue;	
		var Type = E[i].type.toLowerCase();
		if (Type == 'hidden') continue;
		if (Type == 'button') continue;
		if (Type == 'submit') continue;
		if (Type == 'reset') continue;
		if (Type.indexOf('select') != -1) continue;
		try {
			E[i].focus();
		} catch(e) {
			continue;
		}
		return;
	}
}

// Ajoute une option à la liste déroulante dont le nom est contenu dans la variable globale gNomListe
// et sélectionne cette nouvelle option par défaut
// oVal : Valeur de l'option à rajouter
// oLib : Libellé de l'option à rajouter
function dkjs_majListe(oVal, oLib) {
	var liste = document.forms[0].elements[gNomListe];
	var nbOptions = liste.options.length;
	var option = new Option(oLib,oVal);
	liste.options[nbOptions] = option;
	liste.selectedIndex = nbOptions;
}

//_____________________________________________________________________________
// Fenêtre popup pour download pièces jointes
// utilisation de la frame cachée
// Si download direct : bug : le formulaire n'est plus acessible avec JS ???
function dkjs_downloadImg(sUrl) {
	top.Vide.location.href = sUrl;
}

//_____________________________________________________________________________
// Fenêtre popup pour download pièces jointes
// utilisation de la frame cachée
// Si download direct : bug : le formulaire n'est plus acessible avec JS ???
function fpjs_downloadDoc(sType, sUrl) {
	sUrl = '../commun/download.php?T=' + sType + '&F=' + sUrl;
	top.Vide.location.href = sUrl;
}

//_____________________________________________________________________________
// Demande d'affichage de l'objet Calendrier
function fpjs_calendrier(sDate, sNomZone, bRemplaceSaisie) {
	if (gObjCalendrier == null) {
		gObjCalendrier = new oCalendrier('gObjCalendrier');
	}
	gObjCalendrier.setZone(sNomZone);
    if (bRemplaceSaisie != null) gObjCalendrier.setRemplaceSaisie(bRemplaceSaisie);
	gObjCalendrier.affiche(sDate);
}
//_____________________________________________________________________________
// Demande d'affichage de l'objet Calendrier version 2
function dkjs_calendrier(sDate, sNomZone, bRemplaceSaisie) {
	if (gObjCalendrier == null) {
		gObjCalendrier = new oCalendrier('gObjCalendrier');
	}
	gObjCalendrier.setZone(sNomZone);
    if (bRemplaceSaisie != null) gObjCalendrier.setRemplaceSaisie(bRemplaceSaisie);
	gObjCalendrier.afficheInterieur(sDate);
}
//_____________________________________________________________________________
// Fenêtre popup pour aide dans recherche
function fpjs_aideRecherche() {
	sUrl = '../commun/aiderecherche.htm';
	fpjs_popUp(sUrl, 600, 520);
}
// Fenêtre popup pour aide dans le planning
function fpjs_aidePlanning() {
	sUrl = '../commun/aidePlanning.htm';
	fpjs_popUp(sUrl, 600, 250);
}
//_____________________________________________________________________________
function fpjs_popUp(sUrl, nLarge, nHaut, nLeft, nTop) {
	if (gPopUpWin != null && !gPopUpWin.closed) gPopUpWin.close();
	if (nLarge == null) nLarge = (screen.width * 3) / 4;
    if (nLarge == -1) nLarge = screen.width - 50;
	if (nHaut == null) nHaut = (screen.height * 3) / 4;
    if (nHaut == -1) nHaut = screen.height - 60;
	if (nLeft == null) nLeft = ((screen.width - nLarge) / 2) - 10;
    if (nLeft == -1) nLeft = screen.width - nLarge - 10;
	if (nTop == null) nTop = ((screen.height - nHaut) / 2) - 30;
	if (window.opener == null) var Nom = 'tbatgpop';
	else if ((window.opener).opener == null) var Nom = 'tbatgpopb';
	else if (((window.opener).opener).opener == null) var Nom = 'tbatgpopa';
	else var Nom = 'tbatgpopc';
	var sOption = 'scrollbars,resizable,height=' + nHaut + ',width=' + nLarge
		+ ',left=' + nLeft + ',screenX=' + nLeft + ',top=' + nTop + ',screenY=' + nTop;
	gPopUpWin = window.open(sUrl, Nom, sOption);
	gPopUpWin.focus();
}

//_____________________________________________________________________________
//
//  GESTION DES COOKIES
//_____________________________________________________________________________
// Ecrit un cookie.
// nom : nom du cookie
// valeur : valeur du cookie
// 3ème argument possible : expires = date d'expiration du cookie (si non spécifié : expire à la fin de la session
// 4ème argument possible : path = d'accès du cookie (si non spécifié : celui de la page html qui l'a écrit
// 5ème argument possible : domain = discipline de validité du cookie (si non spécifié : celui de la page html qui l'a écrit
// 6ème argument possible : secure = sécurité du cookie (si non spécifié : accessible par une connexion non sécurisée (HTTP))
function dkjs_ecrireCookie(nom, valeur) {
	// tableau des arguments de la fonction
	var argv = dkjs_ecrireCookie.arguments;
	// Nombre d'arguments de la fonction
	var argc = dkjs_ecrireCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom + "=" + escape(valeur) +
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

// Retourne la valeur du cookie
function dkjs_getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr)); 
}

// Retourne la valeur du cookie nom
function dkjs_lireCookie(nom) {
	var arg = nom + "=";
	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 dkjs_getCookieVal(j);
		i = document.cookie.indexOf(" ",i) + 1;
		if (i == 0) break;
	}
	return null; 
}

// Efface le cookie nom
function dkjs_effaceCookie(nom) {
	date = new Date;
	date.setFullYear(date.getFullYear()-1);
	dkjs_ecrireCookie(nom, null, date); 
}


//_____________________________________________________________________________
//
//  GESTION MENU - ONGLETS
//_____________________________________________________________________________
//_____________________________________________________________________________
// Afficher/masquer tous les onglets
function fpjs_switchAllOnglets(bDisplay) {
	if (bDisplay) var Display = 'block';
	else var Display = 'none';

	var Tags = document.getElementsByTagName('div');
	var iMax = Tags.length;
	for (var i = 0; i < iMax; i++) {
		if (Tags.item(i).id.indexOf('onglet') == 0) Tags.item(i).style.display = Display;
	}
}
//_____________________________________________________________________________
// Afficher/masquer les onglets
function fpjs_switchOnglet(sNom) {
	var Bloc = document.getElementById(sNom).style;
	if (Bloc.display == 'none') Bloc.display = 'block';
	else Bloc.display = 'none';
}
//_____________________________________________________________________________
// Reduit ou restaure le bloc des messages d'erreurs
function dkjs_reduitRestaureDivErreur() {
	var oDiv = document.getElementById('corpsErreur');
	var style = oDiv.style.display;
	if (style == 'none') oDiv.style.display = 'block';
	else oDiv.style.display = 'none';
}

//_____________________________________________________________________________
// Gestion rollover sur une liste
function fpjs_listeRollOver(oObj, bOver) {
	var Style = oObj.style;
	if (bOver) {
		gCouleurLigne = Style.backgroundColor;
		Style.backgroundColor = '#FD9039';
		Style.cursor = 'pointer';
	} else {
		Style.backgroundColor = gCouleurLigne;
		Style.cursor = 'default';
	}
}

// Remet la couleur originale au dernier item cliqué du menu
// =>>> utilisé lorsque l'on clique sur le logo des Rousses pour revenir à l'accueil
function dkjs_decoloreItem() {
	if (gItemClique != null) {
		gItemClique.style.color = gCouleurTexte;
	}
}

// Change la couleur de l'item cliqué
// oObj : item du menu sur lequel on clique
function dkjs_itemClick(oObj) {
	if (gItemClique != null) {
		gItemClique.style.color = gCouleurTexte;
	}
	var Style = oObj.style;
	gItemClique = oObj;
	gCouleurTexte = Style.color;
	Style.color = '#000000';//'#FD9039';
}

//_____________________________________________________________________________
// Affichage message dans la barre de status
function fpjs_msg(nMsg) {
	if (nMsg == gLastMsg) return true;
	if (!isNaN(nMsg)) {
		var sMsg = gMsg[nMsg];
		gLastMsg = nMsg;
	} else {
		var sMsg = nMsg;
		gLastMsg = null;
	}
	window.status = sMsg;
	return true;
}
//_____________________________________________________________________________
//
//  GESTION AFFICHAGE - MANIP DOM
//_____________________________________________________________________________

//_____________________________________________________________________________
// Ajout d'un nouvelle image liée
// Génération par objets et méthodes DOM
// appelée depuis la fenêtre de téléchargement
// Le formulaire doit avoir une zone NbImg contenant le nombre d'images liées
// la page doit avoir une table avec un tbody (tboImg) pour l'ajout des lignes
function dkjs_uploadImgOk(sRepert, sNomFichier, sNomDisque, sImage, sTaille, sDate) {
	var NbImg = parseFloat(document.forms[0].NbImg.value);
	NbImg ++;
	document.forms[0].NbImg.value = NbImg;
	
	var ndLigne, ndCell;
	
	// ligne 1 : icone + nom + liens voir, télécharger et supprimer	
    ndLigne = document.createElement('tr');
	ndLigne.setAttribute('id','img_' + NbImg);
	
	// cellule 1 : Icone
	ndCell = document.createElement('td');
	ndCell.innerHTML = sImage;
	ndLigne.appendChild(ndCell);
	
	// cellule 2 : affichage du nom du fichier image	
	ndCell = document.createElement('td');
	ndCell.innerHTML = '<input type="text" size="57" class="saisie_non" name="img_fic_' + NbImg + '" '
		+ 'value="' + sNomFichier + '" readonly="yes">';
	ndLigne.appendChild(ndCell);
	
	// cellule 3 : icônes de lien
	ndCell = document.createElement('td');
	var Lien = '../../' + sRepert + '/' + sNomDisque;
	ndCell.innerHTML = '<a href="' + Lien + '" target="_blank">'
		+ '<img src="../images/oeil.gif" width="30" height="21" class="lien" border="0" '
		+ 'onmouseout="return fpjs_msg(0)" onmouseover="return fpjs_msg(18)" '
		+ 'title="' + gMsg[18] + '"></a>&nbsp;&nbsp;'
		+ '<img src="../images/spacer.gif" width="21">&nbsp;&nbsp;'
		+ '<img src="../images/poubelle.gif" width="16" height="22" class="lien" '
		+ 'onclick="dkjs_razImg('+ NbImg +')" onmouseout="return fpjs_msg(0)" '
		+ 'onmouseover="return fpjs_msg(17)" title="' + gMsg[17] + '">';
	ndLigne.appendChild(ndCell);
	document.getElementById('tboImg').appendChild(ndLigne);
	
	// ligne 2 : taille image, date de téléchargement et légende
	ndLigne = document.createElement('tr');
	ndLigne.setAttribute('id','img2_' + NbImg);
	
	// cellule 1 : spacer.gif => alignement
	ndCell = document.createElement('td');
	ndCell.innerHTML = '<img src="../images/spacer.gif" width="21">';
	ndLigne.appendChild(ndCell);
	
	// cellule 2 : taille image, date de téléchargement et légende
	ndCell = document.createElement('td');
	ndCell.setAttribute('colSpan','2');
	ndCell.innerHTML = 'Taille : <input type="text" name="img_taille_' + NbImg + '" size="6" class="saisie_non" readonly="yes"'
		+ 'value="' + sTaille + '">&nbsp;Téléchargée le : '
		+ '<input type="text" name="img_date_' + NbImg + '" size="10" class="saisie_non" readonly="yes"'
		+ 'value="' + sDate + '">'
		+ '<input type="hidden" name="img_dis_' + NbImg + '" value="' + sNomDisque + '">'
		+ '<br><textarea name="img_lgd_' + NbImg + '" cols="60" rows="3" class="saisie">'
		+ '</textarea>';
	ndLigne.appendChild(ndCell);
	document.getElementById('tboImg').appendChild(ndLigne);
}
//_____________________________________________________________________________
// Suppression d'une image liée
// Génération par objets et méthodes DOM
// Le formulaire doit contenir un champ caché imgToDel qui va contenir les noms des fichiers disques images à supprimer du serveur
function dkjs_razImg(nNumImg) {
	if (confirm('Confirmez-vous la suppression de l\'image ?')) {
		// mise à jour de la valeur du champ caché imgToDel
		var F = document.forms[0];
		F.imgToDel.value += '/' + F.elements['img_dis_'+nNumImg].value;
		
		var ID = 'img_' + nNumImg;
		var ndLigne = document.getElementById(ID);
		var ndTemp = document.getElementById('tboImg').removeChild(ndLigne);
		ID = 'img2_' + nNumImg;
		ndLigne = document.getElementById(ID);
		ndTemp = document.getElementById('tboImg').removeChild(ndLigne);
	}
}

//_____________________________________________________________________________
//
//  GESTION ERREURS - CONTROLES DE ZONES - MANIP
//_____________________________________________________________________________
//_____________________________________________________________________________
function fpjs_erreurZone(sZone) {
	var E =	document.forms[0].elements[sZone];
	E.style.backgroundColor = '#CBF100';
	E.focus();	
}
//_____________________________________________________________________________
// Positionne le curseur sur une zone en erreur
function fpjs_focusErreur(sNomZone) {
	try {
		document.forms[0].elements[sNomZone].focus();
	} catch(e) {
		return;
	}
}
//_____________________________________________________________________________
// Contrôle de saisie des formulaires
function fpjs_verifForm(F, OKs) {
	var E = F.elements
	for (Nom in OKs) {
        if (OKs[Nom][0] == 'date') {
            if (fpjs_verifDate(E[Nom].value) != 1) {
    			alert (OKs[Nom][1]);
    			E[Nom].focus();
    			return false;
    		}
        } else if (!OKs[Nom][0].test(E[Nom].value)) {
			alert (OKs[Nom][1]);
			E[Nom].focus();
			return false;
		}
	}
	return true;
}
//_____________________________________________________________________________
function fpjs_verifDate(laZone) {
	if (laZone.indexOf('/') != -1) var Reg = /^\d{2}\/\d{2}\/\d{4}$/;
	else if (laZone.indexOf('.') != -1) var Reg = /^\d{2}\.\d{2}\.\d{4}$/;
	else if (laZone.indexOf('-') != -1) var Reg = /^\d{2}\-\d{2}\-\d{4}$/;
	else if (laZone.indexOf(' ') != -1) var Reg = /^\d{2} \d{2} \d{4}$/;
	else var Reg = /^\d{8}$/;

	if (!laZone.match(Reg)) return -1

	var JJ, MM, AA;
	if (laZone.length > 8) {
		JJ = laZone.substring(0,2); MM = laZone.substring(3,5); AA = laZone.substring(6);
	} else {
		JJ = laZone.substring(0,2); MM = laZone.substring(2,4); AA = laZone.substring(4);
	}

	if (AA < 1900) return -2
	if (MM < 1 || MM > 12) return -2
	if (JJ < 1 || JJ > 31) return -2
	if (JJ > 30 && (MM == 4 || MM == 6 || MM == 9 || MM == 11)) return -2
	if (MM == 2) {
		Reg = ((AA % 4 == 0) && ( (!(AA % 100 == 0)) || (AA % 400 == 0) ) ) ? 29 : 28
		if (JJ > Reg) return -2
	}
	return 1
}
//_____________________________________________________________________________
function fpjs_amjJma(AMJ) {
	if (AMJ == 0) return '';
	AMJ += '';
	return AMJ.replace(/(\d{4})(\d{2})(\d{2})/,"$3/$2/$1")
}
//_____________________________________________________________________________
function fpjs_jmaAmj(JMA) {
	if (JMA.indexOf('/') != -1) return JMA.replace(/(\d{2})\/(\d{2})\/(\d{4})/,"$3$2$1");
	else if (JMA.indexOf('.') != -1) return JMA.replace(/(\d{2})\.(\d{2})\.(\d{4})/,"$3$2$1");
	else if (JMA.indexOf('-') != -1) return JMA.replace(/(\d{2})\-(\d{2})\-(\d{4})/,"$3$2$1");
	else if (JMA.indexOf(' ') != -1) return JMA.replace(/(\d{2}) (\d{2}) (\d{4})/,"$3$2$1");
	else return JMA.replace(/(\d{2})(\d{2})(\d{4})/,"$3$2$1");
}
//_____________________________________________________________________________
function dkjs_heureChiffre(monHeure) {
	var PosSep1 = monHeure.lastIndexOf(':');
	var PosSep2 = monHeure.lastIndexOf(' ');
	var PosSep3 = monHeure.lastIndexOf('-');
	var PosSep4 = monHeure.lastIndexOf('/');
	var PosSep5 = monHeure.lastIndexOf('.');
	if ((PosSep1 == -1)&&(PosSep2 == -1)&&(PosSep3 == -1)&&(PosSep4 == -1)&&(PosSep5 == -1))
	{
		return monHeure;
	}
	else
	{
		if (monHeure.length == 4)
		{
			var Heure = monHeure.substring(0,1);
			var Minute = monHeure.substring(2,4);
			var res = Heure + '' + Minute;
			return res/1;
		}
		else if (monHeure.length == 5)
		{
			var Heure = monHeure.substring(0,2);
			var Minute = monHeure.substring(3,5);
			var res = Heure + '' + Minute;
			return res/1;
		}
		return 0;
	}
}
//_____________________________________________________________________________
function dkjs_chiffreHeure(Heure) {
	if (Heure == '') return Heure;
	if (Heure == 0) return '00:00';

	var lg = Heure.length;
	var H,M;
	if (lg == 3) {
		H = Heure.substring(0,1);
		M = Heure.substring(1,lg);
	} else if (lg == 4)	{
		H = Heure.substring(0,2);
		M = Heure.substring(2,lg);
	}
	return H+':'+M;
}
//_____________________________________________________________________________
function dkjs_verifHeureValide(laZone) {
	
	if (laZone == '0') return true;
	
	var PosSep = laZone.lastIndexOf(':');
	if (PosSep == -1) PosSep = laZone.lastIndexOf(' ');
	if (PosSep == -1) PosSep = laZone.lastIndexOf('-');
	if (PosSep == -1) PosSep = laZone.lastIndexOf('/');
	if (PosSep == -1) PosSep = laZone.lastIndexOf('.');
	
	if (PosSep == -1)
	{
		if (laZone.match(/^\d{3}$/)) PosSep = 1;
		else if (laZone.match(/^\d{4}$/)) PosSep = 2;
		else return false;
	}
		
	var HH = laZone.substring(0, PosSep);
	if (HH == '') HH = '0';
	if (!HH.match(/^\d{1,2}$/)) return false;
	if (HH > 23) return false;
	
	var MM = laZone.substring(PosSep + 1);
	if (MM == '') MM = '0';
	if (!MM.match(/^\d{1,2}$/)) return false;
	if (MM > 59) return false;
	
	return true;
}
//_____________________________________________________________________________
function fpjs_arrondi(Nombre,Decimales) {
	if (!Number(Nombre)) return 0;
	if (Nombre == 0 || Decimales < 1) return 0
	var Multiplie = Math.pow(10,Decimales)
	Nombre = (Nombre * Multiplie) + 0.5
	Nombre = Math.floor(Nombre)
	Nombre = Nombre / Multiplie
	return Nombre
}

// arrondi supérieur
function dkjs_arrondiSup(Nombre,Decimales) {
	if (!Number(Nombre)) return 0;
	if (Nombre == 0 || Decimales < 1) return 0;
	var Multiplie = Math.pow(10,Decimales);
	var Resultat = (Nombre * Multiplie) + 0.5;
	Resultat = Math.floor(Resultat);
	Resultat = Resultat / Multiplie;
	if (Resultat < Nombre) Resultat = Resultat + (1/Multiplie); 
	return Resultat;
}

/*
 * Arrondit un prix (2 décimales) aux cinq centimes les plus proches (1.82 => 1.80 et 1.83 => 1.85)
 *
 * @param float $Prix Prix à arrondir
 * @return float prix arrondi et formaté
 */
function dkjs_arronditCinqCentimes(Prix) {
	Prix = Prix * 10;
	PrixArrondi = Math.round(Prix);
	PrixFloor = Math.floor(Prix);
	if (PrixArrondi == PrixFloor) {
		if ((Prix - PrixArrondi) > 0.2) Prix = PrixArrondi + 0.5;
		else Prix = PrixArrondi;
	} else {
		if ((PrixArrondi - Prix) > 0.2) Prix = PrixFloor + 0.5;
		else Prix = PrixArrondi;
	}
	Prix = Prix / 10;
	return fpjs_formatNombre(Prix);
}
//_____________________________________________________________________________
function fpjs_formatNombre(Nombre) {
	if (!Number(Nombre)) return '0.00';
	var neg = 0;
	if (Nombre < 0) {neg = 1; Nombre = Nombre * -1;}//return Nombre;
	Nombre = dkjs_arrondiSup(Nombre,2);
	Nombre = '' + parseInt(dkjs_arrondiSup(Nombre * 100, 2));
	if (Nombre < 10) Nombre = '00' + Nombre
	else if (Nombre < 100) Nombre = '0' + Nombre
	return ((neg == 1) ? '-' : '')+Nombre.substring(0, Nombre.length - 2)+ '.'+Nombre.substring(Nombre.length - 2);
}

// Renvoie nb sous forme d'entier. Si jamais nb n'est pas un nombre la fonction renvoie 0
function dkjs_integer(nb) {
	var res = parseInt(nb);
	if (isNaN(res)) res = 0;
	return res;
}

// Renvoie nb sous forme de float. Si jamais nb n'est pas un nombre la fonction renvoie 0
function dkjs_float(nb) {
	var res = parseFloat(nb);
	if (isNaN(res)) res = 0;
	return res;
}
//_____________________________________________________________________________
//
//  OBJET xDHTML - Gestion des blocs
//_____________________________________________________________________________
// Spécial NS 4
function xGetBloc(oDoc, Nom) {
	for (var i = 0; i < oDoc.layers.length; i++) {
		if (oDoc.layers[i].id == Nom) {
			return oDoc.layers[i]
		} else {
			var Bloc = xGetBloc(oDoc.layers[i].document, Nom)
			if (Bloc != null) return Bloc
		}
	}
	return null
}

function xDhtml(NomBloc) {
	// Propriétés
	if (document.layers) {
		this.xMontrer = 'show'; this.xCacher = 'hide'
		this.xUnite = ''
	} else {
		this.xMontrer = 'visible'; this.xCacher = 'hidden'
		this.xUnite = 'px'
	}
	if (document.getElementById) {
		this.leBloc = document.getElementById(NomBloc)
		this.leStyle = this.leBloc.style
	} else  if (document.all) {
		this.leBloc = document.all[NomBloc]
		this.leStyle = this.leBloc.style
	} else if (document.layers) {
		this.leBloc = this.leStyle = xGetBloc(document, NomBloc)
	} else {
		this.leBloc = this.leStyle = null
	}

	return this;
}

xDhtml.prototype.setVisible = function(Quoi) { 
	if (!this.leStyle) return
	if (Quoi == 0) this.leStyle.visibility = this.xCacher
	else if (Quoi == 1) this.leStyle.visibility = this.xMontrer
	else if (Quoi == 2) {
		if (this.leStyle.visibility == this.xMontrer) this.leStyle.visibility = this.xCacher
		else this.leStyle.visibility = this.xMontrer
	}
}

xDhtml.prototype.getVisible = function () {
	if (this.leStyle) return (this.leStyle.visibility == this.xMontrer)
	else return 0
}

xDhtml.prototype.getTop = function () {
	if (this.leStyle) return parseFloat(this.leStyle.pixelTop)
	else return 0
}

xDhtml.prototype.getLeft = function () {
	if (this.leStyle) return parseFloat(this.leStyle.pixelLeft)
	else return 0
}

xDhtml.prototype.getWidth = function () {
	if (document.getElementById || document.all) return this.leBloc.scrollWidth
	if (document.layers) return this.leBloc.document.width
	return 0
}

xDhtml.prototype.getHeight = function () {
	if (document.getElementById || document.all) return this.leBloc.scrollHeight
	if (document.layers) return this.leBloc.document.height
	return 0
}

xDhtml.prototype.moveTo = function (nX,nY) {
	if (this.leStyle) {
		this.leStyle.left = nX + this.xUnite
		this.leStyle.top = nY + this.xUnite
	}
}
//_____________________________________________________________________________
//
//  OBJET xDHTML - xEvent - Gestion des événements
//_____________________________________________________________________________
function xEvent() {
	// Déterminer le navigateur
	this.I5 = this.I4 = this.IE = false;
	this.N4 = this.N6 = this.NS = false
	if (document.all && document.getElementById) this.I5 = true
	else if (document.all) this.I4 = true
	else if (document.layers) this.N4 = true
	else if (document.getElementById) this.N6 = true
	this.IE = this.I4 || this.I5
	this.NS = this.N4 || this.N6
	// Si Doctype avec IE6, on doit travailler avec html et pas body
	try {
		var Tmp = document.getElementsByTagName('html');
		this.nodeRef = Tmp.item(0);
	} catch(e) {
		this.nodeRef = document.body;
	}
	return this
}   
  
xEvent.prototype.add = function(Nom, Fonction) {
	if (this.IE) {
		eval('document.on' + Nom + '= Fonction')
	} else if (this.N6) {
		document.addEventListener(Nom ,Fonction ,false)
	} else if (oE.N4) {
		eval('document.captureEvents(Event.' + Nom.toUpperCase() + ')')
		eval('document.on' + Nom + ' = Fonction')
	}
}

xEvent.prototype.pageX = function(e) {
	if (this.IE) return event.clientX + this.nodeRef.scrollLeft;
	else if (this.NS) return e.pageX
	return 0;
}
xEvent.prototype.pageY = function(e) {
	if (this.IE) return event.clientY + this.nodeRef.scrollTop;
	else if (this.NS) return e.pageY
	return 0;
}   
xEvent.prototype.offsetX = function(e) {
  if (this.IE) return event.offsetX 
  else if (this.N6) return e.offsetX
  else if (this.N4) return e.layerX
  return 0;
}
xEvent.prototype.offsetY = function(e) {
  if (this.IE) return event.offsetY 
  else if (this.N6) return e.offsetY
  else if (this.N4) return e.layerY
  return 0;
}   
//_____________________________________________________________________________
//
//  OBJET oCalendrier - Calendrier perpétuel
//_____________________________________________________________________________
function oCalendrier(sNomObjet) {
	this.NomObjet = sNomObjet;
	this.Zone = null;
	this.Fenetre = null;
	this.Mois = 0;
	this.Annee = 0;
	this.JourEnCours = 0;
	this.MoisEnCours = 0;
	this.AnEnCours = 0;
	var d = new Date()
	this.AnneePivot = d.getFullYear();
    this.RemplaceSaisie = true;
	this.NomMois = new Array('Janv','Fév','Mars','Avr','Mai','Juin','Juil','Aout','Sept','Oct','Nov','Déc');
	this.NbJour = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	//this.NomJour = new Array('Dim','Lun','Mar','Mer','Jeu','Ven','Sam');
	//this.NomJour = new Array('L','M','M','J','V','S','D');
	this.NomJour = new Array('S','D','L','M','M','J','V');
	
	//this.NomZone = '';
	
	return this;
}

oCalendrier.prototype.setRemplaceSaisie = function(VraiFaux) {
    this.RemplaceSaisie = VraiFaux;
}

oCalendrier.prototype.setZone = function(sNomZone) {
	this.NomZone = sNomZone;
}

oCalendrier.prototype.click = function(nJour) {
	if (this.NomZone != null) {
        var laDate = ( (nJour < 10) ? '0':'' ) + nJour + '/'
					+ ( ((this.Mois + 1) < 10) ? '0':'' ) + (this.Mois + 1) + '/'
					+ this.Annee;
        if (this.RemplaceSaisie) this.NomZone.value = laDate;
        else this.NomZone.value += laDate;
	}
	this.Fenetre.close();
}

oCalendrier.prototype.affiche = function(nQuoi, sNomZone) {
	if (nQuoi == -1) {
		this.Mois --;
		if (this.Mois < 0) {
			this.Mois = 11; this.Annee --;
		}
	} else if (nQuoi == -2) {
		this.Mois ++;
		if (this.Mois > 11) {
			this.Mois = 0; this.Annee ++;
		}
	} else if (nQuoi == null) { // change mois ou annee
		var f = window.document.forms[0];
		this.Mois = parseFloat(f.selMois.options[f.selMois.selectedIndex].value);
		this.Annee = parseFloat(f.selAnnee.options[f.selAnnee.selectedIndex].value);
	} else if (nQuoi == '' || nQuoi == 0) {  //Init sur la date du jour
		var d = new Date()
		this.MoisEnCours = d.getMonth();
		this.AnEnCours = d.getFullYear();
		this.JourEnCours = d.getDate();
		this.Annee = this.AnEnCours;
		this.Mois = this.MoisEnCours;
	} else {  // recoit une date jjmmaaaa avec ou sans sépararteurs
		var AMJ = this.verifDate(nQuoi);
		if (AMJ == false) {
			var d = new Date()
			this.MoisEnCours = d.getMonth();
			this.AnEnCours = d.getFullYear();
			this.JourEnCours = d.getDate();
		} else {
			this.AnEnCours = AMJ[0];
			this.MoisEnCours = AMJ[1] - 1;
			this.JourEnCours = AMJ[2];
		}
		this.Annee = this.AnEnCours;
		this.Mois = this.MoisEnCours;
	}
	if (sNomZone != null) this.NomZone = sNomZone;
	this.afficheCalendrier();
}

oCalendrier.prototype.afficheInterieur = function(nQuoi, sNomZone) {
	if (nQuoi == -1) {
		this.Mois --;
		if (this.Mois < 0) {
			this.Mois = 11; this.Annee --;
		}
	} else if (nQuoi == -2) {
		this.Mois ++;
		if (this.Mois > 11) {
			this.Mois = 0; this.Annee ++;
		}
	} else if (nQuoi == null) { // change mois ou annee
		var f = window.document.forms[0];
		this.Mois = parseFloat(f.selMois.options[f.selMois.selectedIndex].value);
		this.Annee = parseFloat(f.selAnnee.options[f.selAnnee.selectedIndex].value);
	} else if (nQuoi == '' || nQuoi == 0) {  //Init sur la date du jour
		var d = new Date()
		this.MoisEnCours = d.getMonth();
		this.AnEnCours = d.getFullYear();
		this.JourEnCours = d.getDate();
		this.Annee = this.AnEnCours;
		this.Mois = this.MoisEnCours;
	} else {  // recoit une date jjmmaaaa avec ou sans sépararteurs
		var AMJ = this.verifDate(nQuoi);
		if (AMJ == false) {
			var d = new Date()
			this.MoisEnCours = d.getMonth();
			this.AnEnCours = d.getFullYear();
			this.JourEnCours = d.getDate();
		} else {
			this.AnEnCours = AMJ[0];
			this.MoisEnCours = AMJ[1] - 1;
			this.JourEnCours = AMJ[2];
		}
		this.Annee = this.AnEnCours;
		this.Mois = this.MoisEnCours;
	}
	if (sNomZone != null) this.NomZone = sNomZone;
	//this.ouvreFenetre();
	this.afficheCalendrier();
}

oCalendrier.prototype.ouvreFenetre = function() {
	if (this.Fenetre == null || this.Fenetre.closed) {
		var sOption = 'resizable, width=160,height=180';
		nLeft = ((screen.width - 160) / 2) - 10;
		nTop = ((screen.height - 160) / 2) - 30;
		sOption += ',left=' + nLeft + ',screenX=' + nLeft;
		sOption += ',top=' + nTop + ',screenY=' + nTop;
		this.Fenetre = window.open('', 'tbatgcal', sOption);
	}
	this.Fenetre.focus();
}

oCalendrier.prototype.afficheFenetre = function() {
	//if (this.Annee == this.AnEnCours && this.Mois == this.MoisEnCours) var CeJour = this.JourEnCours;
	//else var CeJour = -1;
	var CeJour = this.JourEnCours;
	var Html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
		+ '<html><head><title>Calendrier</title>'
		+ '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'
		+ '<style type="text/css">'
		+ 'a {text-decoration: none; color: #FFF}'
		+ '.caltable {border-bottom: 1px #000 solid;border-right: 1px #000 solid;}'
		+ '.caltd, .calautremois, .caljour, .calcejour, .calweekend {font: 11px Verdana, sans-serif; border-top: 1px #000 solid; border-left: 1px #000 solid; padding: 2px}'
		+ '.calautremois {color: #666666;}'
		+ '.caljour {background-color: #BFA97D}'
		+ '.calcejour {background-color: #BFA97D}'
		+ '.calweekend {background-color: #BBB}'
		+ '.big {font: bold 17px Verdana}'
		+ 'select, option {font: 8pt Verdana, sans-serif; background-color: #FFF; }'
		+ '</style>'
		+ '<script language="javascript">'
		+ 'function fpjs_rollOver(oObj, bOver) {'
		+ '	var Style = oObj.style;'
		+ '	if (bOver) {'
		+ '		gCouleurLigne = Style.backgroundColor;'
		+ '		Style.backgroundColor = "#FD9039";'
		+ '	} else {'
		+ '		Style.backgroundColor = gCouleurLigne;'
		+ '	}'
		+ '}'
		+ '</sc'
		+ 'ript></head><body><form>'
		+ '<table cellspacing="0" border="0" cellpadding="0" align="center"><tr><td class="big">'
		+ '<a href="javascript:opener.' + this.NomObjet + '.affiche(-1)">&lt;</a></td>'
		+ '<td align="center" nowrap><select name="selMois" '
		+ 'onchange="opener.' + this.NomObjet + '.affiche(null)">';

	for (var i = 0; i < 12; i++) {
		Html += '<option value="' + i +'"';
		if (i == this.Mois) Html += ' selected="yes"';
		Html += '>' + this.NomMois[i] + '</option>';
	}
	Html += '</select><select name="selAnnee" '
		+ 'onchange="opener.' + this.NomObjet + '.affiche(null)">';

	if (this.Annee < this.AnneePivot) var Debut = this.Annee - 10;
	else var Debut = this.AnneePivot - 10;
	if (this.Annee > this.AnneePivot) var Fin = this.Annee + 11;
	else var Fin = this.AnneePivot + 11;
	for (var i = Debut; i < Fin; i++) {
		Html += '<option value="' + i +'"';
		if (i == this.Annee) Html += ' selected="yes"';
		Html += '>' + i + '</option>';
	}
	Html += '</select></td>'
		+ '<td class="big"><a href="javascript:opener.' + this.NomObjet + '.affiche(-2)">&gt;</a></b></td>'
		+ '</td></tr>';

	// Ligne 2 : le calendrier
	var Debut = new Date(this.Annee,this.Mois,1);
	Debut = Debut.getDay() - 1;
	if (Debut < 0) Debut = 6
	// test année bisex
	this.NbJour[1] = 28;
	if (((this.Annee % 4 == 0) && (this.Annee % 100 != 0)) || (this.Annee % 400 == 0)) this.NbJour[1] = 29; 
	var Colonne = 0;
	var DernierMois = this.Mois - 1;
	if (DernierMois < 0) DernierMois = 11;
	
	Html +='<tr><td align="center" colspan="3">'
		+ '<table cellspacing="0" class="caltable">'
		+'<tr bgcolor="#DEB969">';
		
	for (i=0; i<7; i++) {
		Html += '<td class="caltd"><b>' + this.NomJour[i] +'</b></td>';
	}
	Html += '</tr>'
		+ '<tr align="center">';
		
	// Derniers jours du mois précédent
	for (i = 0; i < Debut; i++, Colonne++){
		Html += '<td class="calautremois">' + (this.NbJour[DernierMois] - Debut + i + 1) + '</td>';
	}
	// Jours du mois
	for (i = 1; i <= this.NbJour[this.Mois]; i++, Colonne++) {
		if (i == CeJour) Html += '<td class="calcejour" ';
		else if(Colonne < 5) Html += '<td class="caljour" ';
		else Html += '<td class="calweekend" ';
		
		Html += 'onmouseover="fpjs_rollOver(this, true)" '
			+ 'onmouseout="fpjs_rollOver(this, false)">'
			+ '<a href="javascript:opener.' + this.NomObjet + '.click(' + i + ')">'
			+ i +'</a></td>';
		if (Colonne == 6) {
			Html += '</tr><tr align="center">';
			Colonne = -1;
		}
	}
	// Premiers jours du mois suivant
	if (Colonne > 0) {
		for (i = 1; Colonne < 7; i++, Colonne++){
			Html += '<td class="calautremois">' + i + '</td>';
		}
	}

	Html += '</tr></table>'
		+ '</td></tr></table></form></body></html>';

	with(this.Fenetre.document) {
		open()
		write(Html);
		close();
	}	
}

oCalendrier.prototype.afficheCalendrier = function() {
	
	//if (this.Annee == this.AnEnCours && this.Mois == this.MoisEnCours) var CeJour = this.JourEnCours;
	//else var CeJour = -1;
	var CeJour = this.JourEnCours;
	
	var Html = '<table cellspacing="0" border="0" cellpadding="0" align="center"><tr><td class="big">'
		+ '<a href="javascript:' + this.NomObjet + '.affiche(-1)">&lt;</a></td>'
		+ '<td align="center" nowrap><select name="selMois" class="champFormu" '
		+ 'onchange="' + this.NomObjet + '.affiche(null)">';

	for (var i = 0; i < 12; i++) {
		Html += '<option value="' + i +'"';
		if (i == this.Mois) Html += ' selected="yes"';
		Html += '>' + this.NomMois[i] + '</option>';
	}
	Html += '</select><select name="selAnnee" class="champFormu" '
		+ 'onchange="' + this.NomObjet + '.affiche(null)">';

	if (this.Annee < this.AnneePivot) var Debut = this.Annee - 10;
	else var Debut = this.AnneePivot - 10;
	if (this.Annee > this.AnneePivot) var Fin = this.Annee + 11;
	else var Fin = this.AnneePivot + 11;
	for (var i = Debut; i < Fin; i++) {
		Html += '<option value="' + i +'"';
		if (i == this.Annee) Html += ' selected="yes"';
		Html += '>' + i + '</option>';
	}
	Html += '</select></td>'
		+ '<td class="big"><a href="javascript:' + this.NomObjet + '.affiche(-2)">&gt;</a></b></td>'
		+ '</td></tr>';

	// Ligne 2 : le calendrier
	var Debut = new Date(this.Annee,this.Mois,1);
	Debut = Debut.getDay() - 1;
	alert(Debut);
	if (Debut < 0) Debut = 6
	
	// test année bisex
	this.NbJour[1] = 28;
	if (((this.Annee % 4 == 0) && (this.Annee % 100 != 0)) || (this.Annee % 400 == 0)) this.NbJour[1] = 29; 
	var Colonne = 0;
	var DernierMois = this.Mois - 1;
	if (DernierMois < 0) DernierMois = 11;
	
	Html +='<tr><td align="center" colspan="3">'
		+ '<table cellspacing="0" class="caltable">'
		+'<tr bgcolor="DEB969">';
		
	for (i=0; i<7; i++) {
		Html += '<td class="caltd" ';
		if (i==5){
			Html += 'bgcolor="#AC4601"';
		}
		Html += '><b>' + this.NomJour[i] +'</b></td>';
	}
	Html += '</tr>'
		+ '<tr align="center">';
		
	// Derniers jours du mois précédent
	for (i = 0; i < Debut; i++, Colonne++){
		Html += '<td class="calautremois">' + (this.NbJour[DernierMois] - Debut + i + 1) + '</td>';
	}
		

	// Jours du mois
	for (i = 1; i <= this.NbJour[this.Mois]; i++, Colonne++) {
		if (i == CeJour) {
			Html += '<td class="calcejour" ';
		}else{
			if(Colonne < 5) {
				Html += '<td class="caljour" ';
			}else{
				if(Colonne == 6) {
					Html += '<td class="caljour" ';
				}else{
					Html += '<td class="calweekend" ';
				}
			}
		}
		
		Html += 'onmouseover="fpjs_rollOver(this, true)" '
			+ 'onmouseout="fpjs_rollOver(this, false)">'
			+ '<a href="javascript:' + this.NomObjet + '.click(' + i + ')">|'
			+ i +'</a></td>';
		if (Colonne == 6) {
			Html += '</tr><tr align="center">';
			Colonne = -1;
		}
	}
	// Premiers jours du mois suivant
	if (Colonne > 0) {
		for (i = 1; Colonne < 7; i++, Colonne++){
			Html += '<td class="calautremois">' + i + '</td>';
		}
	}

	Html += '</tr></table>'
		+ '</td></tr></table>';

	alert(Html);
	document.getElementById('calendrier').innerHTML = Html;
}

oCalendrier.prototype.verifDate = function(laZone) {
	if (laZone.indexOf('/') != -1) var Reg = /^\d{2}\/\d{2}\/\d{4}$/;
	else if (laZone.indexOf('.') != -1) var Reg = /^\d{2}\.\d{2}\.\d{4}$/;
	else if (laZone.indexOf('-') != -1) var Reg = /^\d{2}\-\d{2}\-\d{4}$/;
	else if (laZone.indexOf(' ') != -1) var Reg = /^\d{2} \d{2} \d{4}$/;
	else var Reg = /^\d{8}$/;
	
	if (!laZone.match(Reg)) return false;

	var JJ, MM, AA;
	if (laZone.length > 8) {
		JJ = laZone.substring(0,2); MM = laZone.substring(3,5); AA = laZone.substring(6);
	} else {
		JJ = laZone.substring(0,2); MM = laZone.substring(2,4); AA = laZone.substring(4);
	}

	JJ = Number(JJ);
	MM = Number(MM);
	AA = Number(AA);

	//if (AA < 2001) return -2
	if (MM < 1 || MM > 12) return false;
	if (JJ < 1 || JJ > 31) return false;
	if (JJ > 30 && (MM == 4 || MM == 6 || MM == 9 || MM == 11)) return false;
	if (MM == 2) {
		Reg = ((AA % 4 == 0) && ( (!(AA % 100 == 0)) || (AA % 400 == 0) ) ) ? 29 : 28;
		if (JJ > Reg) return false;
	}
	var Tmp = new Array(AA,MM,JJ);
	return Tmp;
}

// === FIN Objet calendrier

//_____________________________________________________________________________
//
//  GESTION LISTES DEROULANTES (Familles, sous-familles, produits
//_____________________________________________________________________________

// Met à jour la liste des sous-familles en fonction de l'id famille passé en paramètre
function dkjs_majListeSF(idF, libOption0) {
	var listeSF = document.forms[0].listeSsFamille;
	var itemSF = 1;
	listeSF.length = 0;
	dkjs_addOption(listeSF, 0, 0, libOption0);
	// clic sur l'option "Affiner par famille" de la liste des familles
	if (idF == 0) {
		for (cle in tabSousFamilles) {
			dkjs_addOption(listeSF, itemSF, cle, tabSousFamilles[cle][0]);
			itemSF++;
		} 
	} else {
		for (cle in tabSousFamilles) {
			if (tabSousFamilles[cle][1] == idF) {
				dkjs_addOption(listeSF, itemSF, cle, tabSousFamilles[cle][0]);
				itemSF++;
			}
		} 
	}
	if (itemSF == 1) listeSF.options[0].text = 'Pas de sous-famille pour cette famille';
}

// Met à jour la liste des produits en fonction de l'id famille ou sous-famille passé en paramètre
// listeChange contient F (si evt onChange sur la liste des familles) ou SF (si evt onChange sur la liste des sous-familles) 
function dkjs_majListeProduit(id, listeChange,libOption0) {
	var listeProduit = document.forms[0].listeProduit;
	var itemP = 1;
	
	listeProduit.length = 0;
	dkjs_addOption(listeProduit, 0, 0, libOption0);
	// clic sur l'option "Affiner par sous-famille" de la liste des sous-familles ou sur l'option "Affiner par famille" de la liste des familles
	if (id == 0) {
		for (cle in tabProduits) {
			dkjs_addOption(listeProduit, itemP, cle, tabProduits[cle][0]);
			itemP++;
		}
	} else {
		var ind;
		if (listeChange == 'F') ind = 2;
		else ind = 1;
		for (cle in tabProduits) {
			if (tabProduits[cle][ind] == id) {
				dkjs_addOption(listeProduit, itemP, cle, tabProduits[cle][0]);
				itemP++;
			}
		} 
	}
	if (itemP == 1) listeProduit.options[0].text = 'Pas de produit';
}

// Ajoute une option à la liste liste à l'indice ind.
// val : valeur de l'option
// lib : libellé de l'option
function dkjs_addOption(liste, ind, val, lib) {
	liste.length += 1;
	liste.options[ind].value = val;
	liste.options[ind].text = lib;
}
//_____________________________________________________________________________
//
//  GESTION DE FICHIER
//_____________________________________________________________________________
// Création d'une ligne comportant les infos sur le fichier de rattachement compta créé
// + lien pour le téléchargement
function ljs_generePnm(sRepert, sNomFichier, sNomDisque, sImage, sTaille, sDate, sTypeCrypte, sFichierCrypte) {
	var ndLigne, ndCell;
	
	// ligne 1 : icone + nom + liens voir, télécharger et supprimer	
    ndLigne = document.createElement('tr');
	ndLigne.setAttribute('id','pnm');
	
	// cellule 1 : Icone
	ndCell = document.createElement('td');
	ndCell.setAttribute('width','20');
	ndCell.innerHTML = sImage;
	ndLigne.appendChild(ndCell);
	
	// cellule 2 : affichage du nom du fichier image	
	ndCell = document.createElement('td');
	ndCell.setAttribute('width','140');
	ndCell.innerHTML = '<input type="text" size="20" class="saisie_non" name="pnm_vente" '
		+ 'value="' + sNomFichier + '" readonly="yes">';
	ndLigne.appendChild(ndCell);
	
	// cellule 3 : taille image, date de téléchargement et légende
	ndCell = document.createElement('td');
	ndCell.innerHTML = 'Taille : <input type="text" name="pnm_taille" size="10" class="saisie_non" readonly="yes"'
		+ 'value="' + sTaille + '">&nbsp;Généré le : '
		+ '<input type="text" name="pnm_date" size="10" class="saisie_non" readonly="yes"'
		+ 'value="' + sDate + '">'
		+ '<input type="hidden" name="pnm_dis" value="' + sNomDisque + '">';
	ndLigne.appendChild(ndCell);

	// cellule 4 : icônes de lien
	ndCell = document.createElement('td');
	ndCell.setAttribute('width','120');
	ndCell.setAttribute('align','left');
	ndCell.style.textAlign = 'left';
	var Lien = '../../' + sRepert + '/' + sNomDisque;
	ndCell.innerHTML = '<a href="' + Lien + '" target="_blank">'
		+ '<img src="../images/oeil.gif" width="30" height="21" class="lien" border="0" '
		+ 'onmouseout="return fpjs_msg(0)" onmouseover="return fpjs_msg(30)" '
		+ 'title="' + gMsg[30] + '"></a>&nbsp;&nbsp;'
		+ '<img src="../images/telecharge.gif" width="23" height="26" class="lien" '
		+ 'onclick="fpjs_downloadDoc(\'' + sTypeCrypte + '\',\'' + sFichierCrypte + '\')" onmouseout="return fpjs_msg(0)" '
		+ 'onmouseover="return fpjs_msg(31)" title="' + gMsg[31] + '">&nbsp;&nbsp;';
	ndLigne.appendChild(ndCell);
	document.getElementById('tboPnm').appendChild(ndLigne);
}


//_____________________________________________________________________________
//
//  INITIALISATIONS
//_____________________________________________________________________________
var gPopUpWin = null;
var gPopUpUrl = '';
var gLastMsg = '-1';
var gCouleurLigne = null; // sauvegarde de la couleur originale de la ligne lors d'un roll-over sur une liste
var gCouleurTexte = null; // sauvegarde de la couleur originale du texte d'un item du menu lors du clic sur cet item
var gItemClique = null;   // sauvegarde de l'item du menu sur lequel on clique afin de pouvoir réinitialiser sa couleur
var gBlocErreur = null;  // div contenant les messages d'erreurs
var gObjCalendrier = null;
var gNomListe = null; // Nom de la zone de liste à mettre à jour lors de l'ajout dynamique d'une option

// Messages types
var gMsg = new Array();
gMsg[0] = "";
gMsg[1] = "Trier la liste suivant cette colonne - ordre croissant";
gMsg[2] = "Modifier ou supprimer l'élément";
gMsg[3] = "Saisir des critères de recherche";
gMsg[4] = "Liste des éléments trouvés";
gMsg[5] = "Saisir des informations";
gMsg[6] = " ";
gMsg[7] = "Afficher/masquer le menu";
gMsg[8] = "Calendrier perpétuel";
gMsg[9] = "Cliquez pour vous positionner sur l'erreur";
gMsg[15] = "Modifier la ligne";
gMsg[16] = "Supprimer la ligne";
gMsg[17] = "Supprimer l'image";
gMsg[18] = "Afficher l'image";
gMsg[19] = "Télécharger l'image";
gMsg[21] = "Lister les éléments dont le nom commence par cette lettre";
gMsg[22] = "Afficher tous les onglets";
gMsg[23] = "Masquer tous les onglets";
gMsg[30] = "Afficher le document";
gMsg[31] = "Télécharger le document";
gMsg[32] = "Supprimer le document";
gMsg[33] = "Actualiser le document";
gMsg[36] = "Déplacer la ligne vers le haut";
gMsg[37] = "Déplacer la ligne vers le bas";
gMsg[51] = "Trier la liste suivant cette colonne - ordre décroissant";
gMsg[60] = "Editer la liste des participants";

onload = fpjs_initPage;
onunload = fpjs_quitter;
//document.oncontextmenu = function(){return false;};

//_____________________________________________________________________________
//
//  INITIALISATIONS
//_____________________________________________________________________________
// Affichage d'un niveau (ie tous les projets, toutes les taches, etc.)
// on affiche tous les niveaux supérieurs et le niveau
// on masque tous les niveaux inférieurs
// Code : NiveauAAfficher_IDElement
function ljs_switchNiveau(Code) {
    var Cles = Code.split('_');
    //var Nb = parseInt(Cles[0]) + 1;
    var ndNodes = document.getElementById('tbl_' + Cles[0] + '_' + Cles[1]).childNodes;
    var iMax = ndNodes.length;
    for (var i = 0; i < iMax; i++) {
        var Tmp = ndNodes[i].id.split('_');
        if (ndNodes[i].id) {
					if (ndNodes[i].style.display=="none") {
						ndNodes[i].style.display = 'block';
					}else{
						ndNodes[i].style.display = 'none';
					}
				}
    }
}
// Switch affichage des lignes des niveaux.
// En affichage, on affiche que les niveaux directement inférieurs.
// En masquage, on masque tous les niveaux inférieurs.
function ljs_switchTable(NomBloc) {
    var Cles = NomBloc.split('_');
    var Nb = Cles.length + 1;
    var ndNodes = document.getElementById('tbl_' + Cles[0] + '_').childNodes;
    var iMax = ndNodes.length;
    var Affiche = '';
    for (var i = 0; i < iMax; i++) {
        if (ndNodes[i].id == NomBloc) continue;
        if (ndNodes[i].id.indexOf(NomBloc) == 0) {
            if (Affiche == '') {
                if (ndNodes[i].style.display == 'none') Affiche = 'block';
                else Affiche = 'none';
            }
            if (Affiche == 'none') {  // on ferme tout ce qui est en-dessous et ouvert
                ndNodes[i].style.display = Affiche;
            } else {  // on ouvre que le niveau directement inférieur
                var Tmp = ndNodes[i].id.split('_');
                if (Tmp.length == Nb) ndNodes[i].style.display = Affiche;
            }
        }
    }
}

// Gestion rollover sur une liste
function ljs_listeRollOver(oObj, bOver) {
	var Style = oObj.style;
	if (bOver) {
		gCouleurLigne = Style.backgroundColor;
		Style.backgroundColor = '#ebebeb';
	} else {
		Style.backgroundColor = gCouleurLigne;
	}
}

function pixel(img) {
	if(img && img.filters && img.filters[0]) {
		img.filters[0].apply();
		img.filters[0].play();
	}
}

