// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
	var date2 = document.getElementById('val_dates2');
	var date1 = document.getElementById('val_dates');
	
	if (date2.value == "") {
		date2.value = date1.value;
	}
	
	day = date1.value.substring(0,2);
	month = date1.value.substring(2,5);
	year = date1.value.substring(6,10);
	day2 = date2.value.substring(0,2);
	month2 = date2.value.substring(3,5);
	year2 = date2.value.substring(6,10);
	
	/*date2.value = day2+"/"+month2+"/"+year2;
	date1.value = day+"/"+month+"/"+year;*/
	
	d1 = new Date();
	d2 = new Date();
	d1.setFullYear(year); 
	d1.setMonth(month-1);
	d1.setDate(day);
	d2.setFullYear(year2); 
	d2.setMonth(month2-1);
	d2.setDate(day2);
	
	if (d1.getTime()-d2.getTime() > 0) {
		alert ("La date de fin doit être supérieure à la date de début");
		date2.value = date1.value;
	}
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(2005, 3000);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}


function verifFormatDate(date) {
	//alert("check");
	if (date.value != "") {
		day = date.value.substr(0,2);
		if (day.charAt(1) == "/") {
			day = "0"+day.substr(0, 1);
		}
		if (date.value.charAt(1) == "/") {
			month = date.value.substr(2,2);
		} else {
			month = date.value.substr(3,2);
		}
		if (month.charAt(1) == "/") {
			month = "0"+month.substr(0, 1);
		}
		year = date.value.substr((date.value.length-4),4);
		
		date.value = day+"/"+month+"/"+year;
	}
}

//Check si la date valSup est plus grande que la date valInf
////////////////
function checkDate(valSup, valInf) {
	
	var date2 = document.getElementById(valSup).value;
	var date1 = document.getElementById(valInf).value;
	
	var dateOk = true;
	//alert(valSup+"nvhlrenjgpioejgsd"+valInf);
	
	var jour2 = parseInt(date2.substr(0, 2));
	var mois2 = parseInt(date2.substr(3, 2));
	var annee2 = parseInt(date2.substr(6, 4));
	
	var jour1 = parseInt(date1.substr(0, 2));
	var mois1 = parseInt(date1.substr(3, 2));
	var annee1 = parseInt(date1.substr(6, 4));
	
	if (annee2 < annee1) {
		dateOk = false;
		//alert("annee inférieure");
	} else {
		//alert("annee superieure ou egale");
		if (mois2 < mois1) {
			//alert("mois inférieur");
			dateOk = false;
		}else {
			//alert("mois superieur ou egal");
			if (jour2 < jour1) {
				//alert("jour inferieur");
				dateOk = false;
			} else {
				//alert(jour2 + " :: " + jour1);
				//alert("jour superieur ou egal");
				dateOk = true;
			}
		}
	}
	//alert(dateOk);
	return dateOk;	
}

function enableBouton(param, btn) {
	leBtn = document.getElementById(btn);
	if (param.value == "") {
		leBtn.disabled = true;
	} else {
		leBtn.disabled = false;
	}
}

function enableBouton2(param, param2, btn) {
	leBtn = document.getElementById(btn);
	
	leParam2 = document.getElementById(param2);
	
	if (param.value == "") {
		if (leParam2.value == "") {
			//alert("les deux sont null");
			leBtn.disabled = true;
		} else {
			//alert("le champ renseigné est null");
			leBtn.disabled = true;
		}
	} else {
		if (leParam2.value != "") {
			//alert("les deux sont est bon");
			leBtn.disabled = false;
		} else {
			//alert("le champ renseigné est bon mais pas le 2eme");
			leBtn.disabled = true;
		}
	}
}

function enableBtnDate(val2, val1, btn) {
	var leBtn = document.getElementById(btn);
	var champ1 = document.getElementById(val1).value;
	
	/*var slash = 0;
	var longRequete = champ1.length;
	
	for(var i=0; i<longRequete; i++) {
		if (champ1.charAt(i) == '/') {
			//alert("j'ai trouvé un /");
			slash++;
		}
	}*/
	
	if (champ1 != "") {
		/*if (slash == 2) {
			if (checkDate(val2, val1)) {
				leBtn.disabled = false;
			} else {
				leBtn.disabled = true;
			}
		} else {
			leBtn.disabled = true;
		}*/
		leBtn.disabled = false;
	} else {
		leBtn.disabled = true;
	}
	document.getElementById('cache_date').value = document.getElementById('val_dates').value;
}

function afficheSemaine(debut, cible) {
	var champ2 = document.getElementById(cible);
	var dateDebut = document.getElementById(debut).value;
	
	var jour = parseInt(dateDebut.substr(0, 2));
	var mois = parseInt(dateDebut.substr(3, 2));
	var annee = parseInt(dateDebut.substr(6, 4));
	
	var dateFin = new Date(annee, mois-1, jour+6);
	
	if (dateFin.getDay() > 0 ) {
		var decalage = 7 - dateFin.getDay();
		dateFin.setDate(decalage);
	}
	
	var jourAffiche = dateFin.getDate();
	if (jourAffiche < 10) {
		jourAffiche = "0"+jourAffiche;
	}
	var moisAffiche = dateFin.getMonth()+1;
	if (moisAffiche < 10) {
		moisAffiche = "0"+moisAffiche;
	}
	var anneeAffiche = dateFin.getFullYear();
	
	champ2.value = jourAffiche+"/"+moisAffiche+"/"+anneeAffiche;
	document.getElementById('cache_date2').value = champ2.value;
}



function enleveDomaine(dom) {
	//alert("j'enleve ce domaine : "+dom);
	
	document.getElementById('row'+dom).style.display = "none";
	document.getElementById('dom'+dom).value = "";
	
}

function ajouteDomaine(el, leSelect) {
	var contenu = document.getElementById(el).innerHTML;
	//on met tout en minuscule car IE et FF n'interprete pas de la meme maniere le innerHTML
	// sur IE -> TD, sur FF -> td
	contenu = contenu.toLowerCase();
	
	//nombre de cellules (de domaines) deja présent
	var nbCell = (contenu.split("</td").length)/2;
	//alert ("j'ajoute un "+nbCell+"eme domaine");
	
	var libDom = eval(leSelect+".options["+leSelect+".selectedIndex].text");
	var idDom = eval(leSelect+".value");
	
	document.getElementById('totalCell').value = nbCell;
		
	//var newCell = "<tr id='row"+nbCell+"'><td>"+libDom+"<input type='hidden' id='dom"+nbCell+"' name='dom"+nbCell+"' value='"+idDom+"' /></td><td><a href='javascript:enleveDomaine("+nbCell+")'><img src='images/suppr.gif' alt='Supprimer un domaine' /></a></td></tr>";
	//alert (newCell);
	//contenu += newCell;
	//document.getElementById(el).innerHTML = contenu;
	
	//TR
	var trNode = document.createElement("tr");
	trNode.id = 'row'+nbCell;
	//TD
	var tdNode = document.createElement("td");
	tdNode.appendChild(document.createTextNode(libDom));
	//INPUT DU TD
	var inputNode = document.createElement("input");
	inputNode.type = "hidden";
	inputNode.name = "dom" + nbCell;
	inputNode.id = "dom" + nbCell;
	inputNode.value = idDom;
	//TD 2
	var tdNode2 = document.createElement("td");
	//LIEN DU TD 2
	var lien = document.createElement('a');
	lien.setAttribute('href', 'javascript:enleveDomaine('+nbCell+')');
	var imgLien = document.createElement('img');
	imgLien.src = "images/suppr.gif";
	imgLien.alt = "Supprimer un domaine";
	lien.appendChild(imgLien);
		
	//ON AJOUTE
	tdNode.appendChild(inputNode);
	tdNode2.appendChild(lien);
	
	trNode.appendChild(tdNode);
	trNode.appendChild(tdNode2);
	document.getElementById(el).appendChild(trNode);
}

function enleveExpert(expert) {
	//alert("j'enleve cet expert : "+dom);
	
	document.getElementById('row'+expert).style.display = "none";
	document.getElementById('exp'+expert).value = "";
	
}

function ajouteExpert(el, leSelect) {
	var contenu = document.getElementById(el).innerHTML;
	//on met tout en minuscule car IE et FF n'interprete pas de la meme maniere le innerHTML
	// sur IE -> TD, sur FF -> td
	contenu = contenu.toLowerCase();
	
	//nombre de cellules (d'experts) deja présent
	var nbCell = (contenu.split("</td").length)/2;
	//alert ("j'ajoute un "+nbCell+"eme expert");
	
	var libExp = eval(leSelect+".options["+leSelect+".selectedIndex].text");
	var idExp = eval(leSelect+".value");
	
	document.getElementById('totalCell').value = nbCell;
		
	//Chaine permettant l'ajout de cellules !!!InnerHTML ne fonctionne pas avec <table> sous IE !!!
	//var newCell = "<tr id='row"+nbCell+"'><td>"+libExp+"<input type='hidden' id='exp"+nbCell+"' name='exp"+nbCell+"' value='"+idExp+"' /></td><td><a href='javascript:enleveExpert("+nbCell+")'><img src='images/suppr.gif' alt='Supprimer un expert' /></a></td></tr>";
	//alert (newCell);
	/*!!!InnerHTML ne fonctionne pas avec <table> sous IE !!!
	contenu += newCell;
	document.getElementById(el).innerHTML = contenu;*/
	
	//TR
	var trNode = document.createElement("tr");
	trNode.id = 'row'+nbCell;
	//TD
	var tdNode = document.createElement("td");
	tdNode.appendChild(document.createTextNode(libExp));
	//INPUT DU TD
	var inputNode = document.createElement("input");
	inputNode.type = "hidden";
	inputNode.name = "exp" + nbCell;
	inputNode.id = "exp" + nbCell;
	inputNode.value = idExp;
	//TD 2
	var tdNode2 = document.createElement("td");
	//LIEN DU TD 2
	var lien = document.createElement('a');
	lien.setAttribute('href', 'javascript:enleveExpert('+nbCell+')');
	var imgLien = document.createElement('img');
	imgLien.src = "images/suppr.gif";
	imgLien.alt = "Supprimer un expert";
	lien.appendChild(imgLien);
		
	//ON AJOUTE
	tdNode.appendChild(inputNode);
	tdNode2.appendChild(lien);
	
	trNode.appendChild(tdNode);
	trNode.appendChild(tdNode2);
	document.getElementById(el).appendChild(trNode);
}


function afficheSelect(id) {
	var bloc = document.getElementById(id);
	//alert("affiche mon select");
	if (bloc.style.display == "none") {
		bloc.style.display = "";
	} else {
		bloc.style.display = "none";
	}
}


function confirmSuppression(laPage) {
	var result = confirm("Etes-vous sûr de vouloir définitivement supprimer ?");
	if(result == true){
		window.location.href = laPage;
	} else {
		//alert("Suppression annulée...");
	}
}

function confirmDuplique(laPage) {
	var result = confirm("Avez-vous effectué toutes les modifications nécessaires ?");
	if(result == true){
		window.location.href = laPage;
	} else {
		//alert("Duplication annulée...");
	}
}

function jumpPage(laPage, numPage) {
	window.location.href = laPage + "-page-" + numPage + ".html";
}

function afficheNbResult(laPage, nbRes) {
	window.location.href = laPage + "-par-" + nbRes + ".html";
}

//fonction permettant d'afficher une date selon le format suivant : Lundi 26 février 2007 (entrée aaaa-mm-jj)
function affDateComplete(date) {
	var jour = date.substring(8, 10);
	var mois = date.substring(5, 7);
	var annee = date.substring(0, 4);

	var laDate = new Date(annee, mois-1, jour);
	
	var numJourSem = laDate.getDay();
	
	//alert(date+ " " + jour + " " + laDate + " " + numJourSem);
	
	switch (numJourSem) {
		case 0:
			var jourSemaine = "Di";
			break;
		case 1:
			var jourSemaine = "Lu";
			break;
		case 2:
			var jourSemaine = "Ma";
			break;
		case 3:
			var jourSemaine = "Me";
			break;
		case 4:
			var jourSemaine = "Je";
			break;
		case 5:
			var jourSemaine = "Ve";
			break;
		case 6:
			var jourSemaine = "Sa";
			break;
		
	}
	
	switch(mois) {
		case "01":
			var dateStr = jourSemaine+" "+jour+" janvier "+annee
			break;
		case "02":
			var dateStr = jourSemaine+" "+jour+" février "+annee
			break;
		case "03":
			var dateStr = jourSemaine+" "+jour+" mars "+annee
			break;
		case "04":
			var dateStr = jourSemaine+" "+jour+" avril "+annee
			break;
		case "05":
			var dateStr = jourSemaine+" "+jour+" mai "+annee
			break;
		case "06":
			var dateStr = jourSemaine+" "+jour+" juin "+annee
			break;
		case "07":
			var dateStr = jourSemaine+" "+jour+" juillet "+annee
			break;
		case "08":
			var dateStr = jourSemaine+" "+jour+" août "+annee
			break;
		case "09":
			var dateStr = jourSemaine+" "+jour+" septembre "+annee
			break;
		case "10":
			var dateStr = jourSemaine+" "+jour+" octobre "+annee
			break;
		case "11":
			var dateStr = jourSemaine+" "+jour+" novembre "+annee
			break;
		case "12":
			var dateStr = jourSemaine+" "+jour+" décembre "+annee
			break;
	}
	
	document.write(dateStr);
}

function clearChamp(champ, init) {
	if (champ.value == init) {
		champ.value = "";
	}
}
function defaultChamp(champ, val) {
	champ.value = val;
}

function displayFlashNonIE(swf, largeur, hauteur)
{
	//alert('pas IE');
	document.write('<object type="application/x-shockwave-flash" data="'+swf+'" width="'+largeur+'" height="'+hauteur+'">');
	//document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+swf+'" />');
	document.write('<img src="images/plugin_flash.gif" alt="Nécessite le plugin Flash" width="241" height="193" />');
	document.write('</object>');
}

function displayFlashIE(swf, largeur, hauteur)
{
	document.write('<object type="application/x-shockwave-flash" data="'+swf+'" width="'+largeur+'" height="'+hauteur+'" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">');
	//document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+swf+'" />');
	document.write('<img src="images/plugin_flash.gif" alt="Nécessite le plugin Flash" width="241" height="193" />');
	document.write('</object>');
}


function reinitImport() {
	document.getElementById('img_import').innerHTML = "Choisissez une image correspondant à cet événement<br /><br /><a href=\"javascript:window.open('import_image.htm', 'importationImage', 'width=980, height=570, resizable=no, status=yes, scrollbars=no, menubar=yes'); void(0)\"><img src='images/btn_retoucher_importer.gif' alt='Importer une image' /></a><br /><br /><strong>OU</strong><br /><br />Importation classique<input type=\"file\" name=\"import_fichier\" /><br /><br /><a href='http://images.google.fr/imghp?hl=fr&ie=UTF-8&oe=UTF-8&tab=wi&q=' id='lien_google' target='_blank'><img src='images/rech_google.gif' /></a>";
	document.getElementById('img_import').className = "image_fiche_import";
	document.getElementById('id_provisoire').value = "";
	document.getElementById('petit_img_import').innerHTML = "<img src='img_evts/petit_evt_gen.gif' alt=\"Pas d'image\" />";
}

function valideEvt(titre) {
	btnOk = false;
	if (document.getElementById(titre).value != "") {
		if (document.getElementById("domaine").value != "") {
			if (document.getElementById("type").value != "") {
				if (document.getElementById("pays").value != "") {
					if (document.getElementById("periodicite").value != "") {
						if (document.getElementById("statut").value != "") {
							if (document.getElementById("val_dates").value != "") {
								if (document.getElementById("val_dates2").value != "") {
									btnOk = true
								} else {
									//alert('date2');
									btnOk = false;
								}
							} else {
								//alert('date');
								btnOk = false;
							}
						} else {
							//alert('statut');
							btnOk = false;
						}
					} else {
						//alert('per');
						btnOk = false;
					}
				} else {
					//alert('pays');
					btnOk = false;
				}
			} else {
				//alert('type');
				btnOk = false;
			}
		} else {
			//alert('domaine');
			btnOk = false;
		}
	} else {
		//alert('titre');
		btnOk = false;
	}
	
	if (btnOk == false) {
		alert("Veuillez renseigner tous les champs marqués par une étoile");
		return false;
	} else {
		return true;
	}
}

function mailValide(email) {
	//var longMail = email.length();
	if (email != "")	{
		var Pat = /^[a-z][a-z0-9_\.-]+@[a-z0-9_\.\-]+\.[a-z]{2,4}$/i
		
		/*Autres expressions régulières
		/^[^@]+@(([w-]+.){1,4}[a-zA-Z]{2,4}|(([01]?d?d|2[0-4]d|25[0-5]).){3}([01]?d?d|2[0-4]d|25[0-5]))$/
		new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$");
		*/
		
		if (Pat.exec(email) == null) {
			//alert("c pas bon");
			return false;
		} else {
			//alert ("c good");
			return true;
		}
	} else {
		//alert("mail vide");
		return false;
	}
}

function valideProp() {
	btnOk = false;
	mailOk = true;
	if (document.getElementById("titre").value != "") {
		if (document.getElementById("domaine").value != "") {
			if (document.getElementById("type").value != "") {
				if (document.getElementById("pays").value != "") {
					if (document.getElementById("val_dates").value != "") {
						if (document.getElementById("val_dates2").value != "") {
							if (mailValide(document.getElementById("mail_invite").value)) {
								btnOk = true;
							} else {
								//alert('mail');
								btnOk = false;
								mailOk = false;
								message = "Veuillez entrer un mail valide";
							}
						} else {
							//alert('date2');
							btnOk = false;
						}
					} else {
						//alert('date');
						btnOk = false;
					}
				} else {
					//alert('pays');
					btnOk = false;
				}
			} else {
				//alert('type');
				btnOk = false;
			}
		} else {
			//alert('domaine');
			btnOk = false;
		}
	} else {
		//alert('titre');
		btnOk = false;
	}
	
	if (btnOk == false) {
		if (mailOk) {
			alert("Veuillez renseigner tous les champs marqués par une étoile");
		} else {
			alert(message);
		}
		return false;
	} else {
		return true;
	}
}

function valideRechExpert() {
	btnOk = false;
	if ((document.getElementById("rech_txt").value == "" || document.getElementById("rech_txt").value == "Mot-clé - nom - prénom") && document.getElementById("domaine_rech").value == "") {
		btnOk = false;
	} else {
		btnOk = true;
	}
	
	if (btnOk == false) {
		alert("Veuillez saisir au moins un des champs ci-dessus");
		return false;
	} else {
		return true;
	}
	
}

function valideUser(nom) {
	btnOk = false;
	mdpOk = true;
	if (document.getElementById(nom).value != "") {
		if (document.getElementById("login").value != "") {
			if (document.getElementById("prenom").value != "") {
				if (document.getElementById("mail").value != "") {
					if (document.getElementById("mdp").value == document.getElementById("mdp2").value && document.getElementById("mdp").value != "") {
						btnOk = true;
					} else {
						mdpOk = false;
						message = "Veuillez confirmer correctement le mot de passe."
						btnOk = false;
					}
				} else {
					btnOk = false;
				}
			} else {
				btnOk = false;
			}
		} else {
			btnOk = false;
		}
	} else {
		btnOk = false;
	}
	
	if (btnOk == false) {
		return false;
		if (mdpOk) {
			alert("Veuillez renseigner tous les champs marqués par une étoile");
		} else {
			alert(message);
		}
	} else {
		return true;
	}
}

function valideRechSimple() {
	btnOk = false;
	
	if (document.getElementById("rech_text").value == "") {
		btnOk = false;
	} else {
		btnOk = true;
	}
	
	if (btnOk == false) {
		alert("Veuillez saisir le champ de recherche correspondant");
		return false;
	} else {
		return true;
	}
}

function valideRechAvancee() {
	btnOk = false;
	
	if (document.getElementById("titre").value == "" && document.getElementById("type").value == "" && document.getElementById("domaine").value == "" && document.getElementById("pays").value == "" && document.getElementById("lieu").value == "" && document.getElementById("expert").value == "" && document.getElementById("val_dates").value == "" && document.getElementById("val_dates2").value == "") {
		btnOk = false;
	} else {
		btnOk = true;
	}
	
	if (btnOk == false) {
		alert("Veuillez saisir au moins un des paramètres ci-dessus");
		return false;
	} else {
		return true;
	}
}

function valideRechAvanceeAdmin() {
	btnOk = false;
	
	if (document.getElementById("titre").value == "" && document.getElementById("type").value == "" && document.getElementById("domaine").value == "" && document.getElementById("pays").value == "" && document.getElementById("lieu").value == "" && document.getElementById("expert").value == "" && document.getElementById("val_dates").value == "" && document.getElementById("val_dates2").value == "" && document.getElementById("statut").value == "" && document.getElementById("el").checked == false && document.getElementById("vip").checked == false && document.getElementById("periodicite").value == "" && document.getElementById("source").value == "" && document.getElementById("saisi").value == "" && document.getElementById("publie").value == "" && document.getElementById("rq").value == "") {
		btnOk = false;
	} else {
		btnOk = true;
	}
	
	if (btnOk == false) {
		alert("Veuillez saisir au moins un des paramètres ci-dessus");
		return false;
	} else {
		return true;
	}
}

function changeNbResultat(nbRes) {
	document.location.replace("changeNbResultat.php5?nb="+nbRes+"&red="+window.location.href);
}

function cocheDroit(cible, module) {
	
	var cocheTout = document.getElementById("tous"+module);
	var cocheAucun = document.getElementById("aucun"+module);
	
	var cocheLec = document.getElementById("lec"+module);
	var cocheMod = document.getElementById("mod"+module);
	var cocheEcr = document.getElementById("ecr"+module);
	var cocheSuppr = document.getElementById("suppr"+module);
	
	var champCacheNiv = document.getElementById("module"+module);
	
	//alert (cible.name);
	
	switch(cible.name) {
		case "tous"+module :
			if (cible.checked == true) {
				cocheLec.checked = true;
				cocheMod.checked = true;
				cocheEcr.checked = true;
				cocheSuppr.checked = true;
				cocheAucun.checked = false;
				champCacheNiv.value = "15";
			} else {
				cocheLec.checked = true;
				cocheMod.checked = true;
				cocheEcr.checked = true;
				cocheSuppr.checked = false;
				cocheAucun.checked = false;
				champCacheNiv.value = "10";
			}
			break;
		case "lec"+module :
			if (cible.checked == true) {
				cocheAucun.checked = false;
				if (cocheMod.checked == true && cocheEcr.checked == true && cocheSuppr.checked == true) {
					cocheTout.checked = true;
					champCacheNiv.value = "15";
				} else {
					cocheTout.checked = false;
					champCacheNiv.value = "8";
				}
			} else {
				cocheTout.checked = false;
				cocheMod.checked = false;
				cocheEcr.checked = false;
				cocheSuppr.checked = false;
				cocheAucun.checked = true;
				champCacheNiv.value = "0";
			}
			break;
		case "mod"+module :
			if (cible.checked == true) {
				cocheLec.checked = true;
				cocheAucun.checked = false;
				if (cocheLec.checked == true && cocheEcr.checked == true && cocheSuppr.checked == true) {
					cocheTout.checked = true;
					champCacheNiv.value = "15";
				} else {
					cocheTout.checked = false;
					champCacheNiv.value = "10";
				}
			} else {
				cocheTout.checked = false;
				cocheEcr.checked = false;
				cocheSuppr.checked = false;
				if (cocheLec.checked == false && cocheEcr.checked == false) {
					cocheAucun.checked = true;
					champCacheNiv.value = "0";
				} else {
					cocheAucun.checked = false;
					champCacheNiv.value = "8";
				}
			}
			break;
		case "ecr"+module :
			if (cible.checked == true) {
				cocheAucun.checked = false;
				cocheMod.checked = true;
				cocheLec.checked = true;
				cocheSuppr.checked = false;
				cocheTout.checked = false;
				champCacheNiv.value = "14";
			} else {
				cocheTout.checked = false;
				cocheSuppr.checked = false;
				if (cocheMod.checked == false && cocheLec.checked == false) {
					cocheAucun.checked = true;
					champCacheNiv.value = "0";
				} else {
					cocheAucun.checked = false;
					champCacheNiv.value = "10";
				}
			}
			break;
		case "suppr"+module :
			if (cible.checked == true) {
				cocheAucun.checked = false;
				cocheMod.checked = true;
				cocheLec.checked = true;
				cocheEcr.checked = true;
				cocheTout.checked = true;
				champCacheNiv.value = "15";
			} else {
				cocheTout.checked = false;
				if (cocheMod.checked == false && cocheLec.checked == false && cocheEcr.checked == false) {
					cocheAucun.checked = true;
					champCacheNiv.value = "0";
				} else {
					cocheAucun.checked = false;
					champCacheNiv.value = "14";
				}
			}
			break;
		case "aucun"+module :
			if (cible.checked == true) {
				cocheLec.checked = false;
				cocheMod.checked = false;
				cocheEcr.checked = false;
				cocheSuppr.checked = false;
				cocheTout.checked = false;
				champCacheNiv.value = "0";
			} else {
				cocheLec.checked = true;
				cocheMod.checked = false;
				cocheEcr.checked = false;
				cocheSuppr.checked = false;
				cocheTout.checked = false;
				champCacheNiv.value = "8";
			}
			break;
	}
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function changeLienGoogle(titre) {
	champ = titre.value;
	var reg = new RegExp("(\")", "g");
	var reg2 = new RegExp("(')", "g");
	//Si le lien google est présent -> evite une erreur javascript getElementById("...") = null
	if (document.getElementById("lien_google") != null) {
		param = "";
		if (champ.charAt(champ.length-1) != " ") {
			tab_champ = champ.split(" ");
			//alert("test");
			for(var i=0; i<tab_champ.length; i++) {
				if (tab_champ[i].charAt(0) == "'" && tab_champ[i].charAt(0) == "'") {
					tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
				}
				if (tab_champ[i].charAt(0) == '"' && tab_champ[i].charAt(0) == '"') {
					tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
				}
				for (var j=0; j<tab_champ[i].length-1; j++) {
					if (tab_champ[i].charAt(j) == "'" || tab_champ[i].charAt(j) == '"') {
						if (j < (tab_champ[i].length-1)) {
							tab_champ[i] = tab_champ[i].substring((j+1), (tab_champ[i].length));
						} else {
							tab_champ[i] = tab_champ[i].substring(0, j);
						}
					}
				}
				if (tab_champ[i].length > 2) {
					//alert(i);
					if (param != "") {
						param += "+";
					}
					param += tab_champ[i];
				}
			}
			document.getElementById("lien_google").href = "http://images.google.fr/images?hl=fr&q="+param+"&gbv=2";
		}
	}
}


function changeLienWiki(titre) {
	champ = titre.value;
	//Si le lien wiki est présent -> evite une erreur javascript getElementById("...") = null
	if (document.getElementById("lien_wiki") != null) {
		param = "";
		if (champ.charAt(champ.length-1) != " ") {
			tab_champ = champ.split(" ");
			//alert("test");
			for(var i=0; i<tab_champ.length; i++) {
				if (tab_champ[i].charAt(0) == "'" && tab_champ[i].charAt(0) == "'") {
					tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
				}
				if (tab_champ[i].charAt(0) == '"' && tab_champ[i].charAt(0) == '"') {
					tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
				}
				for (var j=0; j<tab_champ[i].length; j++) {
					if (tab_champ[i].charAt(j) == "'" || tab_champ[i].charAt(j) == '"') {
						if (j < (tab_champ[i].length-1)) {
							tab_champ[i] = tab_champ[i].substring((j+1), (tab_champ[i].length));
						} else {
							tab_champ[i] = tab_champ[i].substring(0, j);
						}
					}
				}
				if (tab_champ[i].length > 2) {
					//alert(i);
					if (param != "") {
						param += "+";
					}
					param += tab_champ[i];
				}
			}
			document.getElementById("lien_wiki").href = "http://fr.wikipedia.org/wiki/Special:Search?search="+param;
		}
	}
}

function changeImage(titre) {
	champ = titre.value;
	var reg = new RegExp("(\")", "g");
	var reg2 = new RegExp("(')", "g");
	param = "";
	if (champ.charAt(champ.length-1) != " ") {
		tab_champ = champ.split(" ");
		//alert("test");
		for(var i=0; i<tab_champ.length; i++) {
			if (tab_champ[i].charAt(0) == "'" && tab_champ[i].charAt(0) == "'") {
				tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
			}
			if (tab_champ[i].charAt(0) == '"' && tab_champ[i].charAt(0) == '"') {
				tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
			}
			for (var j=0; j<tab_champ[i].length; j++) {
				if (tab_champ[i].charAt(j) == "'" || tab_champ[i].charAt(j) == '"') {
					if (j < (tab_champ[i].length-1)) {
						tab_champ[i] = tab_champ[i].substring((j+1), (tab_champ[i].length));
					} else {
						tab_champ[i] = tab_champ[i].substring(0, j);
					}
				}
			}
			if (tab_champ[i].length > 2) {
				//alert(i);
				if (param != "") {
					param += "+";
				}
				param += tab_champ[i];
			}
		}
	}
	
	document.getElementById('img_import').innerHTML = "Choisissez une image correspondant à cet événement<br /><br /><a href=\"javascript:window.open('import_image.htm', 'importationImage', 'width=980, height=570, resizable=no, status=yes, scrollbars=no, menubar=yes'); void(0)\"><img src='images/btn_retoucher_importer.gif' alt='Importer une image' /></a><br /><br /><strong>OU</strong><br /><br />Importation classique<input type=\"file\" name=\"import_fichier\" /><br /><br /><a href='http://images.google.fr/images?hl=fr&q="+param+"&gbv=2' id='lien_google' target='_blank'><img src='images/rech_google.gif' /></a>";
	document.getElementById('img_import').className = "image_fiche_import";
	document.getElementById('id_provisoire').value = "";
	document.getElementById('petit_img_import').innerHTML = "<img src='img_evts/petit_evt_gen.gif' alt=\"Pas d'image\" />";
}

function changeImageAdmin(titre) {
	champ = titre.value;
	var reg = new RegExp("(\")", "g");
	var reg2 = new RegExp("(')", "g");
	param = "";
	if (champ.charAt(champ.length-1) != " ") {
		tab_champ = champ.split(" ");
		//alert("test");
		for(var i=0; i<tab_champ.length; i++) {
			if (tab_champ[i].charAt(0) == "'" && tab_champ[i].charAt(0) == "'") {
				tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
			}
			if (tab_champ[i].charAt(0) == '"' && tab_champ[i].charAt(0) == '"') {
				tab_champ[i] = tab_champ[i].substring(1, tab_champ[i].length-1);
			}
			for (var j=0; j<tab_champ[i].length; j++) {
				if (tab_champ[i].charAt(j) == "'" || tab_champ[i].charAt(j) == '"') {
					if (j < (tab_champ[i].length-1)) {
						tab_champ[i] = tab_champ[i].substring((j+1), (tab_champ[i].length));
					} else {
						tab_champ[i] = tab_champ[i].substring(0, j);
					}
				}
			}
			if (tab_champ[i].length > 2) {
				//alert(i);
				if (param != "") {
					param += "+";
				}
				param += tab_champ[i];
			}
		}
	}
	
	document.getElementById('img_import').innerHTML = "Choisissez une image correspondant à cet événement<br /><br /><a href=\"javascript:window.open('import_image.htm', 'importationImage', 'width=980, height=570, resizable=no, status=yes, scrollbars=no, menubar=yes'); void(0)\"><img src='images/btn_recadrer_admin.gif' alt='Importer une image' /></a><br /><br /><strong>OU</strong><br /><br />Importation classique<input type=\"file\" name=\"import_fichier\" /><br /><br /><a href='http://images.google.fr/images?hl=fr&q="+param+"&gbv=2' id='lien_google' target='_blank'><img src='images/rech_google_admin.gif' /></a>";
	document.getElementById('img_import').className = "image_fiche_import";
	document.getElementById('id_provisoire').value = "";
	document.getElementById('petit_img_import').innerHTML = "<img src='img_evts/petit_evt_gen.gif' alt=\"Pas d'image\" />";
}

function changeImageExpert() {
	document.getElementById('photo_expert').innerHTML = "<br /><br />Importation classique<input type=\"file\" name=\"import_fichier\" /><br /><br />";
	document.getElementById('photo_expert').className = "image_expert_import";
	document.getElementById('id_provisoire').value = "";
	document.getElementById('petit_img_import').innerHTML = "<img src='img_experts/petit_exp_gen.gif' alt=\"Pas d'image\" />";
}

function eviteTypeEvt(obj) {
	if (obj.checked == true) {
		document.getElementById("type").disabled = true;
		document.getElementById("type").selectedIndex = 0;
		//alert("1");
	} else {
		document.getElementById("type").disabled = false;
		//alert("2");
	}
}

function valideInscription() {
	btnOk = false;
	mdpOk = true;
	if (document.getElementById("nom").value != "") {
		if (document.getElementById("institution").value != "") {
			if (document.getElementById("prenom").value != "") {
				if (document.getElementById("mail").value != "") {
					if (document.getElementById("mdp").value == document.getElementById("mdp2").value && document.getElementById("mdp").value != "") {
						btnOk = true;
					} else {
						mdpOk = false;
						message = "Veuillez confirmer correctement le mot de passe."
						btnOk = false;
					}
				} else {
					btnOk = false;
				}
			} else {
				btnOk = false;
			}
		} else {
			btnOk = false;
		}
	} else {
		btnOk = false;
	}
	
	if (btnOk == false) {
		if (mdpOk) {
			alert("Veuillez renseigner tous les champs marqués par une étoile");
		} else {
			alert(message);
		}
		return false;
	} else {
		alert("OK");
		return true;
	}
}
