// texte contient le message à afficher par défaut
var msgStatus="Agence de Développement Touristique de la Nièvre";
window.defaultStatus=msgStatus;


function AfficheMaxi(inPATH) {
 var i1 = new Image;
 i1.src = inPATH;
 html = '<HTML><HEAD><TITLE>Image</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+inPATH+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER></BODY></HTML>';
 var popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,top=100,left=100');
 popupImage.document.open();
 popupImage.document.write(html);
 popupImage.document.close()
};

 function openEcomImg(inFormBack, inImg, inPath) {
 var leftPos = (screen.availWidth-700) / 2;
 var topPos = (screen.availHeight-500) / 2;
 var imageWin = window.open('../Portal_HtmlEditor/Popups/HE_Images.asp?mode=Ecom&f_win=EcomImg&h_imgchange='+ inImg +'&h_inPath=' + inPath + '&f_form=' + inFormBack,'EcomImg','width=700,height=500,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
}

 function openEcomFile(inFormBack, inPath) {
 var leftPos = (screen.availWidth-700) / 2;
 var topPos = (screen.availHeight-500) / 2;
 var imageWin = window.open('/..Portal_HtmlEditor/Popups/HE_Files.asp?h_inPath=' + inPath + '&h_formback=' + inFormBack,'','width=700,height=500,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
}

function OpenW(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

function message(txt) {
	window.status=txt;
}

function verifPdtAff() {
 if (ADM_PDT_AFFL2.REF.value.length==0) {
  alert('Saisissez une référence.');
  ADM_PDT_AFFL2.REF.focus();
return false;
}
else{
return true;
}
}

function MsgDelete(category) {
	if (confirm("Vous allez supprimer la catégorie ainsi que toutes ses filles.\nDésirez-vous continuer ?"))
	{
	document.location.href="?mode=catdelete&Category="+category;}
return;	
}

function caddy(idform) {
	var Limite=""
	var refAtt=""
    var fEcom = eval('document.forms[idform]');
	var qte = fEcom.qte_produit.value;
	var idpdt = fEcom.id_produit.value;
	var Att = ""
	if (fEcom.CheckAttribut.value == "1"){
		totAtt = "Tot_Att_"+idpdt;
		Limite = eval('document.forms[idform].'+totAtt+'.value');
		var refAtt = ""
		for (i=0; i<Limite; i++)
		{
			lstNb = eval('document.forms[idform].List_'+i+'.value');
			refAtt = refAtt + lstNb;
			b=i;
			if (b+1<Limite){refAtt = refAtt + ",";}
		}
		Att = "&TotAtt="+Limite+"&ListAtt=" + refAtt;
		}
	fEcom.id_produit.value = idpdt;
	fEcom.qte_produit.value = qte;
	fEcom.TotAtt.value = Limite;
	fEcom.ListAtt.value = refAtt;
	fEcom.mode.value="PopUpCaddy";
	fEcom.submit;
}


function checkEmail(myItem){
  if((myItem.value.search(/[A-Za-z 0-9_-]*@[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/gi) == -1)){
alert('Veuillez vérifier votre adresse email.');
return false;
}
else{
return true;
}
}

function javCheck(user) {
 if (document.ADM_USER_ADD_REP.LOGIN.value.length==0) {
  alert('Login obligatoire.');
 document.ADM_USER_ADD_REP.LOGIN.focus();
return false;
}
 if (user=="0") {
 if (document.ADM_USER_ADD_REP.PASSW.value.length<8) {
  alert('Le mot de passe doit contenir huit caractères au minimum.');
 document.ADM_USER_ADD_REP.PASSW.focus();
return false;
}
 if (document.ADM_USER_ADD_REP.PASSW.value!=document.ADM_USER_ADD_REP.PASSW1.value) {
  alert('Les mots de passe sont différents.');
 document.ADM_USER_ADD_REP.PASSW1.value="";
 document.ADM_USER_ADD_REP.PASSW1.focus();
return false;
}
}
 else {
 if (document.ADM_USER_ADD_REP.PASSW.value.length!=0) {
 if (document.ADM_USER_ADD_REP.PASSW.value.length<8) {
  alert('Le mot de passe doit contenir huit caractères au minimum.');
 document.ADM_USER_ADD_REP.PASSW.focus();
return false;
}
 if (document.ADM_USER_ADD_REP.PASSW.value!=document.ADM_USER_ADD_REP.PASSW1.value) {
  alert('Les mots de passe sont différents.');
 document.ADM_USER_ADD_REP.PASSW1.value="";
 document.ADM_USER_ADD_REP.PASSW1.focus();
return false;
}
}
}
 if (document.ADM_USER_ADD_REP.FIRST.value.length==0) {
  alert('Prénom obligatoire.');
 document.ADM_USER_ADD_REP.FIRST.focus();
return false;
}
 if (document.ADM_USER_ADD_REP.LAST.value.length==0) {
  alert('Nom obligatoire.');
 document.ADM_USER_ADD_REP.LAST.focus();
return false;
}
 if (document.ADM_USER_ADD_REP.DISPNAME.value.length==0) {
  alert('Champs obligatoire.');
 document.ADM_USER_ADD_REP.DISPNAME.focus();
return false;
}
 if (document.ADM_USER_ADD_REP.EMAIL.value.length==0) {
  alert('Adresse email obligatoire.');
 document.ADM_USER_ADD_REP.EMAIL.focus();
return false;
}
if (!checkEmail(document.ADM_USER_ADD_REP.EMAIL))
return false;
document.ADM_USER_ADD_REP.submit();
}

function javCancel() {
 history.go(-1);
}

function goToGroupe(laPage, leMode, leGroupe, laTarget) {
fEcom = eval("document.forms[1]");
  fEcom.h_mode.value = leMode;
  fEcom.h_GroupId.value = leGroupe;
  fEcom.target = laTarget;
  fEcom.action = laPage;
  if (leMode == "GroupDelete") {
    if (confirm("Attention : Vous allez effacer ce Groupe et toutes les informations s\'y rapportant")) {
      fEcom.submit();
    }
  } else {
    fEcom.submit();
  }
};

function goToCat2(laPage, leMode, laCat, laTarget) {
fEcom = eval("document.forms[1]");
  fEcom.h_mode.value = leMode;
  fEcom.h_CatId.value = laCat;
  fEcom.Category.value = laCat;
  fEcom.target = laTarget;
  fEcom.action = laPage;
/*	alert("nom formulaire : " + fEcom.name);*/

  if (leMode == "CatDelete") {
    if (confirm("Attention : Vous allez effacer cette Catégorie et toutes les informations s\'y rapportant")) {
     	fEcom.submit();
    }
  } else {
/*	alert("nom formulaire : " + fEcom.name);*/
	fEcom.submit();
/*	 parent.frames[1].document.write(fEcom.name);*/
/*	 document.write(fEcom.name);*/
  }
};

function goToCat(laPage, leMode, laCat, laTarget) {
fEcom = eval("document.forms[1]");
  fEcom.h_mode.value = leMode;
  fEcom.h_CatId.value = laCat;
  fEcom.target = laTarget;
  fEcom.action = laPage;
/*	alert("nom formulaire : " + fEcom.name);*/

  if (leMode == "CatDelete") {
    if (confirm("Attention : Vous allez effacer cette Catégorie et toutes les informations s\'y rapportant")) {
     	fEcom.submit();
    }
  } else {
/*	alert("nom formulaire : " + fEcom.name);*/
	fEcom.submit();
/*	 parent.frames[1].document.write(fEcom.name);*/
/*	 document.write(fEcom.name);*/
  }
};


function loadCat(laPage, leMode, laTarget) {
  fEcom = eval("document.forms[1]");
  leTemp = eval("document.forms[1].s_GroupId");
  if (leTemp) {
    fEcom.h_GroupId.value = fEcom.s_GroupId.options[document.fEcom.s_GroupId.selectedIndex].value;
    fEcom.h_GroupDescr.value = fEcom.s_GroupId.options[fEcom.s_GroupId.selectedIndex].text;
  } else {
    fEcom.h_GroupId.value = fEcom.sh_GroupId.value;
    fEcom.h_GroupDescr.value = fEcom.sh_GroupDescr.value;
  }
  fEcom.h_mode.value = leMode;
  fEcom.target = laTarget;
  fEcom.action = laPage;
  fEcom.submit();
};

function jsTrim(monItem) {
  var monTexte = new String("");
  monTexte = monItem.value;
  while (monTexte.charAt(0) == ' ') {
    monTexte = monTexte.substring(1,monTexte.length);
  }
  while (monTexte.charAt(monTexte.length - 1) == ' ') {
    monTexte = monTexte.substring(0, (monTexte.length - 1));
  }
  monItem.value = monTexte;
};

function jsUCase(monItem) {
  var monTexte = "" + monItem.value;
  monItem.value = monTexte.toUpperCase();
};

function switchSelect(slt_1, slt_2, type) {
  // s_1   : le select de depart
  // s_2   : le select arrivee
  // type  : type du switch - 'one' / 'all' - determine le passage
  var myForm = this.document.forms[1], sltFrom, sltTo, uneOption, tot1, tot2, i = 0, leCompteur = 0;
  sltFrom = eval("myForm." + slt_1);
  sltTo = eval("myForm." + slt_2);
  if (sltFrom.length > 0) {
    if (type == "one") {
      for (i = 0; i < sltFrom.length; i++) {
	if (sltFrom.options[i].selected == true) {
	  leCompteur = 1;
	  break;
	}
      };
      if (leCompteur == 1) {
	leCompteur = 0;
	for (i = 0; i < sltFrom.length; i++) {
	  if (sltFrom.options[i].selected == true) {
	    leCompteur++;
	  }
	};
	for (i = 0; i < leCompteur; i++) {
	  uneOption = new Option(sltFrom.options[sltFrom.selectedIndex].text, sltFrom.options[sltFrom.selectedIndex].value, false, false);
	  sltTo.options[sltTo.length] = uneOption;
	  sltFrom.options[sltFrom.selectedIndex] = null;
	};
      } else {
	alert("Il n\'y a pas d\'option(s) sélectionnée(s).");
      }
    } else {
      leCompteur = sltFrom.length;
      for (i = 0; i < leCompteur; i++) {
	uneOption = new Option(sltFrom.options[0].text, sltFrom.options[0].value, false, false);
	sltTo.options[sltTo.length] = uneOption;
	sltFrom.options[0] = null;
      };
    }
  } else {
    alert("Il n\'y a plus d\'options à deplacer dans ce sens.");
  }
};

function resetSwitch(hid_1, hid_2, slt_1, slt_2, fld_1, fld_2) {
  // hid_1 : Hidden name pour remplir le premier select
  // hid_2 : Hidden name pour remplir le deuxieme select
  // slt_1 : Nom du premier select
  // slt_2 : Nom du deuxieme select
  // fld_1 : Nom du Recherche 1
  // fld_2 : Nom du Recherche 2
  var myForm = this.document.forms[1], i = 0, leCompteur = 0, hid1, hid2, slt1, slt2, tot1, tot2, fld1, fld2;
  
  hid1 = eval("myForm." + hid_1);
  hid2 = eval("myForm." + hid_2);
  slt1 = eval("myForm." + slt_1);
  slt2 = eval("myForm." + slt_2);
  tot1 = eval("myForm." + hid_1 + "_TOT");
  tot2 = eval("myForm." + hid_2 + "_TOT");
  
  leCompteur = slt1.length;
  for (i = 0; i < leCompteur; i++) {
    slt1.options[0] = null;
  };
  if (tot1.value > 0) {
    leCompteur = 0;
    for (i = 0; i < hid1.length; i = i + 2) {
      uneOption = new Option(hid1[i + 1].value, hid1[i].value, false, false);
      slt1.options[leCompteur] = uneOption;
      leCompteur++;
    };
  }

  leCompteur = slt2.length;
  for (i = 0; i < leCompteur; i++) {
    slt2.options[0] = null;
  };
  if (tot2.value > 0) {
    leCompteur = 0;
    for (i = 0; i < hid2.length; i = i + 2) {
      uneOption = new Option(hid2[i + 1].value, hid2[i].value, false, false);
      slt2.options[leCompteur] = uneOption;
      leCompteur++;
    };
  }

  if (fld_1 != "") { 
    fld1 = eval("myForm." + fld_1);
    fld1.value = "";
  }
  if (fld_1 != "") { 
    fld2 = eval("myForm." + fld_2);
    fld2.value = "";
  }

};

function validSwitch(slt) {
  // slt : Select valide
  var myForm = this.document.forms[1], leSlt, i = 0;
  leSlt = eval("myForm." + slt)
  for (i = 0; i < leSlt.length; i++) {
    leSlt.options[i].selected = true;
  };
  document.forms[1].submit();
};

function autoSelect(fld, slt) {
  // fld : Field de saisie
  // slt : Select de destination
  var myForm = this.document.forms[1], leFld, leSlt, leTxt = "", laTaille = 0, i = 0, j = 0, leTest = "";
  leFld = eval("myForm." + fld)
  leSlt = eval("myForm." + slt)
  leTxt = ("" + leFld.value).toUpperCase();
  laTaille = leTxt.length;
  if (leTxt != "") {
    for (i = 0; i < leSlt.length; i++) {
      leTest = leSlt.options[i].text;
      leTest = (leTest.substring(0, laTaille)).toUpperCase();
      if (leTest == leTxt) {
        for (j = 0; j < leSlt.length; j++) {
          leSlt.options[j].selected = false;
        };
	leSlt.options[i].selected = true;
        break;
      }
    };
  } else {
    for (i = 0; i < leSlt.length; i++) {
      leSlt.options[i].selected = false;
    };
  }
};

function switchRadio(rdo, pos, val, rdoStr, parStr, listStr, rdoType) {
  // rdo     : Identifiant radio
  // pos     : Position radio racine
  // val     : Valeur radio racine
  // rdoStr  : Name Input Radio
  // parStr  : Name Hidden Parent
  // listStr : Name List ID
  // rdoType : Type du message Alert
  var myForm = document.forms[1], leRdo, laList, lePar, leTemp, leStr = "", i = 0, leCompteur = 0;
  leRdo = eval("myForm." + rdoStr + rdo);
  if (leRdo[pos].checked == true) {
    lePar = eval("myForm." + parStr + rdo);
    laList = eval("myForm." + listStr);
    leStr = ""
    while (lePar) {
      leStr = leStr + "§" + lePar.value + "§";
      lePar = eval("myForm." + parStr + lePar.value);
    };
    for (i = 0; i < laList.length; i++) {
      if (laList[i].value == rdo) {
        leCompteur = i + 1;
        break;
      }
    };
    for (i = leCompteur; i < laList.length; i++) {
      lePar = eval("myForm." + parStr + laList[i].value);
      if (leStr.indexOf("§" + lePar.value + "§") != -1) {
        break;
      } else {
        leTemp = eval("myForm." + rdoStr + laList[i].value);
        leTemp[pos].checked = true;
      }
    };
  } else {
    lePar = eval("myForm." + parStr + rdo);
    leTemp = eval("myForm." + rdoStr + lePar.value);
    if (leTemp) {
      if (leTemp[pos].checked == true) {
        leRdo[pos].checked = true;

        // GESTION ALERTE //
        if (rdoType == "Grp") {
          alert("Vous ne pouvez modifier les droits d\'un groupe si l'un de ses pères est interdit");
        } else {
          alert("Vous ne pouvez modifier les droits d\'une catégorie si l'une de ses pères est interdite");
        }

      }
    }
  }
};

function getOrder(prt, ord) {
  // prt : Select contenant le Parent
  // ord : Select de destination
  var myForm = this.document.forms[1], leParent, leOrder, leTemp, i = 0, leCompteur, uneOption;
  leParent = eval("myForm." + prt);
  leOrder = eval("myForm." + ord);
  leCompteur = leOrder.length
  for (i = 1; i < leCompteur; i++) {
    leOrder.options[1] = null;
  };
  leTemp = eval("myForm.h_" + leParent.options[leParent.selectedIndex].value);
  if (leTemp) {
    if (leTemp.length > 1) {
      leCompteur = leOrder.length;
      for (i = 0; i < leTemp.length; i++) {
        uneOption = new Option('Après ' + leTemp[i].value, leCompteur, false, false);
        leOrder.options[leOrder.length] = uneOption;
        leCompteur++;
      };
    } else {
      uneOption = new Option('Après ' + leTemp.value, leOrder.length, false, false);
      leOrder.options[leOrder.length] = uneOption;
    }
  }
};

function swapAPI(slt, fld) {
  // slt : Select API
  // fld : Field de destination
  var myForm = this.document.forms[1], leSelect, leField, leTemp;
  leSelect = eval("myForm." + slt);
  leField = eval("myForm." + fld);
  if (leSelect.options[leSelect.selectedIndex].value == -1) {
    leField.value = "";
  } else {
    leTemp = eval("myForm.h_" + leSelect.options[leSelect.selectedIndex].value);
    leField.value = leTemp.value;
  }
};

function FUCase(monItem) {
  // Passage de la premiere lettre en majuscule
  leText = "" + monItem.value;
  if (leText.value + "" != "") {
    monItem.value = (leText.substring(0,1)).toUpperCase() + leText.substring(1,leText.length);
  }
};

function javCheckEdit(user) {
 if (document.ADM_USER_EDIT.LOGIN.value.length==0) {
  alert('Login obligatoire.');
 document.ADM_USER_EDIT.LOGIN.focus();
return false;
}
 if (user=="0") {
 if (document.ADM_USER_EDIT.PASSW.value.length<8) {
  alert('Le mot de passe doit contenir huit caractères au minimum.');
 document.ADM_USER_EDIT.PASSW.focus();
return false;
}
 if (document.ADM_USER_EDIT.PASSW.value!=document.ADM_USER_EDIT.PASSW1.value) {
  alert('Les mots de passe sont différents.');
 document.ADM_USER_EDIT.PASSW1.value="";
 document.ADM_USER_EDIT.PASSW1.focus();
return false;
}
}
 else {
 if (document.ADM_USER_EDIT.PASSW.value.length!=0) {
 if (document.ADM_USER_EDIT.PASSW.value.length<8) {
  alert('Le mot de passe doit contenir huit caractères au minimum.');
 document.ADM_USER_EDIT.PASSW.focus();
return false;
}
 if (document.ADM_USER_EDIT.PASSW.value!=document.ADM_USER_EDIT.PASSW1.value) {
  alert('Les mots de passe sont différents.');
 document.ADM_USER_EDIT.PASSW1.value="";
 document.ADM_USER_EDIT.PASSW1.focus();
return false;
}
}
}
 if (document.ADM_USER_EDIT.FIRST.value.length==0) {
  alert('Prénom obligatoire.');
 document.ADM_USER_EDIT.FIRST.focus();
return false;
}
 if (document.ADM_USER_EDIT.LAST.value.length==0) {
  alert('Nom obligatoire.');
 document.ADM_USER_EDIT.LAST.focus();
return false;
}
 if (document.ADM_USER_EDIT.DISPNAME.value.length==0) {
  alert('Champs obligatoire.');
 document.ADM_USER_EDIT.DISPNAME.focus();
return false;
}
 if (document.ADM_USER_EDIT.EMAIL.value.length==0) {
  alert('Adresse email obligatoire.');
 document.ADM_USER_EDIT.EMAIL.focus();
return false;
}
if (!checkEmail(document.ADM_USER_EDIT.EMAIL))
return false;
document.ADM_USER_EDIT.submit();
}
