
var browserVersion = parseInt(navigator.appVersion);
var visiteur = "";

/*****
 * YESNOBox : Permet d'afficher une simple boite de confirmation. Si l'usager clique "ok", la fonction 
 * 					   renvoi vrai ou faux dans le cas ou l'usager clique "annuler"		
 */  
function YESNOBox(msg)
 {
 	return window.confirm(msg);
 }
 
/*****
* setFocus :
*/
 function setFocus(element) 
 {
        element.focus();
        return;
}

function Surbrillance(idMot, idMotEnd)
	{
	var oRange = document.getElementById("bodyID").createTextRange();
	oRange.moveToElementText(idMot);
	oRange.select();
	if(idMotEnd != "")
	{
		oRange.moveToElementText(idMotEnd);
		oRange.moveStart("sentence", 1);
	}
	else
	{
		oRange.moveEnd("sentence", 1);
	}
	oRange.scrollIntoView();
	}
	

function ChangerHeure(flagSetInterval)
{
    	VarTemp = new Date();
    	VarTemp1 = VarTemp.getMinutes();
    	VarTemp1 = VarTemp1.toString();
	if (VarTemp1.length < 2) VarTemp1 = "0" + VarTemp1;
    	VarTemp2 = VarTemp.getHours();
	if (VarTemp2 >= 17) VarTemp3 = "Il est ";
	else VarTemp3 = "Il est ";
    	VarTemp2 = VarTemp2.toString();
	if (VarTemp2.length < 2) VarTemp2 = "0" + VarTemp2;
	document.getElementById("heure").innerHTML = VarTemp3 + VarTemp2 + ":" + VarTemp1;
	if(!flagSetInterval)
		window.setInterval('ChangerHeure(true)', 60000);
}

var indTabMemoRech = -1;
var indTabMemoRech1 = -1;

function RechercherTexte(texte, idZoneRecherche, idZonePatience, flagZonePatience, gauche, largeur, sommet, hauteur)
{
   texte = trim(texte);
   if (texte == "")
   {
	window.alert("Veuillez saisir un ou plusieurs mots à rechercher.");
   }
   else
   {
   	var oRange = null;
   	var oRange1 = document.getElementById("bodyID").createTextRange();
	var trouveMemo = false;
	var trouve = false;	
	var i = -1;
	var ii = -1;
	var flagRech = true;

	if (gauche == null || sommet == null || hauteur == null || largeur == null)
	{
		gauche = document.getElementById(idZoneRecherche).offsetLeft;
		sommet = document.getElementById(idZoneRecherche).offsetTop;
		hauteur = document.getElementById(idZoneRecherche).offsetHeight;
		largeur = document.getElementById(idZoneRecherche).offsetWidth;
	}

	if (flagZonePatience && idZonePatience != "" && idZonePatience != null)
	{
		document.getElementById(idZonePatience).style.top = document.getElementById(idZoneRecherche).offsetTop + document.getElementById(idZonePatience).offsetHeight;
		document.getElementById(idZonePatience).style.left = document.getElementById(idZoneRecherche).offsetLeft + (document.getElementById(idZoneRecherche).offsetWidth / 2 - document.getElementById(idZonePatience).offsetWidth / 2);
		document.getElementById(idZonePatience).style.visibility = "visible";
		var string = "RechercherTexte('" + texte + "', '" + idZoneRecherche + "', '" + idZonePatience + "', false, " + gauche + ", " + largeur + ", " + sommet + ", " + hauteur + ");";
		window.setTimeout(string, 1);
		return;
	}

	//Pour déselectionner les zones de la recherhce précédente
	for(i=indTabMemoRech1+1; i<=indTabMemoRech; i++)
	{
		document.getElementById('rechMot' + i).style.color = '';
		document.getElementById('rechMot' + i).style.backgroundColor = '';
	}
	indTabMemoRech1 = indTabMemoRech;

	while(flagRech)
	{
		i = texte.indexOf(" ", i + 1);
		if (i == -1)
		{
			texte1 = texte.substring(ii + 1, texte.length);
			flagRech = false;
		}
		else
			texte1 = texte.substring(ii + 1, i);
		ii = i;
	   	
		oRange = document.getElementById("bodyID").createTextRange();
		trouve = oRange.findText(texte1, 1);
		if (!trouveMemo) 
			oRange1.findText(texte1, 1);

		//Rechercher de la zone de recherche (premier mots)
		while(!((oRange.offsetTop <= sommet + hauteur) && (oRange.offsetLeft <= gauche + largeur) && (oRange.offsetLeft >= gauche) && (oRange.offsetTop >= sommet)) && trouve)
		{
		        oRange.moveStart("character", 1);
			trouve = oRange.findText(texte1, 1);
			if (!trouveMemo) {				
			        oRange1.moveStart("character", 1);
				oRange1.findText(texte1, 1);
			}
		}
		if(trouve && !trouveMemo) 
			trouveMemo = true;
		//Rechercher dans la zone de recherche (tous les mots trouvés)
		while(((oRange.offsetTop <= sommet + hauteur) && (oRange.offsetLeft <= gauche + largeur) && (oRange.offsetLeft >= gauche) && (oRange.offsetTop >= sommet)) && trouve)
		{
			//Mettre les mots en surbrillance
	   		if (trouve) {
				indTabMemoRech += 1;
				oRange.pasteHTML("<span id='rechMot" + indTabMemoRech + "' style='color:#ffffff; background-color:rgb(0,0,128)'>" + texte1 + "</span>");
			}
		        oRange.moveStart("character", 1);
			trouve = oRange.findText(texte1, 1);
		}
	}

	if (trouveMemo) {
		oRange1.scrollIntoView();
	}
	else
		window.alert("Désolé, il n'existe pas d'expression correspondant à votre recherche.");

	if (idZonePatience != "" && idZonePatience != null)
	{
		document.getElementById(idZonePatience).style.visibility = "hidden";
	}
   }
}

function ChangerInnerTextMenu(idMenu, idTextMenu)
{
	var a = "";
	var b = "";
	var c = "";
	for(i = 0; i < 10; i++)
	{
		j = 1;
		a = new String(i);
		b = new String(j);
		c = "TDm" + a + "sm" + b;
		while(document.getElementById(c) != null)
		{
			document.getElementById(c).innerHTML = "<img src='images/puceclose.gif'>";
			//document.getElementById(c).style.color = "#333366";
			//c = "m" + a + "sm" + b;
			//document.getElementById(c).style.color = "#333366";
			j = j + 1;
			b = new String(j);
			c = "TDm" + a + "sm" + b;
		}
	}
	document.getElementById(idTextMenu).innerHTML = "<img src='images/puceopen.gif'>";
	//document.getElementById(idTextMenu).style.color = "#cc6633";
	//document.getElementById(idMenu).style.color = "#cc6633";
}

function trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1)
		return"";
	TRIM_VALUE = rTrim(TRIM_VALUE);
	TRIM_VALUE = lTrim(TRIM_VALUE);
	return TRIM_VALUE;
}

function rTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
		return "";
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
}

function lTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
		return "";
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
}

function verifProfilAdmin()
{

   var fso = new ActiveXObject("Scripting.FileSystemObject");
   // var url = unescape(self.location.pathname);
   // var dir = fso.GetParentFolderName(url).substr(1);
   var dir = "";
   var PathFich = "";
   var ts, s;
   
   PathFich = "c:\\winnt\\system32\\";
   if (!fso.FolderExists(PathFich))
   {
      PathFich = "c:\\windows\\system\\";
   }
   dir = PathFich;
   
   // Lecture, écriture ou écriture à la fin ?
   var ForReading = 1, ForWriting = 2, ForAppending = 8;
   // Path du fichier
   PathFich = dir + "test_profil_admin.txt";
   
   // Créer un fichier
   ts = fso.CreateTextFile(PathFich);
   ts.Close();
   
   // Ouvrir pour écrire (crée automatiquement si true)
   // ts = fso.OpenTextFile(PathFich, ForWriting , false);
   // Ecrire dans un fichier
   // ts.WriteLine("");
   // ts.Close();
   
   // Tester l'existence
   if (fso.FileExists(PathFich))
   {
      alert("Votre profil est de type 'Administrateur'.");
      // Détruire un fichier
      fso.DeleteFile(PathFich);
   }
   else
   {
      alert("Votre profil n'est pas de type 'Administrateur'.");
   }

}

function verifADO()
{

   var fso = new ActiveXObject("Scripting.FileSystemObject");
   var PathFich = "";
   
   PathFich = "c:\\program files\\fichiers communs\\system\\ado\\";
   if (fso.FolderExists(PathFich))
   {
      alert("L'ADO est installé sur votre ordinnateur.");
   }
   else 
   {
      PathFich = "c:\\program files\\common files\\system\\ado\\";
      if (fso.FolderExists(PathFich))
      {
         alert("L'ADO est installé sur votre ordinnateur.");
      }
      else
      {
         alert("L'ADO doit être installé sur votre ordinnateur.");
      }
   }

}
