var JS_BUFFER_EVAL;
var JS_TEMPS_SESSION = "00:20:00";
var JS_FORMULAIRE_MODIFIE = false;
var JS_FORMULAIRE_EDITION = false;
var JS_BUFFER_EVAL;
var JS_IGNORER_MODIFS = false;


var iX, iY;
var jsListeParametres = "";
var jsFormulaireLangues = "";

var jsDialogues = new Array();
var jsVerrouilles = 0;

function aide(sRubrique, sSection) {
         if (sSection != null) 
            sSection = "#" + sSection;
         else
            sSection = "";

         parent.document.getElementById("ifrRubrique").contentWindow.document.location.href = '../aide/' + sRubrique + '.html' + sSection;
         parent.window.scroll(0, 0);
}


function quitter(sMessage) {
   if (jsBoiteMsg_Click == null) {
      msgQuestion("Attention!", analyserMessage(sMessage, null), "quitter();");
   }
   else if (jsBoiteMsg_Click == 'Oui') { 
      eval(JS_BUFFER_EVAL);
      JS_BUFFER_EVAL = null;
   }
}

function quitterApresModifs(sMessage) {
   if ((JS_FORMULAIRE_MODIFIE) && (!JS_IGNORER_MODIFS)) {
      if (jsBoiteMsg_Click == null) {
         msgQuestion("Attention!", analyserMessage(sMessage, null), "quitterApresModifs();");
      }
      else if (jsBoiteMsg_Click == 'Oui') { 
         eval(JS_BUFFER_EVAL);
         JS_BUFFER_EVAL = null;
      }
   }
   else {
      eval(JS_BUFFER_EVAL);
      JS_BUFFER_EVAL = null;
   }
}

function mnuQuitter_Click(sApplication) {
   JS_BUFFER_EVAL = "document.location.href = \"portail.asp?strApp=" + sApplication + "\"";
   quitterApresModifs(C001); 
}

function mnuDeconnecter_Click(sApplication) {
   JS_BUFFER_EVAL = "document.location.href = \"portail.asp?strSession=end&strApp=" + sApplication + "\"";

   if (JS_FORMULAIRE_MODIFIE)
      quitterApresModifs(C001); 
   else
      quitter(C006); 
}

var dlgAPropos, dlgAide;
function mnuAPropos_Click() {
   var sTableau = dlgEntete("A propos de l'extranet", 359, "hrefFermerAPropos_Click(this);") +
                "<table class=\"tdBoiteCorps\" border=\"0\" width=\"359\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">" + 
                "   <tr>";

   sTableau = sTableau + "<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">" + 
                   "   <tr>" + 
                   "      <td>" + 
                   "      <img width=\"100%\" src=\"" + SITE_WEB + "/gestion/images/aPropos.png\" alt=\"\" /> " +                   
                   "      </td>" + 
                   "   </tr>" + 
                   "   <tr>" + 
                   "      <td align=\"top\" style=\"font-size: 11px; font-weight: bold; width: 358px; height: 50px;\" valign=\"top\"><br>" + 
                   "      &nbsp;&nbsp;<input class=\"btnBouton\" name=\"btnOK\" type=\"button\" value=\"Fermer cette fenêtre\" style=\"width: 110px;\" onclick=\"hrefFermerAPropos_Click();\">" +
                   "      </td>" + 
                   "   </tr>" + 
                   "</table></td></tr>" +
                   "</table>";

   verrouillerInterface(true);
   dlgAPropos = new CalqueClasse("dlgAPropos", 363, 380, true);
   dlgAPropos.remplirCalque(sTableau, null, null, "layBoiteMsg");
   dlgAPropos.asgCalque(document.getElementsByTagName("BODY")[0].id);
   dlgAPropos.asgPositionFormatee(jsCenteredCentered);
   dlgAPropos.visibleCalque(true);
}

function mnuRubrique_Click(sRubrique) {
   var sTableau = dlgEntete("Rubriques d'aide", 800, "hrefFermerAide_Click(this);") +
                "<table class=\"tdBoiteCorps\" border=\"0\" width=\"800\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">" + 
                "   <tr>";

   sTableau = sTableau + "<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"490\">" +
                   "   <tr>" + 
                   "      <td valign=\"center\" style=\"width: 30px; border-left: 1px solid #cdcbcb ; border-top: 1px solid #cdcbcb; background-image: url(\'" + SITE_WEB + "/gestion/images/listeFond.png\'); height: 20px;\">" +
                   "      <b>Rubriques</b>  " + 
                   "      </td>" + 
                   "      <td id=\"tdSeparateur\" valign=\"center\" style=\"border-top: 1px solid #cdcbcb; background-image: url(\'" + SITE_WEB + "/gestion/images/listeFond.png\'); width: 7px; height: 20px;\">" +
                   "      <img src=\"" + SITE_WEB + "/gestion/images/iconeSeparateurListe.png\" /> " + 
                   "      </td>" + 
                   "      <td valign=\"center\" style=\"width: 30px; border-right: 1px solid #cdcbcb ; border-top: 1px solid #cdcbcb; background-image: url(\'" + SITE_WEB + "/gestion/images/listeFond.png\'); height: 20px;\">" +
                   "      &nbsp;&nbsp;<b>Aide</b> " + 
                   "      </td>" + 
                   "   </tr>" +     
                   "   <tr>" + 
                   "      <td>" + 
                   "      <iframe scrolling=\"yes\" id=\"ifrListeRubriques\" name=\"ifrListeRubriques\" style=\"width: 200px; height: 100%; background-color: #FFFFFF;\"\" frameborder=\"0\" src=\"about:blank\"></iframe>" +                   
                   "      </td>" +
                   "      <td width=\"7\"></td>" + 
                   "      <td>" + 
                   "      <iframe scrolling=\"yes\" id=\"ifrRubrique\" name=\"ifrRubrique\" style=\"width: 589px; height: 100%; background-color: #FFFFFF;\"\" frameborder=\"0\" src=\"about:blank\"></iframe>" +
                   "      </td>" +                     
                   "   </tr>" + 
                   "   <tr>" + 
                   "      <td align=\"top\" style=\"font-size: 11px; font-weight: bold; width: 358px; height: 50px;\" valign=\"top\" colspan=\"3\"><br>" + 
                   "      &nbsp;&nbsp;<input class=\"btnBouton\" name=\"btnOK\" type=\"button\" value=\"Fermer cette fenêtre\" style=\"width: 110px;\" onclick=\"hrefFermerAPropos_Click();\">" +
                   "      </td>" + 
                   "   </tr>" + 
                   "</table></td></tr>" +
                   "</table>";

   verrouillerInterface(true);
   dlgAide = new CalqueClasse("dlgAide", 800, 500, true);
   dlgAide.remplirCalque(sTableau, null, null, "layBoiteMsg");
   dlgAide.asgCalque(document.getElementsByTagName("BODY")[0].id);
   document.getElementById("ifrListeRubriques").contentWindow.document.location.href = 'aide/rubriques.html';
   document.getElementById("ifrRubrique").contentWindow.document.location.href = 'aide/' + ((sRubrique != null) ? sRubrique : 'intro') + '.html';
   
   dlgAide.asgPositionFormatee(jsCenteredCentered);
   dlgAide.visibleCalque(true);
}

function hrefFermerAPropos_Click(obj) {
   dlgAPropos.visibleCalque(false);
   verrouillerInterface(false);
}

function hrefFermerAide_Click(obj) {
   dlgAide.visibleCalque(false);
   verrouillerInterface(false);
}

function gestionnaireCourant() {
   var sGestionnaire;
   
   sGestionnaire = document.location.href.replace(/(http\:(.)*\/)/, "");
   sGestionnaire = sGestionnaire.replace(/\.asp?(.)*/, "");
   return sGestionnaire;
}

function mnuDiriger_GesUtilisateurs_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesUtilisateurs.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesTextes_Click() {

   JS_BUFFER_EVAL = "document.location.href = \"gesTextes.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesProduits_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesProduits.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesImages_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesImages.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesDemandes_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesDemandesPrix.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesMenus_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesMenus.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function mnuDiriger_GesObjets_Click() {
   JS_BUFFER_EVAL = "document.location.href = \"gesObjets.asp?strProvenance=" + gestionnaireCourant() + "\"";
   quitterApresModifs(C001); 
}

function calculerExpiration() {
   try {
         if (document.getElementById("txtExpiration") != null) {
            var aHeureMinSec = document.getElementById("txtExpiration").value.split(":");

            var sRegExp = eval("/0(?=[0-9])/g");
            iHeures   = parseInt(aHeureMinSec[0].replace(sRegExp, ""));
            iMinutes  = parseInt(aHeureMinSec[1].replace(sRegExp, ""));
            iSecondes = parseInt(aHeureMinSec[2].replace(sRegExp, ""));

            if ((iSecondes == 0) && (iMinutes == 0) && (iHeures == 0)) {
               document.getElementById("txtExpiration").value = "00:00:00";
               clearInterval(jsCompteur);
               msgAlerte("Attention!", "Le temps de votre session est &eacute;coul&eacute;.  Par mesures de s&eacute;curit&eacute;, vous devrez vous identifier de nouveau lorsque vous rafra&icirc;chirez cette page.");
               desactiverControlesFormulaire();
            }
            else {
               if (iSecondes > 0) {
                  iSecondes--;
               }
               else {
                  iSecondes = "59";
                  if (iMinutes > 0) {
                     iMinutes--;
                  }
                  else {
                     iMinutes = "59";
                     iHeures--;      
                  }
               }
               iHeures = (String(iHeures).length == 1) ? "0" + String(iHeures) : String(iHeures);
               iMinutes = (String(iMinutes).length == 1) ? "0" + String(iMinutes) : String(iMinutes);
               iSecondes = (String(iSecondes).length == 1) ? "0" + String(iSecondes) : String (iSecondes);

               document.getElementById("txtExpiration").value = iHeures + ":" + iMinutes + ":" + iSecondes;
            }

         }
   }
   catch (e) { }
}

function desactiverControlesFormulaire() {
   var objSelection = document.getElementsByTagName("SELECT");
   var objBoutons = document.getElementsByTagName("BUTTON");
   var objInputs = document.getElementsByTagName("INPUT");

   // désactiver toutes les balises de type <SELECT>
   if (objSelection != null) {
      for (var i = 0; i < objSelection.length; i++)
         objSelection[i].disabled = true;
   }

   // désactiver toutes les balises de type <BUTTON>
   if (objBoutons != null) {
      for (var i = 0; i < objBoutons.length; i++)
         objBoutons[i].disabled = true;
   }

   // désactiver toutes les balises de type <INPUT>   
   if (objInputs != null) {
      for (var i = 0; i < objInputs.length; i++)
         if ((objInputs[i].type.toUpperCase().match(/^(HIDDEN)$/) == null) && (objInputs[i].id.toUpperCase() != "BTNDIALOGUE"))
            objInputs[i].disabled = true;
   }
   
}

function hrefFermerRepertoires_Click(obj) {
   if (dlgAjoutRepertoires != null) {
   
      document.getElementById('ifrListeFichiers').contentWindow.btnAnnulerRepertoire_Click(obj);
   }

   dlgBoiteRepertoires.visibleCalque(false);
   jsDialogues.pop();
   verrouillerInterface(false);
}

function hrefFermerLangues_Click(obj) {
   dlgBoiteLangues.visibleCalque(false);
   jsDialogues.pop();
   verrouillerInterface(false);
}


function verrouillerInterface(bLectureSeule) {
   jsVerrouilles = jsDialogues.length;

   if (bLectureSeule) {
//      document.body.style.overflow = "hidden";
      objProtecteur = new CalqueClasse("objProtecteur", document.body.scrollWidth, document.body.scrollHeight, true);
      objProtecteur.remplirCalque("&nbsp;", null, null);
      objProtecteur.asgCalque(document.getElementsByTagName("BODY")[0].id);
      objProtecteur.asgPositionFormatee(jsTopLeft);
      objProtecteur.asgTransparence(50);
      objProtecteur.visibleCalque(true);
   }
   else if ((objProtecteur != null) && (jsVerrouilles == 0)) {
      objProtecteur.supprimerCalque();
   }
   else if ((jsVerrouilles > 0) && (jsDialogues[jsDialogues.length-1] != '__default')) {
      eval(jsDialogues[jsDialogues.length-1] + ".mettreAvantPlan()");
   }
}

function marquerLibellesLecture(obj, bLectureSeule) {
   // mettre en évidence les champs en lecture seule
   for (var i = 0; i < obj.elements.length; i++) {
      if (dans(obj.elements[i].className, new Array("txtEdition", "memMemo", "cmbCombos", "btnComboBox"))) {
         if (obj.elements[i].readOnly) {
            obj.elements[i].style.backgroundImage = (bLectureSeule) ? "url('" + SITE_WEB + "/gestion/images/iconeLectureSeule.png')" : "";
         }
         else if (obj.elements[i].disabled) {
            obj.elements[i].style.MozOpacity = (bLectureSeule) ? "0.5" : "1";
         }
      }
   }
}

function identifierChampsRecherche(strFormulaire, arrChamps, bRecherche) {
   var obj;
   for (var i = 0; i < arrChamps.length; i++) {
      obj = eval("document." + strFormulaire + "." + arrChamps[i]);
      if (!obj.readOnly)
         obj.style.backgroundImage = (bRecherche) ? "url('" + SITE_WEB + "/gestion/images/iconeConsulter.png')" : "";
      else
         obj.style.backgroundImage = (bRecherche) ? "url('" + SITE_WEB + "/gestion/images/iconeConsulterLectureSeule.png')" : "";
   }
}


function enableControl(objControl, bControl) {
   objControl.disabled = !bControl;
   objControl.style.MozOpacity = (!bControl) ? "0.5" : "1";
}

function validerChampsObligatoires(aChamps) {
   for (var i = 0; i < aChamps.length; i++) {
      if ((aChamps[i] == null) || (aChamps[i].replace(/^\s+|\s+$/g,"") == "")) {
         return false;
      }
   }
   return true;
}

function validerSyntaxeAlphaNum(aChamps) {
   for (var i = 0; i < aChamps.length; i++) {
      if (aChamps[i].value.replace(/[\w\-\s]/g, "") != "") {
         return false;
      }
   }
   return true;
}

function validerSyntaxeNum(aChamps) {
   for (var i = 0; i < aChamps.length; i++) {
      if (aChamps[i].value.replace(/[0-9]/g, "") != "") {
         return false;
      }
   }
   return true;
}

function sauvegarderCoord(e) {
   iX = (document.all) ? event.clientX : e.pageX;
   iY = (document.all) ? event.clientY : e.pageY;
}

function btnNaviguerRepertoires_Click(obj) {       
   jsDialogues.push("dlgBoiteRepertoires");
   dlgRepertoires("Parcourir l'arbre de r&eacute;pertoires", jsCenteredCentered);
}

var jsQuitter;
function btnDlgLangues_Click(obj, sFormulaire, blnQuitter) {
   jsFormulaireLangues = sFormulaire;
   jsQuitter = blnQuitter;
   jsDialogues.push("dlgBoiteLangues");
   
   dlgLangues("Affichage du choix de langues", jsCenteredCentered);     
}

function btnLangueChoisie_Click(obj, sFormulaire, blnQuitter) {
   if (jsQuitter) {
      JS_BUFFER_EVAL = "validerLangueChoisie(document.getElementById(\"txtLangue\"), '" + sFormulaire + "');"
      quitterApresModifs(C001);
   }
   else {
      validerLangueChoisie(obj, sFormulaire);
   }
}

function validerLangueChoisie(obj, sFormulaire) {
   if (affecterChoixAttribut("ifrListeLangues", "frmGesLangues", jsFormulaireLangues, "hidNoLangue", "txtLangue", analyserMessage(E015, Array("exactement une langue")))) {
      txtLangue_Change(obj);
      hrefFermerLangues_Click();
   }

}

function affecterChoixAttribut(sIFRAME, sFORM, sFORMCible, sHID, sVAL, sMessageErreur) {
   var iCoche = 0;
   var objAttrSelectionne;

   var sSelection = document.getElementById(sIFRAME).contentWindow.document.getElementById("hidValeurSelectionnee").value;
   var objAttrSelectionne = document.getElementById(sIFRAME).contentWindow.document.getElementById(sSelection);

   if (sSelection == "") {
      msgErreur("Erreur de s&eacute;lection", sMessageErreur);
      return false;
   }

   if (sHID != "")
      (eval("document." + sFORMCible + "." + sHID)).value = sSelection;

   if (sVAL != "") {
      var objRecepteur = (eval("document." + sFORMCible + "." + sVAL));
      objRecepteur.value = document.getElementById(sIFRAME).contentWindow.document.getElementById("div" + sSelection).innerHTML.replace(/\&nbsp\;\s/g, "");
      objRecepteur.value = objRecepteur.value.replace(/\&amp\;/g, "&");
   }      
   return true;
}

var jsComboBox = new Array();
function actualiserSelection(sComboBox, sSelectCible, strValeurDefaut) {
   if ((sComboBox == null) || (sComboBox == ""))
      return;

   var iNbElements = nbComboBox(sComboBox) ;
   document.getElementById(sSelectCible).innerHTML = '';            
   if ((iNbElements == null) || (actualisationEnCours(sComboBox))) {
      if (!jsComboBox[sComboBox]) {
//         msgOnTop("Veuillez patienter . . .", "Récupération des données en cours . . .");
         jsComboBox[sComboBox] = true;
      }
      setTimeout("actualiserSelection('" + sComboBox + "', '" + sSelectCible + "', '" + strValeurDefaut + "');", 400);
   }
   else {
      jsComboBox[sComboBox] = false;
      for (var i = 0; i < iNbElements; i++) {
         document.getElementById(sSelectCible).options[i] = new Option(seqComboBox(sComboBox, i),idComboBox(sComboBox, i));
         if (idComboBox(sComboBox, i) == strValeurDefaut) 
            document.getElementById(sSelectCible).options[i].selected = true;
      }
   }   
}

function exec(strFonction, strComboBox) {   
   if ((strFonction == null) || (strComboBox == null))
      return;

   var iNbElements = nbComboBox(strComboBox) ;

   if ((iNbElements == null) || (actualisationEnCours(strComboBox))) {
      if (!jsComboBox[strComboBox]) {
         msgOnTop("Veuillez patienter . . .", "Opération en cours . . .");
         jsComboBox[strComboBox] = true;
      }
      setTimeout("exec('" + strFonction + "', '" + strComboBox + "');", 400);
   }
   else {
      jsComboBox[strComboBox] = false;
      eval(strFonction);
   }   
}


function txtNouveauRepertoire_Focus(obj) {
   JS_FORMULAIRE_EDITION = true;
}

function txtNouveauRepertoire_Blur(obj) {
   JS_FORMULAIRE_EDITION = false;
}

function txtNouvelleLangue_Focus(obj) {
   JS_FORMULAIRE_EDITION = true;
}

function txtNouvelleLangue_Blur(obj) {
   JS_FORMULAIRE_EDITION = false;
}

function txtRepertoireStatique_Focus(obj) {
   JS_FORMULAIRE_EDITION = true;
}

function txtRepertoireStatique_Blur(obj) {
   JS_FORMULAIRE_EDITION = false;
}
