$(document).ready(function() {
	
	$.ajax({
		type:'GET',
		url: '/command.php/client/monCompte?l=fr',
		cache: false,
		success: function(html){
			$('#monCompte').html(html);
		}
	});	
	
	/* Gestion des projets */
	$(".projet").each ( function(){
		var conteneur = $(this);
		var id_projet = $(conteneur).attr("id_projet");
		var id_page_detail_projet = $(conteneur).attr("id_page_detail_projet");
		var langue = $(conteneur).attr("langue");
		var rewrite = $(conteneur).attr("rewrite");;
		$(conteneur).click(function (){
			// document.location.href="/page.php?id_page="+id_page_detail_projet+"&id_projet="+id_projet+"&l="+langue;	
			document.location.href="/"+rewrite;	
		});
	});
	
	$("#projetsRight").ready (function(){
		
		var langue = $("#projetsRight").attr("langue");
		
		$.ajax({
			type:'GET',
			data: 'l='+langue,
			url: '/command.php/projet/listRight',
			cache: false,
			success: function(html){
				$("#projetsRight").html(html);
			}
		});	
					
	});
	
	$("#listeProjets").ready (function(){
		var url = document.location.href;
		var reg = new RegExp('(\\?|&|^)id_projet=(.*?)(&|$)');
    	if(url.match(reg)){
			$.ajax({
				type:'GET',
				url: '/command.php/projet/shortList',
				cache: false,
				success: function(html){
					$("#listeProjets").html(html);
				}
			});	
						
		}
	});
	
	/* Projet sur la home */
	$("#projetHome").ready (function(){			
		var langue=$("#projetHome").attr("langue");
		$.ajax({
			type:'GET',
			url: '/command.php/projet/projetHome/?l='+langue,
			cache: false,
			success: function(html){
				$("#projetHome").html(html);
			}
		});	
					
	});
	
	/* Gestion des réactions */
	$(".placerReaction").each ( function(){
		var conteneur = $(this);
		var id_bloc = conteneur.attr("id_bloc");
		var langue = conteneur.attr("langue");
		$(conteneur).click( function(){
			if($('.reagir').css('display') == 'none'){
			
			$.ajax({
				type:'GET',
				url: '/command.php/reaction/getForm?id_bloc='+id_bloc+"&l="+langue,
				cache: false,
				success: function(html){
					$('.reagir').html(html);
					$('.reagir').slideDown("slow");
				}
			});	
			}
			else{
				$('.reagir').slideUp("slow");
			}
		});		
	});
	
	// Show reactions
	$(".vosReactions").each ( function(){
		var conteneur = $(this);
		var id_bloc = $(conteneur).attr("id_bloc");
		
		$(conteneur).click(function (){
			if($('#reaction_'+id_bloc).css('display') == 'none'){
				$('#reaction_'+id_bloc).slideDown("slow");
			}
			else{
				$('#reaction_'+id_bloc).slideUp("slow");
			}
 	    });
	});
	
	// Newsletters
	$("#sendSubscription").click(function (){
		var myForm = document.getElementById("subscribeform");
		var email = myForm.email.value;
		var id_groupe = myForm.id_groupe.value;
		var langue=$("#sendSubscription").attr("langue");
		
       $.ajax({
			dataType: "json",
			type:'POST',
			data: "email="+email+"&id_groupe="+id_groupe+"&l="+langue,
			url: '/scripts/NLRecord.php',
			cache: false,
			success: function(data){
				if(data.error){
					alert(data.error);	
				}
				else{
					document.location.href="/page.php?id_page=519&l="+langue;	
				}
			}
		});	

		
	});
	
	
	
});
