

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function



function ImprimePopUp(page)
{
	var param = document.location.search;
	var flag=0;
	if(param.length==0)
	{
		if (page.length==0)
		{
			var pos_der_slash = location.href.substring(0,location.href.length-1).lastIndexOf('/');
			var longueur = location.href.length;
			var page_courante = location.href.substring(pos_der_slash+1, longueur);
		}
		else
		{
			var page_courante = page;
			page_courante = page_courante.substring(0,page_courante.lastIndexOf("#"));
		}
		var adresse = page_courante + '?mode=imprim';
	}
	else
	{
		if (page.length==0)
		{
			var pos_der_slash = location.href.substring(0,location.href.length-1).lastIndexOf('/');
			var pos_interro = location.href.substring(0,location.href.length-1).lastIndexOf('?');
			var longueur = location.href.length;
			var page_courante = location.href.substring(pos_der_slash+1, pos_interro);
		}
		else
		{
			var page_courante = page;
			page_courante = page_courante.substring(0,page_courante.lastIndexOf("#"));
		}
		var adresse = page_courante + param + '&mode=imprim';
	}

	if( adresse.lastIndexOf("&mode=&mode=imprim") > 0 )
		adresse = replaceSubstring(adresse, "&mode=&mode=imprim", "&mode=imprim");

	var win;
	win = window.open (adresse, 'page2', 'toolbar=0,location=0,directories=0,history=0,status=0,menubar=0,scrollbars=1,resizable=0,left=40,top=150,width=595,height=500');
	if(flag==0)
	{
		flag = 1;
		win.focus();
	}
}

function openWindow(page)
{
	window.open(page,"","status=1,toolbar=1,location=1,directories=1,menuBar=1,scrollbars=1,resizable=yes,width=727,height=500,left=0,top=0");
}

function ident() {
	alert("L'accès à ce fichier est protégé.\nPour le télécharger veuillez vous identifier.");
	document.form1.ident.focus();
}

function identification() {
	if(ns4) {
		if ((document.layers['menus'].document.form1.ident.value.length > 0) && (document.layers['menus'].document.form1.ident.value != "Identification"))
		{
			document.layers['menus'].document.form1.password.value = prompt("Veuillez entrer votre mot de passe","");
			var pos_der_slash = location.href.substring(0,location.href.length-1).lastIndexOf('/');
			var longueur = location.href.length;
			var page_courante = location.href.substring(pos_der_slash+1, longueur);
			document.layers['menus'].document.form1.origine.value = page_courante;
			document.layers['menus'].document.form1.action = "../../include/identification.jsp";
			document.layers['menus'].document.form1.submit();
		}
		else
		{
			alert("Veuillez saisir un login.");
		}
	} else if (ie4 || ns6) {
		if ((document.form1.ident.value.length > 0) && (document.form1.ident.value != "Identification"))
		{
			document.form1.password.value = prompt("Veuillez entrer votre mot de passe","");
			var pos_der_slash = location.href.substring(0,location.href.length-1).lastIndexOf('/');
			var longueur = location.href.length;
			var page_courante = location.href.substring(pos_der_slash+1, longueur);
			document.form1.origine.value = page_courante;
			document.form1.action = "../../include/identification.jsp";
			document.form1.submit();
		}
		else
		{
			alert("Veuillez saisir un login.");
		}
	}
}

function chargement(message) {
	if ((message != "") && (message != "null"))
	{
		alert(message);
	}
}
