// Fonction d'identification
function identif(){

	var user = document.getElementById("login").value;
	var pwd = document.getElementById("pwd").value;

	//Calcul de l'empreinte du mot de passe
	pwd = (pwd != "") ? MD5(pwd) : "";
	res = request("ajax/identification.php", "user="+ user + "&pass=" + pwd);
	if( res == 0){
		show_message("Login ou mot de passe incorrect !",2);
	}else{
	
		if(navigator.appName == "Netscape"){
			dynamiccontentNS6("Ident",res);
			res = request("ajax/identification.php", "droitsAdmin=oui");
			if(res==1){
				dynamiccontentNS6("administration","<a href='menuAdmin.php'><img src='images/administration.gif' alt='' /></a>");
			}
		}else{
			Ident.innerHTML = res;
			res = request("ajax/identification.php", "droitsAdmin=oui");
			if(res==1){
				administration.innerHTML = "<a href='menuAdmin.php'><img src='images/administration.gif' alt='' /></a>";
			}
		}

		if(document.getElementById("listDocuments")){
			getDonneesDocumentation();
		}		
	}	
}



function deconnexion(){
	request("ajax/identification.php", "deconnexion=oui");
	
	if(navigator.appName == "Netscape"){
		dynamiccontentNS6("Ident","<div id='nonConnecte'><span id='connexion'>CONNEXION</span><br/><label for='login'>login</label><input type='text' id='login' /><br/><label for='pwd'>mot de passe</label><input type='password' id='pwd' /><br/><a href='#' onclick='identif();'><img src='images/validerVert.jpg' style='border:0;' alt='' /></a></div>");
		dynamiccontentNS6("administration","");
	}else{
		Ident.innerHTML = "<div id='nonConnecte'><span id='connexion'>CONNEXION</span><br/><label for='login'>login</label><input type='text' id='login' /><br/><label for='pwd'>mot de passe</label><input type='password' id='pwd' /><br/><a href='#' onclick='identif();'><img src='images/validerVert.jpg' style='border:0;' alt='' /></a></div>";
		administration.innerHTML = "";
	}
	
	if(document.getElementById("listDocuments")){
		getDonneesDocumentation();
	}
}

function ouvreFiche(idSelect){
	var selection = document.getElementById(idSelect).options[document.getElementById(idSelect).selectedIndex].value;
	if(selection!=0){
		document.location.href="fiche.php?numAssoc="+selection;
	}else{
		show_message("Veuillez choisir une association !",2);
	}
}


/**************************************************************************************************************
 Gestion modification fiche
***************************************************************************************************************/
// Test droit de modification
function dmdModifFiche(){

	res = request("ajax/identification.php", "droitsFiche=oui");

	if(res==0){
		show_message("Acces reserve !",2);
	}else{
		document.location.href="modifFiche.php";
	}
}


/**************************************************************************************************************
 Fonction qui affiche dynamiquement les nouvelles valeurs pour Firefox
***************************************************************************************************************/
function dynamiccontentNS6(elementid,content){
	if (document.getElementById && !document.all){
		rng = document.createRange();
		el = document.getElementById(elementid);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(content);
		while (el.hasChildNodes())
		el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
}
