
// ************************************************************************************
//							Bibliotheque LIB_UTILS.JS
//
// Regroupe des fonctions javascripts pour Syfadis
//
// * Bibliotheque NAVIGATION
// <Nom>			findUpperFrame
// <Nom>			AllerPage, AllerLettre
// <Nom>			addId2List, delId2List
//
// * Bibliotheque AFFICHAGE
// <Nom>			AffBulle
// <Nom>			dockOnChange
//
// * Bibliotheque standardisation d'ouverture de FENETRES
// <Nom>			openWindow
// <Nom>			openMessagerie
// <Nom>			ouvrirAide
// <Nom>			openStatsExport
// <Nom>			openFichierCSV
// <Nom>			openChat
// <Nom>			openHistorique
// <Nom>			openForum
// <Nom>			popupDate
//
// * Bibliotheque ROLL-OVER
// <Nom>			MM_swapImgRestore
// <Nom>			MM_preloadImages
// <Nom>			MM_swapImages
// <Nom>			MM_KeepBtnState
//
// * Bibliotheque CONTENU HTML
// <Nom>			findFORM
// <Nom>			getFORM
// <Nom>			launchNextRess
//
// * Bibliotheque CONTENU HTML
// <Nom>			findFORM
// <Nom>			getFORM
// <Nom>			launchNextRess
//
// * Bibliotheque GESTION DES URLS
// <Nom>			getSecuredURL
// <Nom>			getInformationURL
// <Nom>			replaceServernameTag
//
// * Bibliotheque DIVERS
// <Nom>			fnTrapKD, enter_key_trap
//
// <Date Creation> 17 Mai 2002
// ************************************************************************************

	

// ************************************************************************************
//							Bibliotheque NAVIGATION
//
// Regroupe des appels de fonctions standard necessaires a la navigation sur Syfadis
//
// <Nom>			findUpperFrame
// <Nom>			AllerPage, AllerLettre
// <Nom>			addId2List, delId2List
//
// <Date Creation> 17 Mai 2002
// ************************************************************************************


	//--------------------------------------------------------------------------------------
	// Nom de la fonction : findUpperFrame
	// 
	// Description :
	//
	// Parametres : nom : 
	//				upperWindow : 
	//--------------------------------------------------------------------------------------

		function findUpperFrame(nom,upperWindow) {
			if (upperWindow==null) upperWindow=window.parent;
			
			if (upperWindow.frames[nom] != null)
				return upperWindow.frames[nom];
			else if (upperWindow != window.top)
				return findUpperFrame(nom,upperWindow.parent);
			else 
				return null;
		}	




	//---------------------------------------------------------------------------
	// <Nom>          AllerPage
	// <Description>  Permet de se rendre a la page [iPage] lors d'une navigation
	//				  par page. L'emploi de cette fonction suppose l'existence
	//				  d'un formulaire frmNavigation.
	// <Parametres>   (I) iPage : Numero de la page que l'on souhaite afficher
	// <Resultats>	  
	//---------------------------------------------------------------------------

		function AllerPage(iPage) {
			document.frmNavigation.pg.value = iPage;
			document.frmNavigation.submit();
		}




	//---------------------------------------------------------------------------
	// <Nom>          AllerLettre
	// <Description>  Permet de selectionner une lettre commencant un mot ou un nom
	//				  qui permettra de filtrer l'affichage de la page de destination.
	//				  L'emploi de cette fonction suppose l'existence d'un formulaire 
	//                frmNavigation.
	// <Parametres>   (I) sLettre : Lettre permettant de filtrer l'affichage
	// <Resultats>	  
	//---------------------------------------------------------------------------

		function AllerLettre(sLettre) {
			document.frmNavigation.pg.value = 1;
			document.frmNavigation.Lettre.value = sLettre;
			document.frmNavigation.submit();
		}


	//--------------------------------------------------------------------------------------
	// Nom de la fonction : addId2List
	// 
	// Description : Fonction d'ajout d'elements dans une chaine
	//
	// Parametres : myObject : l'objet contenant la liste d'elements
	//				myId	 : l'ID a ajouter
	// 
	// Date de dermiere mise a jour : * - *
	//--------------------------------------------------------------------------------------

		function addId2List(myObject, myId)
		{
			//Ajouter l'id a la liste
			var liste = myObject.value;
			if (liste!="") liste += ";";
			liste += myId;
			
			myObject.value = liste;
		}


	//--------------------------------------------------------------------------------------
	// Nom de la fonction : delId2List
	// 
	// Description : Fonction de suppression d'elements dans une chaine
	//
	// Parametres : myObject : l'objet contenant la liste d'elements
	//				myId	 : l'ID a supprimer
	// 
	// Date de dermiere mise a jour : * - *
	//--------------------------------------------------------------------------------------

		function delId2List(myObject, myId)
		{
			var ecart=0;
			var liste=myObject.value;
			var cpt;
			
			//enlever de listeProfil la ligne ligne-1
			var tabListe = liste.split(";");
			var tabTmp = new Array();
				
			for (cpt=0;cpt<tabListe.length;cpt++)
			{
				if (tabListe[cpt]==myId)
					ecart += 1;
				else
					tabTmp[cpt-ecart] = tabListe[cpt];
				
			}
			myObject.value = tabTmp.join(";");
		}


	
	

// ************************************************************************************
//							Bibliotheque AFFICHAGE
//
// Regroupe des appels de fonctions standard d'ouverture en pop-up de certains fonctionnalites 
//  Syfadis
//
// <Nom>			AffBulle
// <Nom>			dockOnChange
//
// <Date Creation> 21 Janvier 2004
// ************************************************************************************


	//-----------------------------------------------------------------------------------
	// <Nom>			AffBulle
	// <Description>	Ouvre une bulle d'aide
	// <Parametres>		
	// <Resultats>		
	// <Auteur>			AB - 22.05.2002
	//
	// <Source>			http:// www.toutjavascript.com
	// Auteur original :Olivier Hondermarck  <webmaster@toutjavascript.com>
	// Modifs compatibilite Netscape 6/Mozilla : Cedric Lamalle 09/2001 <cedric@cpac.embrapa.br>
	//-----------------------------------------------------------------------------------


		var IB = new Object;
		var posX = 0; posY = 0;
		var xOffset = 10; yOffset = 10;
		
		function AffBulle(texte) {
		  contenu="<TABLE border=0 cellspacing=0 cellpadding="+IB.NbPixel+"><TR bgcolor='"+IB.ColContour+"'><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD><FONT size='-1' face='arial' color='"+IB.ColTexte+"'>"+texte+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
		  var finalPosX=posX-xOffset;
		  if (finalPosX<0) finalPosX=0;
		  if (document.layers) {
		    document.layers["bulle"].document.write(contenu);
		    document.layers["bulle"].document.close();
		    document.layers["bulle"].top=posY+yOffset;
		    document.layers["bulle"].left=finalPosX;
		    document.layers["bulle"].visibility="show";}
		  if (document.all) {
		    bulle.innerHTML=contenu;
		    document.all["bulle"].style.top=posY+yOffset;
		    document.all["bulle"].style.left=finalPosX;//f.x-xOffset;
		    document.all["bulle"].style.visibility="visible";
		  }
		  //modif 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
		  else if (document.getElementById) {
		    document.getElementById("bulle").innerHTML=contenu;
		    document.getElementById("bulle").style.top=posY+yOffset;
		    document.getElementById("bulle").style.left=finalPosX;
		    document.getElementById("bulle").style.visibility="visible";
		  }		  
		}
		
		function getMousePos(e) {
		  if (document.all) {
		  posX=event.x+document.body.scrollLeft; //modifs 09/2001 - IE : regrouper l'evenement
		  posY=event.y+document.body.scrollTop;
		  }
		  else {
		  posX=e.pageX; //modifs 09/2001 - NS6 : celui-ci ne supporte pas e.x et e.y
		  posY=e.pageY; 
		  }
		}
		
		function HideBulle() {
			if (document.layers) {document.layers["bulle"].visibility="hide";}
			if (document.all) {document.all["bulle"].style.visibility="hidden";}
			else if (document.getElementById){document.getElementById("bulle").style.visibility="hidden";}
		}

		function InitBulle(ColTexte,ColFond,ColContour,NbPixel) {
			IB.ColTexte=ColTexte;IB.ColFond=ColFond;IB.ColContour=ColContour;IB.NbPixel=NbPixel;
			if (document.layers) {
				window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
				document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
			}
			if (document.all) {
				document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
				document.onmousemove=getMousePos;
			}
			//modif 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
			else if (document.getElementById) {
			        document.onmousemove=getMousePos;
			        document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
			}
		}


	//-----------------------------------------------------------------------------------
	// <Nom>			dockOnChange
	// <Description>	Permet d'afficher/cacher un block de données
	// <Parametres>		
	// <Resultats>		
	// <Auteur>			AB - 05.09.2005
	//-----------------------------------------------------------------------------------
			
		function dockOnChange(id, bIsTable) {
		
			var sDockDisplay = document.getElementById('dock'+id).style.display;
			var sEtat;
			var sArgDisplay;
					
			if (document.all)
				sArgDisplay = 'block'		// Navigateur IE
			else
				sArgDisplay = 'table-row';	// Autres navigateurs
		
			if (sDockDisplay=='none' || sDockDisplay=='undefined') {
				if (bIsTable)
					sEtat = sArgDisplay
				else
					sEtat = 'block'
			} else {
				sEtat = 'none'
			}		
			document.getElementById('dock'+id).style.display = sEtat;
		}

	
	

// ************************************************************************************
//							Bibliotheque FENETRES
//
// Regroupe des appels de fonctions standard d'ouverture en pop-up de certains fonctionnalites 
//  Syfadis
//
// <Nom>			openWindow
// <Nom>			openMessagerie
// <Nom>			ouvrirAide
// <Nom>			openStatsExport
// <Nom>			openChat
// <Nom>			openHistorique
// <Nom>			openForum
// <Nom>			popupDate
//
// <Date Creation> 03 Decembre 2003
// ************************************************************************************



	//-----------------------------------------------------------------------------------
	// <Nom>			openWindow
	// <Description>	Ouvre une pop-up
	// <Parametres>		url		: l'URL a ouvrir
	//					name	: nom de la fenetre
	//					settings: parametres complementaires
	// <Resultats>		
	// <Auteur>			AB - 21.12.2001
	//-----------------------------------------------------------------------------------

			function openWindow(url,name,settings) {

				window.open(url,name,'location=no'+settings);
			}
		


	//-----------------------------------------------------------------------------------
	// <Nom>			openMessagerie
	// <Description>	Ouvre la messagerie en pop-up
	// <Parametres>		url : l'URL a ouvrir
	//					name : nom de la fenetre
	// <Resultats>		
	// <Auteur>			AB - 06.02.2003
	//-----------------------------------------------------------------------------------

			function openMessagerie(url) {

				window.open (url+'&stnav=2', 'MailBD', 'toolbar=no,location=no,directories=no,scrollbars=yes,menubar=no,status=no,copyhistory=no,resizable=yes,width=750,height=540');

			}	

		
	//-----------------------------------------------------------------------------------
	// <Nom>			openAide
	// <Description>	Ouvre l'aide en pop-up
	// <Parametres>		url : l'URL a ouvrir
	//					name : nom de la fenetre
	// <Resultats>		
	// <Auteur>			AB - 23.04.2003
	//-----------------------------------------------------------------------------------

			
		function OuvrirAide (sURL) {
			window.open (sURL, 'AideImport', 'toolbar=no,location=no,directories=no,scrollbars=yes,menubar=no,status=no,copyhistory=no,resizable=yes,width=450,height=500');
		}

		
	//-----------------------------------------------------------------------------------
	// <Nom>			openStatsExport
	// <Description>	Ouvre l'export de statistiques en pop-up
	// <Parametres>		sURL : l'URL a ouvrir
	// <Resultats>		
	// <Auteur>			AB - 14.11.2003
	//-----------------------------------------------------------------------------------

			
		function openStatsExport (sURL) {
			window.open (sURL, 'Reporting', 'toolbar=yes,location=no,directories=no,scrollbars=yes,menubar=yes,status=yes,copyhistory=no,resizable=yes,width=610,height=400');
			window.close();
		}

	//-----------------------------------------------------------------------------------
	// <Nom>			openFichierCSV
	// <Description>	Ouvre un fichier CSV dans une pop-up
	// <Parametres>		sURL : l'URL a ouvrir
	// <Resultats>		
	// <Auteur>			CS - Mars 2005
	//-----------------------------------------------------------------------------------

			
		function openFichierCSV (sURL) {
			window.open (sURL, 'CSV', 'toolbar=yes,location=no,directories=no,scrollbars=yes,menubar=yes,status=yes,copyhistory=no,resizable=yes,width=610,height=400');
			window.close();
		}
		
	//-----------------------------------------------------------------------------------
	// <Nom>			openChat
	// <Description>	Ouvre la fenetre de l'applet de Chat
	// <Parametres>		sURL : l'URL a ouvrir (chat tout seul ou chat+tracking)
	
	// <Resultats>		
	// <Auteur>			03.12.2003
	//-----------------------------------------------------------------------------------

		function openChat(sURL) {
			var sWidth = 632;
			var sHeight = 500;
			LeftPosition= (screen.width) ? (screen.width-sWidth)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-sHeight)/2 :0;
			settings = 'height='+sHeight+',width='+sWidth+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,resizable=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,copyhistory=no';
			window.open (sURL, 'UnChat', settings);
		}

		
	//-----------------------------------------------------------------------------------
	// <Nom>			openHistorique
	// <Description>	Ouvre la fenetre de l'historique d'une ressource
	// <Parametres>		
	
	// <Resultats>		
	// <Auteur>			AB - 12.01.2004
	//-----------------------------------------------------------------------------------

		function openHistorique(sURL) {
			window.open (sURL, "Historique", 'width=600, height=450, resizable=yes,scrollbars=yes');
		}

		
	//-----------------------------------------------------------------------------------
	// <Nom>			openForum
	// <Description>	Ouvre la fenetre de lancement d'un forum
	// <Parametres>		sURL		: URL a ouvrir
	//					sTypeAction	: Action a executer
	// <Resultats>		
	// <Auteur>			AB - 29.01.2004
	//-----------------------------------------------------------------------------------

		function openForum(sURL, sTypeAction) {
			var settings;
			
			switch (sTypeAction) {
				case 'Nouveau' :
					settings = 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,copyhistory=no,resizable=yes';
					settings+= ',width=712,height=550';
					break;
					
				case 'Moderer' :
					settings = 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,copyhistory=no,resizable=yes';
					settings+= ',width=500,height=250';
					break;
			}
			
			window.open(sURL, 'DonneesForum', settings);
		}
		
		
		
	//-----------------------------------------------------------------------------------
	// <Nom>			popupDate
	// <Description>	Ouvre un calendrier en pop-up
	// <Parametres>		sURLRacine, SessionID
	//					sChamp : nom du champ 'appelant'
	// <Resultats>		
	// <Auteur>			AB - 13.05.2003
	//-----------------------------------------------------------------------------------

			
		function popupDate (sURLRacine, SessionID, sChamp) {
			var sURL;
			sURL = sURLRacine+"Planning/popup_planning.asp?SessionID="+SessionID+"&Champ="+sChamp+"&DateAgenda="+eval('document.'+sChamp+'.value');
			window.open (sURL, 'popupDate', 'toolbar=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,copyhistory=no,resizable=yes,width=283,height=166');
		}




// ************************************************************************************
//							Bibliotheque ROLL-OVER
//
// Regroupe des fonctions de roll-over sur les images de la navigation de Syfadis
//
// <Nom>			MM_swapImgRestore
// <Nom>			MM_preloadImages
// <Nom>			MM_swapImages
// <Nom>			MM_KeepBtnState
//
// <Date Creation> 17 Mai 2002
// ************************************************************************************



	//--------------------------------------------------------------------------------------
	// Nom de la fonction : MM_swapImgRestore
	// 
	// Description : Permet de restaurer l'image du bouton remplacee lors du passage du curseur
	// Cas d'utilisation: <A href="..." onMouseOut="MM_swapImgRestore()" onMouseOver="...">
	//
	// Parametres : Aucun
	//				
	// Date de creation : 10/03/2000 - Francois-Xavier
	// 
	// Date de derniere mise a jour : * - *
	//--------------------------------------------------------------------------------------

		function MM_swapImgRestore() {
		  if (document.MM_swapImgData != null)
		    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
		      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
		}
		
		

	//--------------------------------------------------------------------------------------
	// Nom de la fonction : MM_preloadImages
	// 
	// Description : Permet de charger en memoire les images avec lesquelles
	//				 on veut swapper lors du passage de la souris sur un bouton
	//
	// Parametres : Obligatoires: - Le(s) nom(s) de(s) image(s) a pre-loader,
	//			   l'appel est en general fait suite a un:
	//					 onLoad="MM_preloadImages('image1','image2',...)"
	//	
	// Remarque: Le test : charAt(0)!="#" ne sert que lorsque l'on passe un 
	//			parametre supplementaire de la forme #?????? resultant d'une 
	//			mise en forme automatique avec un outil specialise (inutile 
	//			dans le cas d'une utilisation faite main)
	//				
	// Date de creation : 10/03/2000 - Francois-Xavier
	// 
	// Date de derniere mise a jour : * - *
	//--------------------------------------------------------------------------------------

		function MM_preloadImages() {
		  if (document.images) {
		    var imgFiles = MM_preloadImages.arguments;
		    if (document.preloadArray==null) document.preloadArray = new Array();
		    var i = document.preloadArray.length;
		    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
		      preloadArray[i] = new Image;
		      preloadArray[i++].src = imgFiles[j];
		  } }
		}
		
		

	//--------------------------------------------------------------------------------------
	// Nom de la fonction : MM_swapImages
	// 
	// Description : Permet de remplacer l'image d'un bouton par celle passee en parametre
	// Cas d'utilisation: <A href="..." onMouseOut="..." onMouseOver="MM_swapImages('NomBoutonNetscape','NomBoutonIE','image')">
	//
	// Parametres : Obligatoires:	le nom du bouton image a modifier sous Netscape
	//								le nom du bouton image a modifier sous un autre Navigateur
	//								le nom de l'image qui remplace la precedente
	//				
	// Date de creation : 10/03/2000 - Francois-Xavier
	// 
	// Date de derniere mise a jour : * - *
	//--------------------------------------------------------------------------------------

		function MM_swapImages() { 
		  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
		  for (i=0; i < (MM_swapImages.arguments.length-2); i+=3) {
		    objStr = MM_swapImages.arguments[(navigator.appName == 'Netscape')?i:i+1];
		    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
		        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
		      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
		    obj = eval(objStr);
		    if (obj != null) {
		      swapArray[j++] = obj;
		      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
		      obj.src = MM_swapImages.arguments[i+2];
		  } }
		  document.MM_swapImgData = swapArray; //used for restore
		}
		
		

	//--------------------------------------------------------------------------------------
	// Nom de la fonction : MM_KeepBtnState
	// 
	// Description : Une fois qu'on a clique sur un bouton en roll-over, laisse celui-ci dans l'etat specifie en parametre,
	//				 et supprime le lien '<A Href=' pour que le lien ne soit plus cliquable et imbrique l'image dans un '<Span>'
	//
	// Parametres : Obligatoires:	ID du Span
	//								Adresse de l'image à afficher
	//				
	// Date de creation : AB - 19/01/2004
	//--------------------------------------------------------------------------------------
		
		function MM_KeepBtnState(sCteImg, sIMG) {
			document.getElementById('SPAN_'+sCteImg).innerHTML = '<img src="'+sIMG+'" border="0">';
		}
		
		
		
		
		



	
	

// ************************************************************************************
//							Bibliotheque CONTENU HTML
//
// Regroupe les fonctions javascripts necessaires aux fonctionnement des contenus HTML
//  crees par l'Editeur HTML
//
// <Nom>	findFORM, getFORM	(fonctions derivees des fonctions findAPI et getAPI pour SCORM)
//
// <Date Creation> 25 Fevrier 2004
// ************************************************************************************


	// Constante de debug
	var _Debug = false;

	/******************************************************************************************
	**
	** Function findFORM(win)
	** Inputs:	win - a Window Object
	** Return:	If an FORM object is found, it is returned, otherwise null is returned.
	**
	** Description:
	** This function looks for an object named FORM in the supported window hierarchy, 
	** 
	******************************************************************************************/
	function findFORM(win) {
	 
	   // Search the window hierarchy for an object named "FORM"  
	   // Look in the current window (win) and recursively look in any child frames
	    
	   if (_Debug) alert("win is: "+win.location.href);
	 
	 
	   if (win.document.frmRelancer != null) {
	      if (_Debug) alert("found FORM in this window");
	      return win.document.frmRelancer;
	   }

	   // does the window have frames?
	   if (win.length > 0) {
	      if (_Debug) alert("looking for FORM in windows frames"); 
	      
	      for (var i=0;i<win.length;i++) {
	 
	         if (_Debug) alert("looking for FORM in frames["+i+"]");
	         
	         var theFORM = findFORM(win.frames[i]);
	         if (theFORM != null) return theFORM;
	      }
	   }
	 
	   if (_Debug) alert("didn't find FORM in this window (or its children)");
	   return null;
	 
	}
	 
	 
	/******************************************************************************************
	**
	** Function getFORM()
	** Inputs:	none
	** Return:	If a FORM object is found, it is returned, otherwise null is returned.
	**
	** Description:
	** This function looks for an object named FORM, first in the current window's hierarchy, 
	**  and then, if necessary, in the current window's opener window hierarchy (if there is
	**  an opener window).
	******************************************************************************************/
	 
	function getFORM() {
	 
	   // start at the topmost window - findFORM will recurse down through
	   // all of the child frames
	   var theFORM = findFORM(this.top);
	 
	   if (theFORM == null) {
	      // the FORM wasn't found in the current window's hierarchy.  If the
	      // current window has an opener (was launched by another window),
	      // check the opener's window hierarchy. 
	      if (_Debug) alert("checking to see if this window has an opener/nwindow.opener typeof is> "+typeof(window.opener));
	 
	      if (typeof(this.opener) != "undefined") {
	         if (_Debug) alert("checking this windows opener");
	         
	         if (this.opener != null) {
	            if (_Debug) alert("this windows opener is NOT null - looking there");
	            
	            theFORM = findFORM(this.opener.top);
	         }
	         else {
	            if (_Debug) alert("this windows opener is null");
	         }
	      }
	   }
	 
	   return theFORM;
	}
	 
	 
	/******************************************************************************************
	**
	** Function launchNextRess(RessId)
	** Inputs:	RessId : ID de la ressource
	** Return:	Lancement du tracking de la ressource suivante + la ressource
	**
	******************************************************************************************/
	
	function launchNextRess(RessId) {
		var oForm = getFORM(); 
		var sURL = oForm.sURL.value+RessId; 
		
		if (window.parent.name=='principal') {
			// La page html est ouverte dans la frame
			findUpperFrame('principal',null).location = sURL;
		} else {
			// La page html est ouverte dans une nouvelle fenetre
			top.location = sURL;
		}
	}


	
	

// ************************************************************************************
//							Bibliotheque GESTION DES URLS
//
// 
//
// <Nom> getSecuredURL
// <Nom> getInformationURL
// <Nom> replaceServernameTag
//
// <Date Creation> Juin 2005
// ************************************************************************************


	// -----------------------------------------------------------------------------
	// <Nom>         getSecuredURL
	// <Description> recontruit une url en https a partir d'une url en http. Si l'url
	//	n'est pas en http, l'url d'origine est renvoyee
	// <Parametres>  (I) obj
	// <Resultats>   Booleen
	// -----------------------------------------------------------------------------
	
		function getSecuredURL(sUnsecureURL) {
			var newUrl=new String(sUnsecureURL);
			if (sUnsecureURL.length < 6) 
			{ 
				alert("Invalid hyperlink entered: " + newUrl); 
				return; 
			} 
			var sProtocol = newUrl.substring(0,6); 
			if (sProtocol == 'http:/') return 'https:/' + newUrl.substring(6);
			return sUnsecureURL;
		}
		

	// -----------------------------------------------------------------------------
	// <Nom>         getInformationURL
	// <Description> extrait les informations sur l'url a savoir le protocole, le nom
	//	de domaine, le port
	// <Parametres>  (I) sURL = URL complete, souvent le document.location
	// <Resultats>   Tableau contenant 
	//		- en position 0 le protocole http ou https
	//		- en position 1 le nom du server
	//		- en position 2 le port utilise, avec 80 si rien n est precise. si on voulait etre exact, il faudrait mettre egalement 443 si on est en https.
	// -----------------------------------------------------------------------------
	
		function getInformationURL(sURL) {
		
			var m_aResult=new Array(3);
			var m_sUrl=new String(sURL);
			
			if (sURL.length < 6) 
			{ 
				alert("Invalid hyperlink entered: " + sURL); 
				return; 
			}
			//recherche du protocole pour le premier parametre
			var m_sProtocol = m_sUrl.substring(0,6); 
			switch(m_sProtocol) 
			{
				case 'http:/' :
					m_aResult[0]='http';
					break;
				case 'https:' :
					m_aResult[0]='https';
					break;
			}
			var m_iPosSlash, m_iPosColon, m_sDomain;
			//recherche du domaine pour le deuxieme parametre
			//	on ajoute la longueur de '://' à la longueur du protocole trouvé (donc + 3)
			m_sUrl=m_sUrl.substring(m_aResult[0].length + 3);
			m_iPosColon=m_sUrl.indexOf(':'); 
			m_iPosSlash=m_sUrl.indexOf('/');
			//si deux points est apres slash, on en tient pas compte
			if (m_iPosColon>m_iPosSlash) m_iPosColon=-1;
			if (m_iPosColon < 0)
			{
				m_aResult[1] = m_sUrl.substring(0, m_iPosSlash);
				m_aResult[2] = '80';
			}
			else
			{
				m_aResult[1] = m_sUrl.substring(0, m_iPosColon);
				m_aResult[2] = m_sUrl.substring(m_iPosColon + 1,  m_iPosSlash);
			}
				
			//alert('getInformationURL=' + m_aResult[0] + '://' + m_aResult[1] + ':' + m_aResult[2]);
			return m_aResult;
		}
		

	// -----------------------------------------------------------------------------
	// <Nom>         replaceServernameTag
	// <Description> remplace le servername dans les url relatives par la valeur ad hoc
	// fonction du contexte
	// <Parametres>  (I) psUrl = Url ou le tag servername est a remplacer
	//				 (I) paParamsUrl = Tableau des parametres issu de la fonction getInformation
	// <Resultats>   l urltransformee
	// -----------------------------------------------------------------------------
	
		function replaceServernameTag(psUrl,paParamsUrl) 
		{
			var m_sRes;
			//	replace avec urlencode
			m_sRes=psUrl.replace(/http%3A%2F%2F%5Bservername%5D/g,paParamsUrl[0] + '%3A%2F%2F' + paParamsUrl[1] + (paParamsUrl[2]=='80' ? '' : '%3A'+paParamsUrl[2]));
			//	replace sans urlencode
			m_sRes=m_sRes.replace(/http:\/\/\[servername\]/g,paParamsUrl[0] + '://' + paParamsUrl[1] + (paParamsUrl[2]=='80' ? '' : ':'+paParamsUrl[2]));
			//	quelquesfois, il n'y a pas de protocole specifie (cas des contenus aicc HORIZONS)
			m_sRes=psUrl.replace(/%5Bservername%5D/g,paParamsUrl[1] + (paParamsUrl[2]=='80' ? '' : '%3A'+paParamsUrl[2]));
			m_sRes=m_sRes.replace(/\[servername\]/g,paParamsUrl[1] + (paParamsUrl[2]=='80' ? '' : ':'+paParamsUrl[2]));
			return m_sRes;
		}
		
	
	

// ************************************************************************************
//							Bibliotheque DIVERS
//
// 
//
// <Nom>	fnTrapKD, enter_key_trap
//
// <Date Creation> 12 janvier 2005
// ************************************************************************************
		
	
	// -----------------------------------------------------------------------------
	// <Nom>         fnTrapKD, enter_key_trap
	// <Description> Selon le navigateur, identifie une pression sur la touche RETURN
	// <Parametres>  (I) obj
	// <Resultats>   Booleen
	// -----------------------------------------------------------------------------
		function fnTrapKD(obj) {
			if (navigator.appName == "Microsoft Internet Explorer") {
			    if (event.keyCode == 13) {
					event.returnValue = false; 
				    // execution
				    fnExecuteKD();
				}
			} else {
				if (window.document.captureEvents != null) {
				    window.document.captureEvents(Event.KEYPRESS);
				    window.document.onkeypress = enter_key_trap;
				}
			}
		}
		
		function enter_key_trap(e) {
		    var keyPressed;

		    if (document.layers) {
		        keyPressed = String.fromCharCode(e.which);
		    } else if (document.all) {
		        keyPressed = String.fromCharCode(window.event.keyCode);
		    } else if (document.getElementById) {
		        keyPressed = String.fromCharCode(e.keyCode);
		    }
		    if ((keyPressed == "\r" || keyPressed == "\n")) {
				// Execution
				fnExecuteKD();
			}
		}
		
	