$(document).ready(function(){
	
	//bouton connexion
	/*$("#btn_connexion").click( function() {
										  
		passClair = $("#pass").val();
		passHash = $("#hash").val();
		salt = $("#salt").val();
	
		// Recuperation du mdp, vidage du champ
		pass = passClair;
		$("#pass").val("");
		
		// Calcul du hash
		hash = MD5(pass+salt);
		
		$("#hash").val(hash);
						
		$("#form_connexion").submit();
	});*/
	 $('.nyroModal').nyroModal();
	// copie des projets
	$('#copierProjet').click(function(){
		if($(this).attr('checked') == true)
			$('#divThematiqueCopie').fadeIn('fast');
		else
			$('#divThematiqueCopie').fadeOut('fast');
	});
	//galleries photo
	$("a.prettyPhoto").prettyPhoto({animation_speed:'normal',theme:'dark_rounded',slideshow:3000, autoplay_slideshow: false});
	$("area.prettyPhoto").prettyPhoto({animation_speed:'normal',theme:'dark_rounded',slideshow:3000, autoplay_slideshow: false});
	
	//activer surlignage ligne tableau
	$('table.activermover tr').hover(function() {
		if(!$(this).hasClass('ligne_titre') && !$(this).hasClass('ligne_grisee'))									
			$(this).addClass('over');
	}, function() {
		$(this).removeClass("over");
	});
	
	$('#form_lettre_info').submit(function(){
		if($('#nl_email').val() == "Votre adresse email"){
			afficherErreurs("Veuillez saisir votre adresse email.");	
		}else{
			
			$.ajax({
				type: "POST",
				url: "/modules/ajax/newsletter.php",
				data: "email="+$('#nl_email').val(),
				success: function(msg){
				
					$('#nl_email').val("Votre adresse email");
					
					var tab = msg.split('|');
						
					if(tab[0] == "ok")
						afficherConfirmation(tab[1]);	
					else
						afficherErreurs(tab[1]);	
					
					
				}
			});
		}
		return false;									  
	});
	/*
	//ligne clicable
	$('table tr').click(function() {
		if($(this).find('a').hasClass("ligneCliquable")){
			
			var lien = $(this).find('a.ligneCliquable').attr('href');
			
			//tester si le lien a un onclick
			if($(this).find('a.ligneCliquable').attr('onclick') != null){
//				alert($(this).find('a.ligneCliquable').attr('onclick'));
				window.open(lien); return false;
				
			}else{			
				document.location = lien;
			}
		}
	});
	*/
	
	// fenêtres modales 
	$("#dialog-alert").dialog({
		resizable: false,						
		modal: true,
		draggable: false,
		autoOpen: false,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});
	if($("#message-alert").html() != "")
	{
		$("#dialog-alert").dialog("open");
	}
	
	$("#dialog-confirmation").dialog({
		resizable: false,						
		modal: true,
		draggable: false,
		closeOnEscape: true,
		autoOpen: false,
		buttons: {
			Ok: function() {
				$(this).dialog('close');
				
				
			}
		},
		close: function(event, ui) {
			if(typeof(urlRetourConfirmation) != 'undefined' && urlRetourConfirmation != "")
				$(location).attr('href', urlRetourConfirmation);
		}

	});
	if($("#messageconfirmation").html() != "")
	{
		$("#dialog-confirmation").dialog("open");
	}
	$("a.suppression-confirm").click(function(){
										  
		var url = $(this).attr('href');
		
		$("#message-confirmation").html($(this).attr('rel'));
		
		$("#dialog-confirm").dialog({
			modal: true,
			resizable: false,
			draggable: false,
			buttons: {	
				Supprimer: function() {
					$(this).dialog('close');
					
					$(location).attr('href', url);
					
				},
				Annuler: function() {
					$(this).dialog('close');
					
				}
			}
		});
		return false;

	});
});

function afficherErreurs(erreurs){
	$('#message-alert').html(erreurs);
	$('#dialog-alert').dialog("open");
}
function afficherConfirmation(confirmation){
	$('#messageconfirmation').html(confirmation);
	$('#dialog-confirmation').dialog("open");
}


