function init() {
	// on recupere chaque champ a verifier
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	var email = document.getElementById('email');
	
	// initialise l'appel aux fonctions pour chaque champ
	// il y a des différences de traitement DOM entre IE et Firefox, notamment pour l'affectation d'évenement
	// pour IE
	if (window.attachEvent) {
		username.onkeyup = function() { verifUsername(username); };
		password.onkeyup = function() { verifPassword(password); };
		email.onkeyup = function() { verifEmail(email); };
	}
	// pour Firefox
	else {
		username.setAttribute('onKeyUp', 'verifUsername(username)');
		password.setAttribute('onKeyUp', 'verifPassword(password)');
		email.setAttribute('onKeyUp', 'verifEmail(email)');
	}
}
 
function verifUsername(username) {
	var XHR = new XHRConnection();
	XHR.appendData("username", username.value);
	XHR.sendAndLoad("verifUsername.php", "POST", afficheDispo);
}
 
function verifPassword(password) {
	motDePasse = password.value;
	password_alert = document.getElementById('password_alert');
	// suppression du texte existant
	while(password_alert.firstChild != null) {
		password_alert.removeChild(password_alert.firstChild);
	}
	// creation du message suivant le cas
	if(motDePasse.length < 6) {
		var texte = document.createTextNode("Niveau faible");
	}
	if(motDePasse.length >= 6 && motDePasse.length < 8) {
		var texte = document.createTextNode("Niveau correct");
	}
	if(motDePasse.length >= 8) {
		var texte = document.createTextNode("Niveau élevé");
	}
	password_alert.appendChild(texte);
}
 
function verifEmail(email) {
	adresse = email.value;
	email_alert = document.getElementById('email_alert');
	// suppression du texte existant
	while(email_alert.firstChild != null) {
		email_alert.removeChild(email_alert.firstChild);
	}
	// creation du message suivant le cas
	if (!checkEmail(adresse)) {
		var texte = document.createTextNode("Adresse incorrecte");
		email_alert.appendChild(texte);
	} else {
		var texte = document.createTextNode("Adresse correcte");
		email_alert.appendChild(texte);
	}
}
 
function checkEmail(email) {
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	if((arobase < 3) || (point + 3 > email.length) || (point < arobase+3)) {
		return false;
	}
	return true;
}
 
function afficheDispo(obj) {
	username_alert = document.getElementById('username_alert');
	// suppression du texte existant
	while(username_alert.firstChild != null) {
		username_alert.removeChild(username_alert.firstChild);
	}
	
	// Construction des noeuds
	var tabResult = obj.responseXML.getElementsByTagName('resultat');
	var resultat = tabResult.item(0);
	var dispo = resultat.getAttribute('dispo');
	
	// creation du message suivant le cas
	if (dispo == "true") {
		var texte = document.createTextNode("Le nom d'utilisateur est disponible");
		username_alert.appendChild(texte);
	} else {
		if (dispo == "false") {
			var texte = document.createTextNode("Le nom d'utilisateur n'est pas disponible");
			username_alert.appendChild(texte);
		}
	}
}

function validate(event) {
	// Compatibilité IE / Firefox
	if(!event&&window.event) {
		event=window.event;
	}
	if(event.keyCode > 31 && (event.keyCode < 45 || event.keyCode > 57))
		event.returnValue = false;
		event.cancelBubble = true;
	if(event.which > 31 && (event.which < 45 || event.which > 57))
		event.preventDefault();
		event.stopPropagation();
		return false;
}

function confirmDeleteCapture(id){
	if (confirm("Etes vous sûre de vouloir supprimer cette capture ? id("+id+")")){
		var path = 'mcaptures/delete.php?id_capture=' + id;
		window.document.location = path;
	}
}

function confirmDeletePhoto(id){
	if (confirm("Etes vous sûre de vouloir supprimer cette photo ? id("+id+")")){
		var path = 'mphotos/delete.php?id_photo=' + id;
		window.document.location = path;
	}
}

function switchDiv(id){
	if (id==1){
		document.getElementById("stats_annee").style.display = 'none';
		document.getElementById("stats_total").style.display = 'block';
		document.getElementById("a_stats_annee").style.textDecoration = 'none';
		document.getElementById("a_stats_total").style.textDecoration = 'underline';
	}else{
		document.getElementById("stats_total").style.display = 'none';
		document.getElementById("stats_annee").style.display = 'block';
		document.getElementById("a_stats_annee").style.textDecoration = 'underline';
		document.getElementById("a_stats_total").style.textDecoration = 'none';
	}
}

var xhr = null;
function ShowPage(FILE,IDBLOCK){
	if(window.XMLHttpRequest) // FIREFOX
		{
		xhr_object = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) // IE
		{
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
		{
		return(false);
	}

	xhr_object.open("GET", FILE, false);
	xhr_object.send(null);

	if(xhr_object.readyState == 4 && xhr_object.status == 200){
		document.getElementById(IDBLOCK).innerHTML = xhr_object.responseText;
	}
	else	{
		return(false);
	}
}

function underline(id){
	// on place tout le monde à none
	document.getElementById("a_actu_captures").style.textDecoration = 'none';
	document.getElementById("a_actu_ajouts").style.textDecoration = 'none';
	document.getElementById("a_actu_com").style.textDecoration = 'none';


	// on applique la class au href souhaité
	var onglet	= document.getElementById(id);
	document.getElementById(id).style.textDecoration = 'underline';
}

/*--------------- Fonction openCalendar ---------------
		Fonction permettant d'afficher le calendrier
-------------------------------------------------------*/
function openCalendar(params, form, field, type){
	//On affiche le claendrier
	window.open("./inc/calendar.php?" + params, "calendar", "width=450,height=150,modal");
	//On definit le champs du formulaire a remplir
	dateField_en = document.getElementById(field);
	dateField_fr = document.getElementById(field);
	//On definit le type de date (date ou datetime ou timestamp)
	dateType = type;
}
/*-----------------------------------------------------*/
