function msgPatientez(){
	alert("Veuillez patientez pendant l'upload des images, ceci peut prendre quelques minutes... Merci!");
}
function AddPhotoToList(liste, valToInsert){

	var len=liste.length;
	if(valToInsert.value!=""){
		//Avant d'insérer, on valide que le fichier n'est pas déjà là...
		for(i=0; i<len; i++){
			if(liste.options[i].value == valToInsert.value){
				alert("Cette photo "+valToInsert.value+" a déjà été ajoutée à la liste.");
				return;
			}
		}
		
		if(valToInsert.value.lastIndexOf(".jpg") == -1 && valToInsert.value.lastIndexOf(".jpeg") == -1 && 
		   valToInsert.value.lastIndexOf(".zip") == -1 && valToInsert.value.lastIndexOf(".JPG") == -1 && 
		   valToInsert.value.lastIndexOf(".JPEG") == -1 && valToInsert.value.lastIndexOf(".ZIP") == -1){
			alert("Vous ne pouvez choisir que des fichiers .jpg ou .jpeg ou .zip contenant ces 2 extensions");
			//alert("Vous ne pouvez choisir que des fichiers .jpg ou .jpeg.");
		}
		else{
			// On met dans la liste des photos principales seulement les fichiers .jpg
			if(valToInsert.value.lastIndexOf(".zip") == -1 && valToInsert.value.lastIndexOf(".ZIP") == -1){
				liste.options.add(new Option(valToInsert.value, valToInsert.value));   
				//liste.focus();
			}
		}		
	}
	else{
		//alert("Vous devez sélectionner un fichier...")
	}
}

function DeletePhotoFromList(liste, delListe, fileInput, maxPic, button){
	var indexDelListe = delListe.length;
	if(liste.length > 0){
		var selIndex = liste.selectedIndex;
		if (selIndex != -1) {
			for(i=liste.length-1; i>=0; i--){
				if(liste.options[i].selected){
					if(liste.options[i].value!=liste.options[i].text){
						delListe.options.add(new Option(liste.options[i].value, liste.options[i].value));
					}
					liste.options[i] = null;
				}
			}
			if (liste.length > 0) {
				liste.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
			}
			else{
				delListe.style.visibility = "hidden";
				liste.style.visibility = "hidden";
				button.style.visibility = "hidden";	
			}
			if (liste.length <= maxPic){
				fileInput.disabled = false;	
			}
		}   
		else{
			alert("Vous devez sélectionner un fichier dans la liste.");
		}           
	}
	else{
		alert("Il doit y avoir au moins un fichier dans la liste.");
	}
}

function DeletePhoto(box, delListe, liste, selected){
	if(box.checked == true){
		delListe.options.add(new Option(box.name, box.name ));
		
		for(i=liste.length-1; i>=0; i--){
			if(liste.options[i].value == box.name){
				liste.options[i] = null;
			}
		}
	}
	else{
		liste.options.add(new Option(box.value, box.name ));
		if(selected){
			liste.options[0].selected = true;
		}
		
		for(i=delListe.length-1; i>=0; i--){
			if(delListe.options[i].value == box.name){
				delListe.options[i] = null;
			}
		}		
	}
}

/*function enableList(liste1, liste2){
	if(liste1!=null){
		liste1.style.visibility  = "visible";
		alert(liste1.value);
	}
	if(liste2!=null){
		liste2.style.visibility = "visible";
	}
}*/

function selectMainPic(liste, photoPrincipaleHidden){
	if(liste.length > 0){
		if(liste.selectedIndex != -1){
			for(i=0;i<liste.length;i++){
				liste.options[i].style.color = "#000000";   
			}
			var selIndex = liste.selectedIndex;
			liste.options[selIndex].style.color = "#CC0000";
			photoPrincipaleHidden.value = liste.options[selIndex].value;
		}
		else{
			alert("Vous devez choisir au moins un fichier");
		}
	}
	else{
		alert("Il doit y avoir au moins un fichier dans la liste...");
	}
}

function selectAllPhotos(liste){
	if(liste != null){
		// On compte le nombre d'item de la liste select
		var nbCol = liste.length;	
		// On lance une boucle pour selectionner tous les items
		for(a=0; a<nbCol; a++){
			liste.options[a].selected = true;
		}
	}
}
  
function reloadForm(form){
	var val = form.trierNouvellePar.options[form.trierNouvellePar.options.selectedIndex].value;
	var formPost = form.formPost.value;
	var valide = form.valide.value;
	var archive = form.archive.value;
	var approuve = form.approuve.value;
	self.location = 'ModSupNouv.php?trierPar='+val+'&formPost='+formPost+'&valide='+valide+'&archive='+archive+'&approuve='+approuve;
}

function reloadFormPA(form){
	var val = form.trierAnnoncePar.options[form.trierAnnoncePar.options.selectedIndex].value;
	var formPost = form.formPost.value;
	var valide = form.valide.value;
	self.location = 'ModSupAnnonce.php?trierPar='+val+'&formPost='+formPost+'&valide='+valide;
	
}

function reloadFormPP(form){
	var val = form.listeDePubs.options[form.listeDePubs.options.selectedIndex].value;
	var formMethod = form.formPost.value;
	if(formMethod == null || formMethod == ""){
		formMethod=  form.formMethod.value;	
	}
	var valide = form.valide.value;
	self.location = 'ModSupPub.php?listePub='+val+'&formMethod='+formMethod+'&valide='+valide;
	
}

function reloadFormUser(form){
	var val = form.listeDesUsagers.options[form.listeDesUsagers.options.selectedIndex].value;
	var formMethod = form.formPost.value;
	if(formMethod == null || formMethod == ""){
		formMethod=  form.formMethod.value;	
	}
	var valide = form.valide.value;
	self.location = 'ModSupUsager.php?listeUsager='+val+'&formMethod='+formMethod+'&valide='+valide;
	
}

/*function valideFieldSelected(form){
	var val = form.listeDePubs.options[form.listeDePubs.options.selectedIndex].value;
	var formPost = form.formPost.value;
	
	alert(formPost);
	if(val == null || val == ""){
		alert("Vous devez sélectionner une publicitié à modifier.");	
		self.location = 'ModSupPub.php?formPost='+formPost+'&valide='+valide;
		return false;
	}
}*/