
function TehmsNavigateur(){
	
	var self;
	var dall;
	var geid;
	
	var history;
	var icons;

	
	var offsetxpoint=0
	var offsetypoint=20
	var infosDisplayed = false;
	var divInfos;
	var divPopup;
	
	
	var ouverts = new Array();
	
	this.init = function(title){
		
		dall=document.all;
		geid=(document.getElementById && !document.all);
		self = this;
		
		history = new Array();
		icons = new Array();
		
		document.onmousemove=this.mousePosition;
		
		document.write('<div id="tnDivInfos" class="tnDivInfos" style="display:block;visibility:hidden;z-index:200;">-</div>');
		document.write('<div id="tnDivTestWidth" style="position:absolute;top:-50;left;0;visibility:hidden;z-index:100;">-</div>');
		divInfos = document.getElementById("tnDivInfos");
		document.write('<div id="tnDivConfirm" class="tnConfirm" style="z-index:100;">-</div>');
		divPopup = document.getElementById('tnDivConfirm');
		document.write('<div id="tnDivUpload" style="display:none;position:absolute;top:0px;left:0px;width:400px;height:200px;"><iframe id="tnIFrameUpload" name="tnIFrameUpload"></iframe></div>');
		
		
		document.write('<div id="popupNiveau" class="popupNiveau" style="border:1px outset blue;background-color:#FFFFFF;display:none;z-index:200;position:absolute;top:0px;left:0px;">-</div>');
	
		// Navigateur
		document.write('<table class="tnNavigateur" cellspacing="0">');
			
			// Titre
			document.write('<tr>');
				document.write('<td id="tnTitre" colspan="2">');
					document.write(title);
				document.write('</td>');
			document.write('</tr>');
			
			// Cadres
			document.write('<tr>');
				document.write('<td id="tnCadreArborescence">');
					document.write('<div id="tnIconesArborescence"></div>');
					document.write('<div id="tnArborescence">&nbsp;</div>');
				document.write('</td>');
				document.write('<td id="tnCadreDetail">');
					document.write('<div id="tnIconesDetail"></div>');
					document.write('<div id="tnDetail">&nbsp;</div>');
				document.write('</td>');
			document.write('</tr>');
			
		document.write('</table>');
		
		
		
	}
	
	
	//////////////////////////////////////////////////////
	// Requests management
	//////////////////////////////////////////////////////
	
	this.load = function(element_id,url,message)
	{
		
		if( !message ) message = '<div class="tnChargement">Chargement en cours...</div>';
		var req = null; 
		var div = document.getElementById(element_id);
		var memoire = div.innerHTML;
		
		
		div.innerHTML=message;
		if(window.XMLHttpRequest)
			req = new XMLHttpRequest(); 
		else if (window.ActiveXObject)
			req  = new ActiveXObject("Microsoft.XMLHTTP"); 
		
		req.onreadystatechange = function()
		{ 
			div.innerHTML=message;
			if(req.readyState == 4)
			{
				switch( req.status ){
					case 12029: // Erreurs de proxy ou firewall, on reessaie la requete 3 fois
				    case 12030:
				    case 12031:
				    case 12152:
				    case 12159:
				    	div.innerHTML = '<div class="tnChargement">Vous rencontrez des probl&egrave;mes de connexion &agrave; cause d\'un proxy ou d\'un par-feu. <br/>Pour plus de renseignement, contactez votre administrateur ou Tehms &agrave; l\'adresse contact@tehms.com</div>';
				    break;
				    
				    case 200: // Reponse positive
				    	
			    		var header_debut = req.responseText.substring(0,47);
			    		
			    		if( header_debut == "<div class=\"tehmsheader\" style=\"display:none;\">" ){
				    		var header_fin = req.responseText.substring(47).indexOf("</div>\n\n\n\n") + 47;
				    		var header_contenu = req.responseText.substring(47,header_fin);
				    		var header_text = req.responseText.substring(51,header_fin);
							var page_html = req.responseText.substring(header_fin + 9);
			    			var code = header_contenu.substring(0,4);
							code = parseInt(code,10);
							switch( code ){
						    	case 201: // Execution automatique d'un script
						    		self.clearIcons(element_id);
							    	div.innerHTML=page_html;
							    	self.limitWidthName('limitedText',200);
							    	eval(header_text);
							    	self.saveHistory(element_id,url,page_html);
							    break;
							    case 3001: // LOGIN
							    	document.location.href="index.php5";
							    break;
							   	default:	// Autre code d'erreur, on affiche le formulaire de retour de bug
							    	document.tehms.popup('<div class="tnChargement">' + header_text + '<br/><br/><a href="#" onclick="popup(\'erreur\',\'index.php5?module=portail&amp;page=saisie_erreur&amp;libelle='+(code + ' : ' + header_text.replace(/\'/g,'\\\''))+'&url='+encodeURIComponent(url)+'\');return false;" style="font-style:italic;font-size:11px;">Cette erreur vous semble anormale ? <br/>Contactez le support technique en cliquant ici</a></div>','');
							    	div.innerHTML = memoire;
							    break;
							}
			    		}else{
			    			self.clearIcons(element_id);
			    			div.innerHTML=req.responseText;
			    			self.limitWidthName('limitedText',200);
			    			self.saveHistory(element_id,url,req.responseText);
			    		}
			    	
				    break;
				    
				    
					default: 	// Autre code d'erreur, on affiche le formulaire de retour de bug
				    	div.innerHTML = '<div class="tnChargement">Erreur ' + req.status + ' : ' + req.statusText + '<br/><a href="#" onclick="popup(\'erreur\',\'index.php5?module=portail&amp;page=saisie_erreur&amp;libelle='+(req.status + ' : ' + encodeURIComponent(req.statusText).replace(/\'/g,'\\\''))+'&url='+encodeURIComponent(url)+'\');return false;">Signaler l\'erreur</a></div>';
				    break;
				}

			}
		}; 
		req.open("GET", url, true); 
		req.setRequestHeader("Pragma","no-cache");
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		req.send(null);
	} 
	
	
	
	this.submit = function(f,element_id,redirect_url,essai,message)
	{
		
		
		var div = document.getElementById(element_id);
		if (!div) div = divDetail;
		//var basket = document.getElementById("tnDivBasket");
		
		var memoire = div.innerHTML;
		
		// Recuperation des valeurs du formulaire
		inputList = f.getElementsByTagName('input');
		var queryComponents = new Array();
		for( i=0 ; i < inputList.length ; i++ )
		{
			myInput = inputList.item(i);
			
			if( myInput.widgEditorObject ){
				myInput.widgEditorObject.updateWidgInput();
			}
			
			if( myInput.type == 'file' ) return true;
			if( myInput.name ){
				if( myInput.type == 'hidden' || myInput.type == 'text' || myInput.type == 'password' || (myInput.type == 'radio' && myInput.checked==true) || (myInput.type == 'checkbox' && myInput.checked==true) ){
					//alert(encodeURIComponent(myInput.name) + "=" + encodeURIComponent(myInput.value));
					if( myInput.value == "" ) myInput.value = " ";
					queryComponents.push( encodeURIComponent(myInput.name) + "=" + encodeURIComponent(myInput.value) );
		        }
			}
		}
		
		areaList = f.getElementsByTagName('textarea');
		for( i=0 ; i < areaList.length ; i++ )
		{
			myArea = areaList.item(i);
			if( myArea.name )
			{
				if( myArea.value == "" ) myArea.value = " ";
				queryComponents.push(
	        	  encodeURIComponent(myArea.name) + "=" + 
	        	  encodeURIComponent(myArea.value) );
			}
		}
		
		selectList = f.getElementsByTagName('select');
		for( i=0 ; i < selectList.length ; i++ )
		{
			mySelect = selectList.item(i);
			if( mySelect.name )
			{
				queryComponents.push(
	        	  encodeURIComponent(mySelect.name) + "=" + 
	        	  encodeURIComponent(mySelect.value) );
	       	}
		}
		
		
		var post_vars = queryComponents.join("&");
		var action = f.attributes['action'].value;
		
		
		// Requete AJAX
		if(message == null || message == ''){
			div.innerHTML='<div class="tnChargement">Traitement en cours...</div>';
		}else{
			div.innerHTML='<div class="tnChargement">' + message + '</div>';
		}
		if(window.XMLHttpRequest)
			req = new XMLHttpRequest(); 
		else if (window.ActiveXObject)
			req  = new ActiveXObject("Microsoft.XMLHTTP"); 
		
		req.onreadystatechange = function()
		{ 
			if(message == null || message == ''){
				div.innerHTML='<div class="tnChargement">Traitement en cours...</div>';
			}else{
				div.innerHTML='<div class="tnChargement">' + message + '</div>';
			}
			if(req.readyState == 4)
			{
				switch( req.status ){
					
					case 12029: // Erreurs de proxy ou firewall, on r?essaie la requ?te 3 fois
				    case 12030:
				    case 12031:
				    case 12152:
				    case 12159:
				    	if( essai <= 4 ) this.submit(f,element_id,redirect_url,essai+1,message);
				    	else div.innerHTML = '<div class="tnChargement">Vous rencontrez des probl&egrave;mes de connexion &agrave; cause d\'un proxy ou d\'un par-feu. ('+req.status+ '-'+essai+') <br/>Pour plus de renseignement, contactez votre administrateur ou Tehms &agrave; l\'adresse contact@tehms.com</div>';
				    	self.cacheSucces();
				    break;
				    case 200: // Reponse positive
				    
				    	var header_debut = req.responseText.substring(0,47);
			    		
			    		if( header_debut == "<div class=\"tehmsheader\" style=\"display:none;\">" ){
				    		var header_fin = req.responseText.substring(47).indexOf("</div>\n\n\n\n") + 47;
				    		var header_contenu = req.responseText.substring(47,header_fin);
				    		var header_text = req.responseText.substring(51,header_fin);
							var page_html = req.responseText.substring(header_fin + 9);
			    			var code = header_contenu.substring(0,4);
							code = parseInt(code,10);
							switch( code ){
						    	case 201: // Execution automatique d'un script
						    		if( redirect_url.length > 0 ){
							    		if( redirect_url == 'retour' ){
							    			self.retour();
							    		}else{
											//basket.innerHTML=page_html;
											self.load(element_id,redirect_url,message);
										}
									}else{
										div.innerHTML=page_html;	
									}
							    	eval(header_text);
							    break;
							    case 3001: // LOGIN
							    	document.location.href="index.php5";
							    break;
							   	default:	// Autre code d'erreur, on affiche le formulaire de retour de bug
							    	document.tehms.popup('<div class="tnChargement">' + header_text + '<br/><br/><a href="#" onclick="popup(\'erreur\',\'index.php5?module=portail&amp;page=saisie_erreur&amp;libelle='+(code + ' : ' + header_text.replace(/\'/g,'\\\''))+'&url='+encodeURIComponent(action)+'\');return false;" style="font-style:italic;font-size:11px;">Cette erreur vous semble anormale ? <br/>Contactez le support technique en cliquant ici</a></div>','');
							    	div.innerHTML = memoire;
							     	//div.innerHTML = '<div class="tnChargement">Erreur ' + code + ' : ' + text + '<br/><a href="#" onclick="popup(\'erreur\',\'index.php5?module=portail&amp;page=saisie_erreur&amp;libelle='+(req.status + ' : ' + encodeURIComponent(req.statusText).replace(/\'/g,'\\\''))+'&url='+encodeURIComponent(action)+'\');return false;">Signaler l\'erreur</a></div>';
							    break;
							}
			    		}else{
			    			if( redirect_url.length > 0 ){
					    		if( redirect_url == 'retour' ){
					    			self.retour();
					    		}else{
									//basket.innerHTML=req.responseText;
									self.load(element_id,redirect_url,message);
								}
							}else{
								div.innerHTML=req.responseText;	
							}
			    		}
			    		
			    		
				    break;
				    
				    default:
				    	div.innerHTML = '<div class="tnChargement">Erreur ' + req.status + ' : ' + req.statusText + '<br/><a href="#" onclick="popup(\'erreur\',\'index.php5?module=portail&amp;page=saisie_erreur&amp;libelle='+(req.status + ' : ' + encodeURIComponent(req.statusText).replace(/\'/g,'\\\''))+'&url='+encodeURIComponent(action)+'\');return false;">Signaler l\'erreur</a></div>';
				    break;
				}

			} 
		};
		
		req.open("POST", action, true); 
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		req.send(post_vars);
		
		return false;
	}
	
	
	
	//////////////////////////////////////////////////////
	// Icons management
	//////////////////////////////////////////////////////
	
	this.addIcon = function( divId, img, jsSrc, title, divWhichClean, left, align ){
		if( !title ) title = "";
		if( !align ) align = "left";
		var div = document.getElementById(divId);
		var icon = '<a class="tnIcone" style="float:'+align+';"';
		if( jsSrc != '' ) icon += ' href="#" onclick="document.tehms.hideInfos();'+jsSrc+';return false;" onmouseover="document.tehms.displayInfos(\''+title+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();">';
		icon += '<img class="tnIcone" src="'+img+'" border="0" style="margin-left:2px;"/></a>';
		if( left )
			div.innerHTML = icon + div.innerHTML;
		else
			div.innerHTML += icon;
		
		
		if( !icons[divWhichClean] ){
			icons[divWhichClean] = Array();
		}
		var element = Array();
		element['divId'] = divId;
		icons[divWhichClean][icons[divWhichClean].length] = element;
	}
	
	
	this.clearIcons = function( element_id, align ){
		if( icons[element_id] ){
			for( var i=0; i<icons[element_id].length; i++ ){
				var contener = document.getElementById(icons[element_id][i]['divId']);
				var icon_elements = contener.getElementsByTagName("A");
				for( var e=0; e<icon_elements.length; e++ ){
					if( !align || icon_elements[e].style.cssFloat == align ){
						contener.removeChild(icon_elements[e]);
					}
				}
			}
			delete icons[element_id];
		}
	}
	
	
	this.addIconWithId = function( imgId, divId, img, jsSrc, title, divWhichClean, left, align ){
		if( !title ) title = "";
		if( !align ) align = "left";
		var div = document.getElementById(divId);
		var icon = '<span id="icon_'+imgId+'" style="float:'+align+';"><a class="tnIcone"';
		if( jsSrc != '' ) icon += ' href="#" onclick="document.tehms.hideInfos();'+jsSrc+';return false;" onmouseover="document.tehms.displayInfos(\''+title+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();">';
		icon += '<img class="tnIcone" src="'+img+'" border="0" style="margin-left:2px;"/></a></span>';
		if( left )
			div.innerHTML = icon + div.innerHTML;
		else
			div.innerHTML += icon;
		
		
		if( !icons[divWhichClean] ){
			icons[divWhichClean] = Array();
		}
		var element = Array();
		element['divId'] = divId;
		icons[divWhichClean][icons[divWhichClean].length] = element;
	}
	
	this.hideIconWithId = function(imgId){
		if (imgId){
			if (document.getElementById('icon_'+imgId)){
				document.getElementById('icon_'+imgId).style.display = 'none';
			}
		}
	}
	this.displayIconWithId = function(imgId){
		if (imgId){
			if (document.getElementById('icon_'+imgId)){
				document.getElementById('icon_'+imgId).style.display = 'inline';
			}
		}
	}
	
	this.changeIconWithId = function( imgId, img, jsSrc, title, divWhichClean, left, align ){
		if( !title ) title = "";
		if( !align ) align = "left";
		
		var span_icon = document.getElementById( 'icon_' + imgId );
		if( span_icon ){
			
			if( !title ) title = "";
			if( !align ) align = "left";
			var icon = '<a class="tnIcone"';
			if( jsSrc != '' ) icon += ' href="#" onclick="document.tehms.hideInfos();'+jsSrc+';return false;" onmouseover="document.tehms.displayInfos(\''+title+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();">';
			icon += '<img class="tnIcone" src="'+img+'" border="0" style="margin-left:2px;"/></a>';
			
			span_icon.innerHTML = icon;
			
		}else{
			alert(imgId);
		}
	}
	
	//////////////////////////////////////////////////////
	// History management
	//////////////////////////////////////////////////////
	
	this.saveHistory = function( element_id, url, content ){
		
		if( !history[element_id] ){
			history[element_id] = Array();
		}
		
		var element = Array();
		element['url'] = url;
		element['content'] = content;
		element['icons'] = icons[element_id];
		
		history[element_id][history[element_id].length] = element;
		
	}
	
	this.backHistory = function( element_id, step ){
		if( !element_id ) element_id = "tnDetail";
		if( !step ) step = 1;
		
		if( history[element_id] && history[element_id].length > step ){
			var length = history[element_id].length;
			var position = history[element_id][length-step-1];
			self.load(element_id,position['url']);
		}else{
			self.refresh(element_id);
		}
	}
	
	this.refresh = function( element_id ){
		var elt = document.getElementById( element_id );
		if( history[element_id] && history[element_id].length > 0 ){
			var length = history[element_id].length;
			var position = history[element_id][length-1];
			self.load(element_id,position['url']);
		}
	}
	
	
	
	//////////////////////////////////////////////////////
	// Tab management
	//////////////////////////////////////////////////////
	
	this.loadTab = function(element_id_base,url,id,close,reload){
		var i=1;
		var divSsCadre;
		while( divSsCadre=document.getElementById(element_id_base + i) ){
			var div_id = element_id_base + i;
			if( i==id ){
				if(close){
					if( divSsCadre.style.display != "block" ){
						self.load(div_id,url);
						divSsCadre.style.display = "block";
					}else{
						divSsCadre.style.display = "none";
					}
				}else{
					self.load(div_id,url);
					divSsCadre.style.display = "block";
				}
			}else{
				divSsCadre.style.display = "none";
			}
			i++;
		}
		
	}
	
	this.selectTab = function(element_id_base,id){
		var i=1;
		while( divCadre=document.getElementById(element_id_base + i) ){
			if( i==id ){
				divCadre.className = 'tnTab_on_over';
			}
			else{
				divCadre.className = 'tnTab';
			}
			i++;
		}
	
	}
	
	
	
	//////////////////////////////////////////////////////
	// Tab management
	//////////////////////////////////////////////////////
	
	this.loadStep = function(element_id_base,url,id){
		var i=1;
		var divContenu;
		var j=1;
		while( divContenu=document.getElementById('div_' + element_id_base + i) || i<10 ){
			if( divContenu.style ){
				var tdLine = document.getElementById('line_' + element_id_base + i);
				var idContenu = 'div_' + element_id_base + i;
				var tdNumero = document.getElementById('numero_' + element_id_base + i);
				
				if( i==id ){
					self.load(idContenu,url);
					divContenu.style.display = "block";
					tdNumero.className = 'tnStep'+j+'_on';
				}else{
					divContenu.style.display = "none";
					tdNumero.className = 'tnStep'+j;
				}
				j++;
			}
			i++;
		}
		
	}
	
	
	
	
	//////////////////////////////////////////////////////
	// Infos display on mouse over
	//////////////////////////////////////////////////////
	
	this.displayInfos = function( text, cssClass ){
		
		if( !cssClass ) cssClass = "tnDivInfos";
		divInfos.className = cssClass;
		divInfos.innerHTML = text;
		infosDisplayed = true;
		divInfos.style.visibility = 'visible';
		
		
	}
	this.hideInfos = function(){
		divInfos.style.visibility = 'hidden';
		infosDisplayed = false;
		divInfos.style.top = -50;
	}
	
	
	
	//////////////////////////////////////////////////////
	// Mouse position calculation
	//////////////////////////////////////////////////////
	
	this.mousePosition = function(e){
	
		curX=(geid)?e.pageX : event.clientX + self.truebody().scrollLeft;
		curY=(geid)?e.pageY : event.clientY + self.truebody().scrollTop;
	
		if (infosDisplayed)
		{
			
			//Find out how close the mouse is to the corner of the window
			var rightedge = dall&&!window.opera? self.truebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
			var bottomedge = dall&&!window.opera? self.truebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
			var topedge = dall&&!window.opera? event.clientY+offsetypoint : e.clientY+offsetypoint-20
			
			var leftedge = (offsetxpoint<0)? offsetxpoint*(-1) : -1000
			
			//if the horizontal distance isn't enough to accomodate the width of the context menu
			if (rightedge < divInfos.offsetWidth)
			{
				//move the horizontal position of the menu to the left by it's width
				divInfos.style.left=dall? self.truebody().scrollLeft + event.clientX - divInfos.offsetWidth+"px" : window.pageXOffset+e.clientX - divInfos.offsetWidth+"px"
			}
			else if (curX < leftedge)
			{
				divInfos.style.left="5px"
			}
			else
			{
				//position the horizontal position of the menu where the mouse is positioned
				divInfos.style.left = curX + offsetxpoint + "px"
			}
	
			//same concept with the vertical position
			if (bottomedge < divInfos.offsetHeight)
			{
				divInfos.style.top = dall? self.truebody().scrollTop + event.clientY - divInfos.offsetHeight - offsetypoint+"px" : window.pageYOffset + e.clientY - divInfos.offsetHeight - offsetypoint+"px"
			}
			else
			{
				divInfos.style.top = curY+offsetypoint + "px"
			}
	
		}
	}
	
	
	this.truebody = function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}
	
	this.getX = function(){
		return curX;
	}
	
	this.getY = function(){
		return curY;
	}
	
	
	
	
	this.checkbox = function( input, value_on, value_off, js_on, js_off ){
		if( input.value != value_on ){
			input.src="/modules/commun/img/arbo/checkbox/checkbox_on.gif";
			if( js_on ) eval(js_on);
			input.value=value_on;
		}else{
			input.src="/modules/commun/img/arbo/checkbox/checkbox.gif";
			if( js_off ) eval(js_off);
			input.value=value_off;
		}
	}
	
	
	this.limitWidth = function( element_id, widthPx ){
		var element = document.getElementById(element_id);
		var i=0;
		while( element.offsetWidth > widthPx && i<100 ){
			element.innerHTML = element.innerHTML.substring(0,element.innerHTML.length-1);
			i++;
		}
	}
	
	this.limitWidthName = function( element_name, widthPx ){
		var elements = document.getElementsByName(element_name);
		var testDiv = document.getElementById("tnDivTestWidth");
		for( var e=0; e<elements.length; e++ ){
			var element = elements[e];
			var length = element.getAttribute('length');
			if( !length ) length = widthPx;
			var positif = true;
			if( length < 0 ){
				positif = false;
				length = -length;
			}
			var i=0;
			var step = 1;
			testDiv.innerHTML = element.innerHTML;
			var initial_text = element.innerHTML;
			
			var fill = (element.getAttribute('fill') && element.getAttribute('fill')=='fill')?true:false;
			
			while( testDiv.offsetWidth > length && i<100 ){
				var taille_dernier = testDiv.innerHTML.length;
				
				if( positif ){
					if( testDiv.innerHTML.substring(testDiv.innerHTML.length-3-5,testDiv.innerHTML.length-3) == "&amp;" ) step += 5;
					testDiv.innerHTML = (testDiv.innerHTML.substring(0,testDiv.innerHTML.length-3-step)+"...");
					element.innerHTML = testDiv.innerHTML;//(element.innerHTML.substring(0,element.innerHTML.length-3-step)+"...");
					if( testDiv.innerHTML.length >= taille_dernier ){
						step += (testDiv.innerHTML.length - taille_dernier) + 1;
					}else{
						step = 1;
					}
				}else{
					
					if( testDiv.innerHTML.substring(3,8) == "&amp;" ) step += 5;
					testDiv.innerHTML = ("..."+testDiv.innerHTML.substring(3+step,testDiv.innerHTML.length));
					element.innerHTML = testDiv.innerHTML;//(element.innerHTML.substring(0,element.innerHTML.length-3-step)+"...");
					if( testDiv.innerHTML.length >= taille_dernier ){
						step += (testDiv.innerHTML.length - taille_dernier) + 1;
					}else{
						step = 1;
					}
				}
				
				i++;
			}
			
			if( i > 0 ){
				//onmouseover="document.tehms.displayInfos('{$infos}');" onmouseout="document.tehms.hideInfos();"
				element.initial_text = initial_text;
				element.onmouseover = function(){document.tehms.displayInfos(this.initial_text);};
				element.onmouseout = function(){document.tehms.hideInfos();};
			}
			
			i=0;
			if( fill ){
			
				//alert( testDiv.offsetWidth );
				while( testDiv.offsetWidth < (length-3) && i<100 ){
					
					if( positif ){
						testDiv.innerHTML = testDiv.innerHTML + ".";
						element.innerHTML = testDiv.innerHTML;
					}else{
						testDiv.innerHTML = "." + testDiv.innerHTML;
						element.innerHTML = testDiv.innerHTML;
					}
					
					i++;
				}
				
			}
			
		}
	}
	
	this.clearSucces = function(){
		if( !dateDernierSucces ) return false;
		if( dateDernierSucces + 10 > self.getSecondes() ) return false;
		dateDernierSucces = false;
		return true;
	}
	
	
	
	/**
	 * V?rifie sur l'?l?ment a d?j? re?u son contenu / v?rification du cache
	 * @param element
	 */
	this.contains = function( element ){
		for( var i=0; i<ouverts.length; i++ ){
			if( ouverts[i]['elt'] == element ) return true;
		}
		return false;
	}
	
	this.refreshElement = function( eltNom ){
		var elt = document.getElementById( eltNom );
		for( var i=0; i<ouverts.length; i++ ){
			if( ouverts[i]['elt'] == elt ){
				this.doPost(elt,ouverts[i]['url']);
				return true;
			}
		}
	}
	
	this.refreshElementAvecParametres = function( eltNom, parametres ){
		var elt = document.getElementById( eltNom );
		for( var i=0; i<ouverts.length; i++ ){
			if( ouverts[i]['elt'] == elt ){
				this.doPost(elt,ouverts[i]['url'] + parametres);
				return true;
			}
		}
	}
	
	/**
	 * Permet de rafraichir la page de d?tail en cours ou pr?c?dent (h)
	 * @param h
	 */
	this.refreshDetails = function( h ){
		if( h_courant >= 0 ){
			var h_c = h_courant;
			if( h && historique[h_c+h] ) h_c += h;
			var elt = historique[h_c]['elt'];
			var url = historique[h_c]['url'];
			this.doPost(elt,url);
			return true;
		}
	}
	
	/**
	 * Permet de revenir en arri?re dans l'historique
	 * @param force
	 
	this.retour = function(force){
		if( h_courant > 0 ){
			h_courant--;
			var elt = historique[h_courant]['elt'];
			var url = historique[h_courant]['url'];
			this.doPost(elt,url);
			return true;
		}else{
			if(!force) alert( "Vous etes au debut de l'historique" );
			return false;
		}
	}*/
	
	/**
	 * Permet de revenir en arri?re dans l'historique
	 * @param force
	 */
	this.retour = function(force,cache){
	
		
		if( h_courant > 0 ){
			h_courant--;
			var elt = historique[h_courant]['elt'];
			var url = historique[h_courant]['url'];
			
			if( cache ){
				var contenu = historique[h_courant]['contenu'];
				elt.innerHTML = contenu;
			}else{
				this.doPost(elt,url);
			}
			return true;
		}else{
			if(!force) alert( "Vous etes au debut de l'historique" );
			return false;
		}
	}
	
	/**
	 * Permet d'avancer dans l'historique
	 * @param force
	 */
	this.avance = function( force ){
		if( h_courant < (historique.length-1) ){
			h_courant++;
			var elt = historique[h_courant]['elt'];
			var url = historique[h_courant]['url'];
			this.doPost(elt,url);
			return true;
		}else{
			if( !force ) alert( "Vous etes a la fin de l'historique." );
			return false;
		}
	}


	/**
	 * Permet de d?finir l'?l?ment destinataire de la reponse
	 * @param elt
	 */
	this.setDestElt = function( elt, url ){
		destElt = elt;
		if( url ){
			var i = h_courant+1;
			historique[i] = new Array();
			historique[i]['elt'] = elt;
			historique[i]['url'] = url;
			h_courant++;
		}
	}
	
	this.setDestCadre = function( url ){		
		destElt = divDetail;
		if( url ){
			var i = h_courant+1;
			historique[i] = new Array();
			historique[i]['elt'] = divDetail;
			historique[i]['url'] = url;
			h_courant++;
		}
	}
	
	/**
	 * Permet de d?finir le r?pertoire des images
	 * @param rep
	 */
	this.setRepertoireImages = function( rep ){
		repertoire = rep;
	}
	
	/**
	 * Place la page url ? la racine de l'arborescence
	 * @param url
	 */
	this.initArbo = function(url){
		var racine = document.getElementById("tnRacine");
		if( !url ) racine.innerHTML = "";
		else this.doPost(racine,url);
	}
	

	this.recherche = function(elt, url){
		var element = document.getElementById(elt);
		if( !document.tehms.contains( element ) ){
			element.innerHTML = "";
			document.tehms.doPost(element,url);
		}
		
	}
		
	/**
	 * Ouvre une arborescence dans l'element elt avec le contenu de url
	 * Modifie l'image img avec nomOuvert
	 * @param elt
	 * @param url
	 * @param img
	 * @param nomOuvert
	 */		
	this.ouvrir = function(elt,url,img,nomOuvert,forceReload){
		self.cacheSucces();
		
		var imageAChanger = true;
		if(!nomOuvert || nomOuvert.length == 0 || !img || img.length == 0){
			imageAChanger = false;
		}
		
		var element = document.getElementById(elt);
		
		if(imageAChanger){
			var image = document.getElementById(img);
			if( nomOuvert.substring(0,1) != "/" ){
				nomOuvert = repertoire + nomOuvert;
			}
			image.src = nomOuvert;
		}
		
		if( !document.tehms.contains( element ) && !forceReload ){
			element.innerHTML = "";
			document.tehms.load(elt,url);
		}
		
		element.style.display = "block";
	}
	
	
	/**
	 * Ouvre ou ferme une arborescence dans l'element elt avec le contenu de url
	 * Modifie l'image img avec nomOuvert ou nomFerme
	 * @param elt
	 * @param url
	 * @param img
	 * @param nomFerme
	 * @param nomOuvert
	 */
	this.fleurir = function(elt,url,img,nomFerme,nomOuvert,forceReload){
		self.cacheSucces();
		
		var imageAChanger = true;
		if(!nomFerme || nomFerme.length == 0){
			imageAChanger = false;
		}
		if(!nomOuvert || nomOuvert.length == 0){
			imageAChanger = false;
		}
		
		var urlFerme = nomFerme;
		var urlOuvert = nomOuvert;
		if( imageAChanger ){
			if( nomFerme.substring(0,1) != "/" ){
				urlFerme = repertoire + nomFerme;
			}
			if( nomOuvert.substring(0,1) != "/" ){
				urlOuvert = repertoire + nomOuvert;
			}
		}
		
	
		var element = document.getElementById(elt);
		var image = document.getElementById(img);
		
		if(element.style.display=="block"){
			element.style.display = "none";
			
			if(imageAChanger)
				image.src = urlFerme;
		}else{
			if( !document.tehms.contains( element ) && !forceReload ){
				element.innerHTML = "";
				document.tehms.load(elt,url);
			}
			element.style.display = "block";
			
			if(imageAChanger)
				image.src = urlOuvert;
		}
	}
	
	this.accordeon = function(elt,sselt,url,img,nomFerme,nomOuvert){
		self.cacheSucces();
		
		var efface = false;
		
		if(this.idElementAccordeon){
					
			document.getElementById(this.idSsElementAccordeon).style.borderBottom = '';
			document.getElementById(this.idSsElementAccordeon).style.borderLeft = '';
			document.getElementById(this.idSsElementAccordeon).style.borderRight = '';
			document.getElementById(this.idSsElementAccordeon).style.display = 'none';
		
			for(var i=0; i < document.getElementById(this.idElementAccordeon).getElementsByTagName("td").length;i++){
				document.getElementById(this.idElementAccordeon).getElementsByTagName("td")[i].style.fontWeight = '';
				document.getElementById(this.idElementAccordeon).getElementsByTagName("td")[i].style.backgroundColor = '';
				document.getElementById(this.idElementAccordeon).getElementsByTagName("td")[i].style.color = '';
			}	
			
			if(this.idElementAccordeon == elt)
				efface = true;
	
		}
		
		if(this.idElementAccordeon != elt){
			this.fleurir(sselt,url,img,nomFerme,nomOuvert);
			
			this.idElementAccordeon = elt;
			this.idSsElementAccordeon = sselt;
			
			document.getElementById(this.idSsElementAccordeon).style.borderBottom = '1px solid #6699FF';
			document.getElementById(this.idSsElementAccordeon).style.borderLeft = '1px solid #6699FF';
			document.getElementById(this.idSsElementAccordeon).style.borderRight = '1px solid #6699FF';
	
			for(var i=0; i < document.getElementById(elt).getElementsByTagName("td").length;i++){
				document.getElementById(elt).getElementsByTagName("td")[i].style.backgroundColor = '#6699FF';
				document.getElementById(elt).getElementsByTagName("td")[i].style.color = 'white';
			}
		}
		
		if(efface){
			this.idElementAccordeon = false;
		}
	}
	
	this.accordeonMouseOverOut = function(elt,over){

		if(this.idElementAccordeon && this.idElementAccordeon != elt || (!this.idElementAccordeon)){
			if(over){				
				for(var i=0; i < document.getElementById(elt).getElementsByTagName("td").length;i++){					
					document.getElementById(elt).getElementsByTagName("td")[i].style.fontWeight = 'bold';
				}
			}
			else{
				for(var i=0; i < document.getElementById(elt).getElementsByTagName("td").length;i++){	
					document.getElementById(elt).getElementsByTagName("td")[i].style.fontWeight = '';
				}
			}				
		}		
	}
	
	this.fleurirSimple = function(elt,img,nomFerme,nomOuvert){
		self.cacheSucces();
		
		var imageAChanger = true;
		if(!nomFerme || nomFerme.length == 0){
			imageAChanger = false;
		}
		if(!nomOuvert || nomOuvert.length == 0){
			imageAChanger = false;
		}
		
		var urlFerme = nomFerme;
		var urlOuvert = nomOuvert;
		if( imageAChanger ){
			if( nomFerme.substring(0,1) != "/" ){
				urlFerme = repertoire + nomFerme;
			}
			if( nomOuvert.substring(0,1) != "/" ){
				urlOuvert = repertoire + nomOuvert;
			}
		}
		
	
		var element = document.getElementById(elt);
		var image = document.getElementById(img);
		
		if( element ){
			if(element.style.display=="block"){
				element.style.display = "none";
				
				if(imageAChanger)
					image.src = urlFerme;
			}else{
				element.style.display = "block";
				
				if(imageAChanger)
					image.src = urlOuvert;
			}
		}
		
	}
	
	
	this.ouvrirSimple = function(elt,img,nomOuvert){
		self.cacheSucces();
		
		var imageAChanger = true;
		if(!nomOuvert || nomOuvert.length == 0){
			imageAChanger = false;
		}
		
		var urlOuvert = nomOuvert;
		if( imageAChanger ){
			if( nomOuvert.substring(0,1) != "/" ){
				urlOuvert = repertoire + nomOuvert;
			}
		}
		
		var element = document.getElementById(elt);
		var image = document.getElementById(img);
		
		if( element ){
			element.style.display = "block";
			
			if(imageAChanger) image.src = urlOuvert;
		}
		
	}
	
	
	this.fleurirSeulement = function(elt){
		self.cacheSucces();
		
		var element = document.getElementById(elt);
		if(element.style.display=="block"){
			element.style.display = "none";
		}else{
			element.style.display = "block";
		}
	}
	
	/**
	 * Affiche une page dans le cadre des d?tails
	 * @param url
	 */
	this.cadre = function(url,not_saved,ssCadre,fermer){
		if( !not_saved ) not_saved = false;
		self.cacheSucces();
		if( !ssCadre || !document.getElementById("sousCadre_" + ssCadre)){
			//this.clearIconesDetailGauche();
			if(!document.getElementById(ssCadre)){
				self.load('tnDetail',url);
				//document.tehms.doPost(divDetail,url,!not_saved);
			}else{
				self.load(ssCadre,url);
				//document.tehms.doPost(document.getElementById(ssCadre),url,!not_saved);
			}
		}else{
			var i=1;
			var divSsCadre;
			while( divSsCadre=document.getElementById("sousCadre_" + i) ){
				if( i==ssCadre ){
					if(fermer){
						if(divSsCadre.style.display != "block" ){
							if(!document.tehms.contains(divSsCadre)){
								document.tehms.doPost(divSsCadre,url,!not_saved);
							}
							else{
								h_courant++;
								historique[h_courant] = new Array();
								historique[h_courant]['elt'] = divSsCadre;
								historique[h_courant]['url'] = url;
							}
							divSsCadre.style.display = "block";
						}else{
							divSsCadre.style.display = "none";
						}
					}else{
						document.tehms.doPost(divSsCadre,url,!not_saved);
						divSsCadre.style.display = "block";
					}
				}else{
					divSsCadre.style.display = "none";
				}
				i++;
			}
		}
	}
	
	
	this.succes = function(msg,position){
		if( isNaN(position) ){
			if( dateDernierSucces && !self.clearSucces() ){
				divSucces.innerHTML=msg;
				dateDernierSucces = self.getSecondes();
				return true;
			}
			
			position = 20;
			divSucces.innerHTML = msg;
			divSucces.style.visibility = 'visible';
			dateDernierSucces = self.getSecondes();
		}
		divSucces.style.top = position;
		if( position > 0 ) setTimeout("document.tehms.succes('"+msg+"',"+(position-1)+");",50);
		
	}
	this.cacheSucces = function(position,force){
		if( /*self.clearSucces() ||*/ force ){
		
			if( isNaN(position) ){
				position = 0;
			}
			divSucces.style.top = position;
			if( position >= 20 ){
				divSucces.style.visibility = 'hidden';
			}else{
				setTimeout("document.tehms.cacheSucces("+(position+1)+",true);",50);
			}
			
		}
	}
	
	this.getSecondes = function(){
		var d = new Date();
		return 3600*d.getHours() + 60*d.getMinutes() + d.getSeconds();
	}
	
	this.requestElement = function(idElt,url,save){
		self.cacheSucces();
		var elt = document.getElementById(idElt);
		document.tehms.doPost(elt,url,save);
	}
		
	
	this.addIconeArbo = function( urlImg, jsSrc, titre, debut ){
		if( !titre ) titre = "";
		var iconesCourantes = document.getElementById("tnIconesArbo");
		var icone = '<a href="#" onclick="'+jsSrc+'" onmouseover="document.tehms.displayInfos(\''+titre+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();"><img src="'+urlImg+'" border="0" style="margin-left:2px;"/></a>';
		if( debut )
			iconesCourantes.innerHTML = icone + iconesCourantes.innerHTML;
		else
			iconesCourantes.innerHTML += icone;
	}
	
	this.addIconeArboWithId = function( urlImg,idImg, jsSrc, titre, debut ){
		if( !titre ) titre = "";
		var iconesCourantes = document.getElementById("tnIconesArbo");
		var icone = '<span id="span_'+idImg+'" href="#"><a href="#" onclick="'+jsSrc+'" onmouseover="document.tehms.displayInfos(\''+titre+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();"><img src="'+urlImg+'" border="0" style="margin-left:2px;"/></a></span>';
		if( debut )
			iconesCourantes.innerHTML = icone + iconesCourantes.innerHTML;
		else
			iconesCourantes.innerHTML += icone;
	}
	
	this.cacheIconeArboWithId = function(idImg){
		if (idImg){
			if (document.getElementById("span_"+idImg))
				document.getElementById("span_"+idImg).style.display = 'none';
		}
	}
	this.montreIconeArboWithId = function(idImg){
		if (idImg){
			if (document.getElementById("span_"+idImg))
				document.getElementById("span_"+idImg).style.display = 'inline';
		}
	}
	
	this.changeIconeArbo = function( idImg, urlImgNew, jsSrcNew, titreNew ){
		if( !titreNew ) titreNew = "";

		var iconeHTML = '<a href="#" onclick="'+jsSrcNew+'" onmouseover="document.tehms.displayInfos(\''+titreNew+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();"><img src="'+urlImgNew+'" border="0" style="margin-left:2px;"/></a>';
		var icone = document.getElementById("span_"+idImg);
		icone.innerHTML = iconeHTML;
	}

	this.addIconeDetail = function( urlImg, jsSrc, titre, debut ){
		if( !titre ) titre = "";
		var iconesCourantes = document.getElementById("tnIconesDetailDroit");
		var icone = '<a href="#" onclick="'+jsSrc+'" onmouseover="document.tehms.displayInfos(\''+titre+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();"><img src="'+urlImg+'" border="0" style="margin-left:2px;"/></a>';
		if( debut )
			iconesCourantes.innerHTML = icone + iconesCourantes.innerHTML;
		else
			iconesCourantes.innerHTML += icone;
	}
	
	this.addIconeDetailGauche = function( urlImg, jsSrc, titre, debut ){
		
		if( !titre ) titre = "";
		var iconesCourantes = document.getElementById("tnIconesDetailGauche");
		var icone = '';
		if( jsSrc ) icone += '<a href="#" onclick="document.tehms.hideInfos();'+jsSrc+'" onmouseover="document.tehms.displayInfos(\''+titre+'\',\'tnDivInfosIcones\');" onmouseout="document.tehms.hideInfos();">';
		icone += '<img src="'+urlImg+'" border="0" style="margin-left:2px;"/>';
		if( jsSrc ) icone += '</a>';
		if( debut )
			iconesCourantes.innerHTML = icone + iconesCourantes.innerHTML;
		else
			iconesCourantes.innerHTML += icone;
	}
	
	this.clearIconesDetailGauche = function(){
		var iconesCourantes = document.getElementById("tnIconesDetailGauche");
		iconesCourantes.innerHTML = "";
	}
	
	this.execFleurir = function( nom_element, display ){
		if( !display ) display = 'block';
		var a = document.getElementById("fleurir_" + nom_element);
		var element = document.getElementById(nom_element);
		if( a ){
			eval(this.extractCodeFromEvent(a.onclick));
			
			while( element.style.display != display ){
				eval(this.extractCodeFromEvent(a.onclick));
			}
		}
	}
	this.execOuvrir = function( nom_element ){
		var a = document.getElementById("ouvrir_" + nom_element);
		if( a ){
			eval(this.extractCodeFromEvent(a.onclick));
		}
	}
	
	this.extractCodeFromEvent = function( event ){
		var fonction = new String(event);
		var split = fonction.split("{");
		if( split.length > 0 ){
			fonction = fonction.substring(split[0].length + 1);
			split = fonction.split("}");
			if( split.length > 0 ){
				var length = 0;
				for( var i=0; i<split.length-1; i++ ) length += split[i].length;
				fonction = fonction.substring(0,length);
				fonction = fonction.replace(/return false;/,"");
				fonction = fonction.replace(/return/,"");
				return fonction;
			}
		}
		return "";
	}
	
	this.confirm = function( txt, jsSrc ){
		
		var html = '';
		
		html += '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">';
		html += '<tr>';
	      html += '<td width="9" height="8"><img src="modules/commun/img/alert/alert_g_h.gif"/></td>';
	      html += '<td style="background-image:url(\'/modules/commun/img/alert/alert_h_fd.gif\');background-repeat:repeat-x;" class="carte_competence"></td>';
	      html += '<td width="9" height="8"><img src="modules/commun/img/alert/alert_d_h.gif"/></td>';
	    html += '</tr>';
	    
	    html += '<tr>';
	    	html += '<td width="9" style="background-image:url(\'/modules/commun/img/alert/alert_g_fd.gif\');background-position: top right"></td>';
		    html += '<td class="tnConfirmText" align="center" style="vertical-align:top">';
			    html += '<div align="left" style="vertical-align:top;color:47AB1C;"><img src="modules/commun/img/bouton/info.gif"/>&#160;Confirmation</div><br/>';	      
				html += txt + '<br/><br/>';
				html += '<input onclick="document.tehms.closePopup();'+jsSrc+'" type="image" src="modules/commun/img/bouton/valider.gif" border="0" onmouseover="this.src = \'/modules/commun/img/bouton/valider_on.gif\'" onmouseout="this.src = \'/modules/commun/img/bouton/valider.gif\'"/>';
				html += '<a onclick="document.tehms.closePopup();" href="#"><img src="/modules/commun/img/bouton/annuler.gif" border="0" onmouseover="this.src = \'/modules/commun/img/bouton/annuler_on.gif\'" onmouseout="this.src = \'/modules/commun/img/bouton/annuler.gif\'"/></a>';
			html += '</td>';
	    	html += '<td width="9" style="background-image:url(\'/modules/commun/img/alert/alert_d_fd.gif\');background-position: top left"></td>';
	    html += '</tr>';
	    
	    html += '<tr>';
	      html += '<td width="9" height="10"><img src="/modules/commun/img/alert/alert_g_b.gif"/></td>';
	      html += '<td height="10" style="background-image:url(\'/modules/commun/img/alert/alert_b_fd.gif\');background-repeat-x;background-position:bottom left;"></td>';
	      html += '<td width="9" height="10"><img src="/modules/commun/img/alert/alert_d_b.gif"/></td>';
	    html += '</tr>';
		
		html += '</table>';
		
		divPopup.innerHTML = html;
		divPopup.style.display='block';
		
	}
	
	this.closePopup = function(){
		divPopup.style.display='none';
	}

	this.popup = function( txt, jsSrc ){
		
		var html = '';
		
		html += '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">';
		
	    html += '<tr>';
	      html += '<td width="9" height="8"><img src="/modules/commun/img/alert/alert_g_h.gif"/></td>';
	      html += '<td style="background-image:url(\'/modules/commun/img/alert/alert_h_fd.gif\');background-repeat:repeat-x;" class="carte_competence"></td>';
	      html += '<td width="9" height="8"><img src="/modules/commun/img/alert/alert_d_h.gif"/></td>';
	    html += '</tr>';
	    
	    html += '<tr>';
	      html += '<td width="9" style="background-image:url(\'/modules/commun/img/alert/alert_g_fd.gif\');background-position: top right"></td>';
	      html += '<td class="tnConfirmText" align="center" style="vertical-align:top">';
	      html += '<div align="left" style="vertical-align:top;color:47AB1C;"><img src="/modules/commun/img/alert/info.gif" style="vertical-align:middle"/>&#160;Information</div><br/>';
	      html += txt + '<br/><input id="tnPopupBouton" onclick="document.tehms.closePopup();'+jsSrc+'" type="image" src="/modules/commun/img/bouton/valider.gif" border="0" onmouseover="this.src = \'/modules/commun/img/bouton/valider_on.gif\'" onmouseout="this.src = \'/modules/commun/img/bouton/valider.gif\'"/>';
	      html += '</td>';
	      html += '<td width="9" style="background-image:url(\'/modules/commun/img/alert/alert_d_fd.gif\');background-position: top left"></td>';
	    html += '</tr>';
	    
	    html += '<tr>';
	      html += '<td width="9" height="10"><img src="/modules/commun/img/alert/alert_g_b.gif"/></td>';
	      html += '<td height="10" style="background-image:url(\'/modules/commun/img/alert/alert_b_fd.gif\');background-repeat-x;background-position:bottom left;"></td>';
	      html += '<td width="9" height="10"><img src="/modules/commun/img/alert/alert_d_b.gif"/></td>';
	    html += '</tr>';
	    
		html += '</table>';
		
		divPopup.innerHTML = html;
		divPopup.style.display='block';
		document.getElementById('tnPopupBouton').focus();
		
	}
	
	this.focusElementArbre = function( eltNom ){
		var elt = document.getElementById(eltNom);
		if( elt ){
			//elt.className='tnElementArbreOn';
			elt.style.backgroundColor = '#DDEEFF';
			focused[focused.length] = elt;
		}
	}
	
	this.blurElementArbre = function( eltNom ){
		var elt = document.getElementById(eltNom);
		//if( elt ) elt.className='tnElementArbreOff';
		if( elt ) elt.style.backgroundColor = '';
	}
	this.blurElementsArbre = function(){
		for( var i=0; i<focused.length; i++ ){
			//focused[i].className='tnElementArbreOff';
			focused[i].style.backgroundColor = '';
		}
	}
	
	/*
	Met l'?l?ment courant en gras 
	si on clique sur un autre 
	?a s'efface
	*/
	this.focusGrasElement = function ( eltNom ){

		var elt = document.getElementById(eltNom);
		if( elt ){
			if(focusedGras!=false)
				focusedGras.style.fontWeight = '';

			elt.style.fontWeight = 'bold';
			focusedGras = elt;
		}		
	}
	
	this.debug = function(){
		document.getElementById('tnDivSrc').style.display = "block";
	}
		
	this.verifFormulaire = function(nomRadio){
			var boutonRadioATester = false;
			if (nomRadio)
				boutonRadioATester = true;
			var erreur = true;
			var radio = false;
			var nomBoutonRadio = false;					
			var erreurLocale = true;
			var fondErreur = "#FFCFCF";
			var couleurErreur = "#FF0000";
			
			for ( var i=0 ; i < document.forms.formulaire.length ; i++){						
				erreurLocale = true;
				
				input = document.forms.formulaire[i];
				
				if( input && input.nodeName.toLowerCase() == "input" && (input.type == "text" || input.type == "password") && input.value.replace(/^(\s)*/, '') != '' ){
					while( input.value.indexOf(String.fromCharCode(8217)) != -1 )
						input.value = input.value.replace(String.fromCharCode(8217),String.fromCharCode(39));
					while( input.value.indexOf(String.fromCharCode(8211)) != -1 )
						input.value = input.value.replace(String.fromCharCode(8211),"-");
					while( input.value.indexOf(String.fromCharCode(339)) != -1 )
						input.value = input.value.replace(String.fromCharCode(339),"oe");
					while( input.value.indexOf(String.fromCharCode(8230)) != -1 )
						input.value = input.value.replace(String.fromCharCode(8230),"...");
					for( var j=0; j<input.value.length; j++ ){
						if( input.value.charCodeAt(j) > 255 ){
							alert( input.value.charCodeAt(j) );
							input.value = input.value.substring(0,j) + input.value.substring(j+1);
							j--;
						}
					}
					
					input.value = input.value.substring(0,255);
				}
				
				
				
				
				switch(document.forms.formulaire[i].className){
					
					
					
					case "texte_obligatoire":
						if(document.forms.formulaire[i].value.length == 0){
							erreur = false;
							erreurLocale = false;
							document.forms.formulaire[i].style.backgroundColor = fondErreur;					
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
						}
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
						}
					break;
					
					case "label_obligatoire":
					
						if(document.forms.formulaire[i].value.length == 0 || document.forms.formulaire[i].value.indexOf(" ",0) != -1 ){
							erreur = false;
							erreurLocale = false;
							document.forms.formulaire[i].style.backgroundColor = fondErreur;					
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
						}
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
						}
					break;
					
					case "nombre":
						
						if(document.forms.formulaire[i].value.length != 0){
														
							if ( ! IsNumber(document.forms.formulaire[i].value) ){
								erreur = false;
								erreurLocale = false;
								document.forms.formulaire[i].style.backgroundColor = fondErreur;									
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
							}
							else{
								document.forms.formulaire[i].style.backgroundColor = "";
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
							}
						}	
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
						}						
						
					break;
					
					case "nombre_obligatoire":
						
						if(document.forms.formulaire[i].value.length != 0){
														
							if ( ! IsNumber(document.forms.formulaire[i].value) ){
								erreur = false;
								erreurLocale = false;
								document.forms.formulaire[i].style.backgroundColor = fondErreur;									
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
							}
							else{
								document.forms.formulaire[i].style.backgroundColor = "";
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
							}
						}	
						else{
							erreur = false;
							erreurLocale = false;
							document.forms.formulaire[i].style.backgroundColor = fondErreur;					
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
						}						
						
					break;
					
					case "date":
						
						if(document.forms.formulaire[i].value.length != 0){
							
							jour = document.forms.formulaire[i].value.slice(0, document.forms.formulaire[i].value.indexOf("/",0) );								
							mois = document.forms.formulaire[i].value.slice(jour.length + 1, document.forms.formulaire[i].value.indexOf("/",jour.length + 1));
							annee = document.forms.formulaire[i].value.slice(jour.length + 1 + mois.length + 1, document.forms.formulaire[i].value.length);
							
							if ( ! IsDate(jour, mois, annee) ){
								erreur = false;
								erreurLocale = false;
								document.forms.formulaire[i].style.backgroundColor = fondErreur;									
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
							}
							else{
								document.forms.formulaire[i].style.backgroundColor = "";
								if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
									document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
							}
						}	
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
						}						
						
					break;
					
					case "date_obligatoire":
					
						jour = document.forms.formulaire[i].value.slice(0, document.forms.formulaire[i].value.indexOf("/",0) );								
						mois = document.forms.formulaire[i].value.slice(jour.length + 1, document.forms.formulaire[i].value.indexOf("/",jour.length + 1));
						annee = document.forms.formulaire[i].value.slice(jour.length + 1 + mois.length + 1, document.forms.formulaire[i].value.length);
																		
						if ( ! IsDate(jour, mois, annee) ){
							erreur = false;
							erreurLocale = false;
							document.forms.formulaire[i].style.backgroundColor = fondErreur;									
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
						}
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";
						}
							
						
					break;
					
					case "mail":
						if( ! IsEMail(document.forms.formulaire[i].value) ){
							erreur = false;
							erreurLocale = false;
							document.forms.formulaire[i].style.backgroundColor = fondErreur;									
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = couleurErreur;
						}
						else{
							document.forms.formulaire[i].style.backgroundColor = "";
							if(document.getElementById("libelle_" + document.forms.formulaire[i].name))
								document.getElementById("libelle_" + document.forms.formulaire[i].name).style.color = "";								
						}
					break;
					
					case "radio_obligatoire":
						
						nomBoutonRadio = document.forms.formulaire[i].name;
						if ( document.forms.formulaire[i].checked )
							radio = true;

					break;
				}
				
				
				if(!erreurLocale && document.getElementById("msg_erreur_" + document.forms.formulaire[i].name))
					document.getElementById("msg_erreur_" + document.forms.formulaire[i].name).style.display = "block";
				else{
					if(document.getElementById("msg_erreur_" + document.forms.formulaire[i].name))
						document.getElementById("msg_erreur_" + document.forms.formulaire[i].name).style.display = "none";
				}
			}
			
			if((nomBoutonRadio != false && !radio) || (boutonRadioATester && !radio)){
				erreur = false;
				if(nomRadio!=''){
					if(document.getElementById("libelle_" + nomRadio))
						document.getElementById("libelle_" + nomRadio).style.color = couleurErreur;
				}
				else{
				if(document.getElementById("libelle_" + nomBoutonRadio))
					document.getElementById("libelle_" + nomBoutonRadio).style.color = couleurErreur;
				}
			}
			else{
				if(nomRadio!=''){
					if(document.getElementById("libelle_" + nomRadio))
						document.getElementById("libelle_" + nomRadio).style.color = "";
				}
				else{
				if(document.getElementById("libelle_" + nomBoutonRadio))
					document.getElementById("libelle_" + nomBoutonRadio).style.color = "";
				}
			}
			
			if(!erreur && document.getElementById("msg_erreur_globale"))
				document.getElementById("msg_erreur_globale").style.display = "block";
			else{
				if(document.getElementById("msg_erreur_globale"))
					document.getElementById("msg_erreur_globale").style.display = "none";
			}
			
			// V?rification du changement de mot de passe
			var pass1 = document.forms.formulaire['mdp'];
			var pass2 = document.forms.formulaire['confirm_mdp'];
			if( pass1 && pass2 ){
				if( pass1.value != pass2.value ){
					document.getElementById("msg_erreur_globale").style.display = "block";
					erreur = false;
				}
			}

			return erreur;
	}
	
	this.libereAttente = function(){
	}
	this.miseEnAttente = function(){
	}
	
	
	
	
	this.ouvrirFermer = function(idDiv){
		divOF=document.getElementById(idDiv);
		if(divOF.style.display == "block"){
			divOF.style.display = "none";
		}else{
			divOF.style.display = "block";
		}
	}
	
	
	
	
	this.ouvrirPopupNiveau = function(){
		divNiveau=document.getElementById('popupNiveau');
		
		divNiveau.style.display = "block";
		divNiveau.style.top = curY;
		divNiveau.style.left = curX - 400;
	}
	
	
}




function TehmsCalendrier(n, min, max, format)
{
	//Declaration de variable
	this.submitAutomatique=false;
	this.champEnregistrement=new String("");
	this.msgEnregistrement=new String("");
	this.target= null;	
	this.format = new String("fr");
	this.name = new String(n);
	this.tag = new String();
	this.title =  new String("Calendrier");
	this.date=new Date();
	this.vis = new Boolean(false);
	this.curYear = new Number(this.date.getFullYear());
	this.maxYear = new Number(this.curYear+max);
	this.minYear = new Number(this.curYear-min);
	this.curMonth= new Number(this.date.getMonth());
	this.day = ["D", "L", "M", "M", "J", "V", "S" ];//
	this.month = ["Janvier", 
				"F&eacute;vrier", 
				"Mars", 
				"Avril", 
				"Mai", 
				"Juin", 
				"Juillet", 
				"Ao&ucirc;t", 
				"Septembre", 
				"Octobre", 
				"Novembre", 
				"D&eacute;cembre"];
	
	
	
	//fonctions
	this.setChampEnregistrement=function(champ)
	{
		this.champEnregistrement=champ;
		return;
	}
	
	this.setMsgEnregistrement=function(msg)
	{
		this.msgEnregistrement=msg;
		return;
	}
	
	this.setSubmitAutomatique=function(bool)
	{
		this.submitAutomatique=bool;
		return;
	}
	
	
	//modification du format Date
	this.setFormat=function(f)
	{
		this.format=f;
		return;
	}
	
	
	
	//modification du titre
	this.setTitle=function(t)
	{
		this.title = t;
		return;
	}
	
	//liste des mois
	this.mList=function()
	{
		var tmp = "<table border='0' cellpadding='0' cellspacing='0' class='calendrier'>";
	
		tmp += "<tr><td align='center' colspan='2'>";
		
		tmp += "<a class='calCroix' href='javascript://' onclick='"+this.name+".hide();'>X</a>";
		tmp += "<div align='center'><h1 class='calendrier'>";
		tmp += this.title;
		tmp += "</h1></div>";
		
		tmp += "</td></tr>";
		tmp += "<tr>";
		tmp += "<td><select name='"+this.name+"month' class='calendrier' ";
		tmp += "onchange='"+this.name+".setMonth(this[this.selectedIndex].value)' >\n";
		for(var i=0; i<this.month.length; i++)
		{			
			tmp += "<option value='"+i+"'";
			if(this.curMonth==i)
				tmp += " selected";
			tmp += ">"+ this.month[i] +"</option>\n";
		}
		tmp += "</select></td><td>\n";
		tmp += this.yList();
		tmp += "</td></tr></table>";
		tmp += this.dList();
		return tmp;
	}

	//liste des annees
	this.yList=function()
	{
		var tmp = "<select name='"+this.name+"year' class='calendrier' ";
		tmp += "onchange='"+this.name+".setYear(this[this.selectedIndex].value);' >\n";
		for(var i=this.minYear; i<=this.maxYear; i+=1)
		{
			tmp += "<option value='"+i+"'";
			if(this.curYear==i)
				tmp += " selected";
			tmp += ">"+ i +"</option>\n";
		}
		tmp += "</select>\n";
		return tmp;
	}

	this.dayCell=function(d,n)
	{
		var tmp = new String("");
		var now = new Date();
		if (this.checkDate(d)==now.getDate() 
				&& this.curMonth==now.getMonth()
				&& this.curYear==now.getFullYear()) 
		{
			tmp += "<td class='jour'";
		}
		else
		{
			tmp += "<td class='jour"+n+"'";
		}
		if(!document.layers)
		{
			tmp += "title='"+this.checkDate(d)+" "+this.month[this.curMonth]+" "+this.curYear+"'";
			tmp += " onmousedown='"+this.name+".getDate(\"";
			tmp += this.formatDate(d);
			tmp += "\");' ";
			tmp += " onmouseover='this.className=this.className+\"on\";' ";
			tmp += " onmouseout='this.className= this.className.substring(0,this.className.indexOf(\"on\"));'";
		}
		else
			tmp += " width='22' height='16' ";
		tmp += ">";
		return tmp;
	}

	this.dList=function()
	{
		var cur=new Number(1);
		var tmpDate = new Date();
		var tmp = new String("<table border='0' cellpadding='0' cellspacing='0' class='calendrier'>");
		tmpDate.setDate(cur);
		tmpDate.setMonth(this.curMonth);
		tmpDate.setFullYear(this.curYear);
		tmp += "<tr>\n";
		for(var i=1; i<this.day.length; i++)
			tmp += "<td class='jourSemaine"+i+"'>"+ this.day[i] +"</td>\n";
		tmp += "<td class='jourSemaine0'>"+ this.day[0] +"</td>\n";
		tmp += "</tr>\n";
		for(var j=0; j<6; j++)
		{
			tmp += "<tr>\n";
			for(var i=1; i<this.day.length; i++)
			{
				tmpDate.setDate(cur);			
				if( cur<=31 && i==tmpDate.getDay() && this.curMonth==tmpDate.getMonth())
				{
					tmp += this.dayCell(cur,i);
					tmp += this.getLink(cur);
					cur+=1;
				}
				else
				{
					tmp += "<td class='jour"+i+"'";
					tmp += ">&nbsp;";
				}
				tmp += "</td>\n";
				tmpDate.setDate(cur);
			}
			if( cur==tmpDate.getDate() && this.curMonth==tmpDate.getMonth())
			{
				tmp += this.dayCell(cur,0);
				tmp += this.getLink(cur);
				cur+=1;
			}
			else
			{
				tmp += "<td class='jour0'";
				tmp += ">&nbsp;";
			}
			tmp += "</td>\n</tr>\n";
		}
		tmp += "</table>\n";
		return tmp;
	}

	this.getLink = function(c)
	{
		var tmp = new String("");
		
		tmp = (c);
		
		return tmp;
	}
	
	//choix du mois
	this.setMonth = function(m)
	{
		this.curMonth = m;
		this.show();
		return;
	}
	
	//recupere le mois
	this.getMonth = function (d)
	{
		
		for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"month"].length; i++)
		{
			if(document.forms[this.name+"_form"].elements[this.name+"month"][i].value==d)
			{
				document.forms[this.name+"_form"].elements[this.name+"month"].selectedIndex=i;
				this.setMonth(d);
				return;
			}
		}
		
		return;
	}
	
	//choix de l'annnee
	this.setYear = function (y)
	{
		this.curYear = y;
		this.show();
		return;
	}
	
	
	//recupere l'annee
	this.getYear = function (y)
	{
		for(var i=0; i<document.forms[this.name+"_form"].elements[this.name+"year"].length; i++)
		{
			if(document.forms[this.name+"_form"].elements[this.name+"year"][i].value==y)
			{
				document.forms[this.name+"_form"].elements[this.name+"year"].selectedIndex=i;
				this.setYear(y);
				return;
			}
		}
		
		return;
	}
	
	//Masque le calendrier
	this.hide = function()
	{
		document.getElementById(this.div).style.visibility = 'hidden';
		document.getElementById(this.div).style.display = 'none';
		this.vis = false;
		return;
	}
	
	//Recupere la date
	this.getDate = function(d)
	{
		if(this.target!=null)
		{
			this.target.value=d;	
			this.hide();
			if(this.submitAutomatique){
				if(this.champEnregistrement != ""){
					return document.tehms.submit(this.target.form,this.champEnregistrement,'','',this.msgEnregistrement);
				}
				return document.tehms.submit(this.target.form,'tnDivBasket','');
			}
		}
		return;
	}
	
	//Affiche le calendrier
	this.show = function()
	{
		this.vis = true;
		this.tag = "<form name='"+this.name+"_form' method='post'>\n";
		this.tag += this.mList();
		this.tag += "</form>\n";
		
		document.getElementById(this.div).innerHTML = ""+this.tag;
		document.getElementById(this.div).style.visibility = 'visible';
		document.getElementById(this.div).style.display = 'block';
		
		return;
	}
	
	//initialisation du calendrier avant affichage
	this.init = function(d, obj, title, enreg, champEnregistrement, msgEnregistrement)
	{
		this.div=d;
		this.target = obj;
		this.date=new Date();
		this.date.setDate(1);		
		this.curMonth = this.date.getMonth();
		this.curYear = this.date.getFullYear();
		this.setSubmitAutomatique(enreg);
		this.setChampEnregistrement(champEnregistrement);
		this.setMsgEnregistrement(msgEnregistrement);
		
		
		if(enreg == 'true'){
			this.setSubmitAutomatique(true);
		}else{
			this.setSubmitAutomatique(false);
		}
						
		this.setTitle(title);
		document.getElementById(this.div).style.top = curY;
		document.getElementById(this.div).style.left = curX;
		this.show();
		return;
	}
	
	this.checkDate = function(d)
	{
		if(parseInt(d)<=9)
			return "0"+parseInt(d);
		return parseInt(d);
	}

	this.formatDate = function(c)
	{
		var tmp = "";
		switch(this.format)
		{
			case "us":	
				tmp = this.curYear+"-";
				tmp += this.checkDate(1+parseInt(this.curMonth))+"-";
				tmp += this.checkDate(c);
				break;
			default: 	
				tmp = this.checkDate(c)+"/";
				tmp += this.checkDate(1+parseInt(this.curMonth))+"/";
				tmp += this.curYear;
				break;
		}
		return tmp;

	}
	
	
	
	
}

