//voter
function voterActu(id,choix)
{
	

$("#ligne_vote"+id+" a.choix1").attr("onclick","javascript:void(0);");
$("#ligne_vote"+id+" a.choix2").attr("onclick","javascript:void(0);");
	
	$.ajax({
  type: "POST",
  url: "centrale.php",
  async: false,
  cache: false,
  data: "action=voter_actu&ida="+id+"&choix="+choix,
}).done(function( msg ) {
	

	$("#ligne_vote"+id+"").addClass("deja_vote");
	$("#ligne_vote"+id+" a.choix"+choix+"").addClass("selected_choix");
	
	$("#ligne_vote"+id+" p.para_merci").show();
	
	if(choix=="1")
	$("#ligne_vote"+id+" a.choix2").addClass("disabled_choix");
	
	if(choix=="2")
	$("#ligne_vote"+id+" a.choix1").addClass("disabled_choix");
	
	

	
});
	
}

//soumettre le formulaire
function soumettreCommentaire(idform)
{
	var passform=true;
if( ($("#pseudo_commentaire_"+idform+"").val()=='')||($("#pseudo_commentaire"+idform+"").val()=='Entrez  votre nom / pseudo') )
 passform=false;
 

 
 if( ($("#contenu_commentaire_"+idform+"").val()=='')||($("#contenu_commentaire_"+idform+"").val()=='Et pour finir faites parler votre plume ici') )
 passform=false;
 
 
	if(passform)
	{$('#'+idform+'').submit();
	$("#"+idform+" .res_comment").html("");
	}
	
	else
	$("#"+idform+" .res_comment").html("Vous devez compléter votre commentaire.");
	
}

//fonction chargerPosts
function chargerPosts(id,ida,page,ind)
{
$("#ln_"+id+" .pagination_post a.fleche_page").remove();	
$("#ln_"+id+" .pagination_post").addClass("pagination_loading");

	
	
$.ajax({
  type: "POST",
  url: "ajax_type_modele.php",
  async: false,
  cache: false,
  data: "action=load_com&ida="+ida+"&page="+page+"&id="+id+"&ind="+ind,
}).done(function( msg ) {
	$("#ln_"+id+" .pagination_post").remove();
	$("#ln_"+id+"").append(msg);
	
});

}

//fonction ouverture collapse commentaire
function openCollapse(id)
{

	$("#ln_"+id).slideDown("slow");
	$("#open_"+id).hide();
	$("#close_"+id).show();
}

//fonction fermeture collapse commentaire
function closeCollapse(id)
{
	$("#ln_"+id).slideUp("slow");
	$("#open_"+id).show();
	$("#close_"+id).hide();
}

//filtre accueil 
function filterPage(action,classe,page)
{
	
$("#menu_actus").attr("class",""+classe);
	
if(page==0)
$("#liste_accueil").html('<li class="liste_loading"></li>');
else
$("#liste_accueil li.ligne_pagination a.fleche_page").addClass("fleche_loading");


	
$.ajax({
  type: "POST",
  url: "ajax_type_modele.php",
  data: "action="+action+"&page="+page+""
}).done(function( msg ) {
	if(page==0)
	$("#liste_accueil").html(msg);
	else
	{
	$("#liste_accueil li.ligne_pagination a.fleche_loading").remove();
	$("#liste_accueil").append(msg);
	
	}
	
	
  //alert( "Data Saved: " + msg );
});
	
}

$(document).ready(function(){
	
$('form.ajaxform').each(function(){
	
	var id_form=$(this).attr('id');
	
	   $('#'+id_form).ajaxForm(function() { 
	                $('.res_comment').html("Votre commentaire a été soumis avec succès.");					
					$('.ajaxform').resetForm();
					
					//alert("l'article est :"+$("#"+id_form+" input[name=ida]").val());
					
					$.ajax({
  type: "POST",
  url: "ajax_type_modele.php",
  async: false,
  cache: false,
  data: "action=load_last_com&ida="+ $("#"+id_form+" input[name=ida]").val(),
}).done(function( msg ) {
	var class_addition="ligne_grise";
	
	var premiere_lignecom=$("#"+id_form+"").parent(".ligne_collapse_com").find(".ligne_post_com:first");
	
	var id_global=$("#"+id_form+"").parent(".ligne_collapse_com").attr("id");
	
	
	$("#cpt"+id_global).html( (parseInt($("#cpt"+id_global).html())+1));
	
	
	if($(premiere_lignecom).hasClass("ligne_grise"))
	{ class_addition="";}
	
	
	
	
	 
	$("#"+id_form+"").after(msg);
	$("#"+id_form+"").parent(".ligne_collapse_com").find(".ligne_post_com:first").addClass(class_addition);

	
});
					
					
					
            });
			
}); 			 
	
	//masquer les collapse
	$(".ligne_collapse_com").not(".futur_com").hide();
	
	//masquer les background des derniers elements
	$(".fiche_verdict:last").addClass("fiche_verdict_nobg");
	$(".encart_blog:last").addClass("encart_blog_nobg");
	
	
	//effet click menu navigation
	var slide_load="";
	$("#main #cadtre_slide #menu_nav_article li a.link_nav_article").click(function(){
		
		if(!$(this).hasClass("selected"))
		{
		slide_load=	$(this).attr("rel");
		$("a.link_nav_article").not($(this)).removeClass("selected");
		$(this).addClass("selected");
		
		//masquer le slide encours
		$(".bloc_article:visible").fadeOut("slow",function(){ $(""+slide_load).fadeIn("slow"); });
		
		}
		
		});
		
	//click des choix commandes
	
		$("#choix_cat_cmd h3.h3new").click(function(){
		
		if($(this).next("div.slide_panier").not(":animated"))
		{
					if($(this).hasClass("selected"))
					{$(this).removeClass("selected"); $(this).next("div.slide_panier").slideUp(400);  }
					else
					{$(this).addClass("selected"); $(this).next("div.slide_panier").slideDown(400); }
					
		}
		});	
	
	
	//slide authentification
	$("#slide_auth").click(function(){
		
		$("#slide_auth").toggleClass("marge_selected");
		$("#formu_auth_usbek").toggle();

		
		});
	
		// validation du formulaire /****************************************************************/
	$("form.valider").validate({
		/*showErrors: function(errorMap, errorList) { 
if (errorList.length > 0) {
jQuery('#msgerror').html( errorList[0].message);        }    },	*/		


		rules: {
			captcha: {
				required: true,
				remote: "captcha/process.php"
			},
			
    passwordc: {
      equalTo: "#password"
    }
		},
		messages: {
			captcha: "<br/>Code correcte doit être saisi. <br/>Cliquez sur l'image pour générer un nouveau code."	
		},
	
	success: function(label) {
			label.addClass("valid");
		}
		
	});		
	
		// rafaraichissement captcha				   
	$("#refreshimg").live("click",function(){
		$.post('captcha/newsession.php');
		$("#captchaimage").load('captcha/image_req.php');
		return false;
	});
			
			
			$("#finscription").validate({
		/*showErrors: function(errorMap, errorList) { 
if (errorList.length > 0) {
jQuery('#msgerror').html( errorList[0].message);        }    },	*/		


		rules: {
			captcha: {
				required: true,
				remote: "captcha/process.php"
			},
			
    passwordc: {
      equalTo: "#password"
    }
		},
		messages: {
			captcha: "<br/>Code correcte doit être saisi. <br/>Cliquez sur l'image pour générer un nouveau code."	
		},
	
	success: function(label) {
			label.addClass("valid");
		}
		
	});	
	
	
	$('input.uploadify').each(function(){
		
		var id_fichier=$(this).attr("id");
		
		 $('#'+id_fichier).uploadify({
	   
	  
    'uploader'  : 'uploadify/uploadify.swf',
    'script'    : 'uploadify/uploadify.php',
    'cancelImg' : 'uploadify/cancel.png',
    'folder'    : 'admin/media/img_avatar',
	'buttonImg' : 'images/bt_upload.jpg',
	'width' : '189',
	'fileExt'     : '*.jpg;*.gif;*.png',
    'fileDesc'    : 'Choisissez votre avatar',
	'sizeLimit'   : 1048576,
    'auto'      : true,
	'onComplete'  : function(event, ID, fileObj, response, data) {
      
	  $("#"+id_fichier).parent(".zone_upload").find(".zone_picto_avatar").html('<img src="admin/media/timage/phpThumb.php?src=../../media/img_avatar/'+fileObj.name+'&h=36&w=36&far=C&bg=#ffffff&q=100" width="36" height="36"  class="avatar" /> ');
	  $("#"+id_fichier).parent(".zone_upload").find(".filename").val(fileObj.name);
	  
	 // alert("L'id de l'upload est :"+id_fichier);
	  
    }
  });
		
		
		});

 

	
	
	});
