/*$(document).ready(function() {

	$('textarea#commentaire').autoResize({
		animateDuration : 300,
		extraSpace : 40
	});

});*/

function VDM(id,nb) {

	$.post("/apps/vote.php",{"id":id,"nb":nb},function(html) {
		$('span#vote'+id).css('display','none');
		if (html == 'NA') {
			$('#vote'+id).html('vous avez déjà validé... pourriture communiste').fadeIn();
		} else {
			$('#vote'+id).html('merci d\'avoir validé ! ('+html+')').fadeIn();
		}
	});
	
	pageTracker._trackEvent("Votes", "VDM", id);

}

function VDM_BF(id,nb) {

	$.post("/apps/vote_bf.php",{"id":id,"nb":nb},function(html) {
		$('span#votebf'+id).css('display','none');
		if (html == 'NA') {
			$('#votebf'+id).html('vous avez déjà balancé... pourriture communiste').fadeIn();
		} else {
			$('#votebf'+id).html('merci d\'avoir balancé ! ('+html+')').fadeIn();
		}
	});
	
	pageTracker._trackEvent("Votes", "TLBM", id);

}

function signaler(type,id) {

	$('#signaler'+id).css('display','none');
	$.get("/apps/moderer.php?type="+type+"&id="+id,function(html) {
		$('#signaler'+id).html('abus signalé');
	});
	$('#signaler'+id).fadeIn();

}

function cut(input) {

	if (input.value.length >= 300) {
		input.value = input.value.substring(0,300);
	}

	var reste = 300 - input.value.length;
 	var print =  reste;
	
	$(".ok #compteur").html(input.value.length+'/300');

}

function submitToggle() {

	if ($('#submit').css('display') == 'none') {
		$('#submit').slideDown();
		pageTracker._trackEvent("Actions", "Submit VDM", "Down");
	} else {
		$('#submit').slideUp();
		pageTracker._trackEvent("Actions", "Submit VDM", "Up");
	}

}

function displayMail() {

	$('#submit .input_mail').html('Email (optionnel)'+' : <input type="text" name="mail">');

}

function plusToggle(id) {

	if ($('#plus'+id).css('display') == 'none') {
		$('#plus'+id).slideDown();
		pageTracker._trackEvent("Actions", "Plus...", "Down");
	} else {
		$('#plus'+id).slideUp();
		pageTracker._trackEvent("Actions", "Plus...", "Up");
	}

}

function Favori(action,id) {

	$.get("/apps/favori.php?action="+action+"&id="+id,function() {
		if (action == 'add') {
			$('#plus'+id+' .plus_bouton#favori').attr('OnClick',"Favori('delete','"+id+"');");
			$('#plus'+id+' .plus_bouton#favori .label').html('Supprimer de mes favoris');
			pageTracker._trackEvent("Actions", "Favori", "Ajout");
		} else {
			$('#plus'+id+' .plus_bouton#favori').attr('OnClick',"Favori('add','"+id+"');");
			$('#plus'+id+' .plus_bouton#favori .label').html('Ajouter à mes favoris');
			pageTracker._trackEvent("Actions", "Favori", "Suppression");
		}
	});

}


function toggleSuiviComms(type,id) {

	$.get("/apps/togglesuivi.php?type="+type+"&id="+id,function(html) {
		if (html == '1') {			
			$('span.suivicomm').fadeOut( function() { $('span.suivicomm').html('<a href="javascript:toggleSuiviComms(\''+type+'\',\''+id+'\');">Désactiver le suivi</a>'); $('span.suivicomm').fadeIn(); });
		} else {
			$('span.suivicomm').fadeOut( function() { $('span.suivicomm').html('<a href="javascript:toggleSuiviComms(\''+type+'\',\''+id+'\');">Activer le suivi</a>'); $('span.suivicomm').fadeIn(); });
		}
	});

}

function compte_SuiviListe() {

	if ($('#suivi').css('display') == 'none') {

		$.get("/apps/suivi.php?action=display",function(html) {
	
			$('#suivi').html(html);
			compte_SuiviEvent();
			$('#suivi').slideDown();
	
		});
	
	} else {
	
		$('#suivi').slideUp();
	
	}

}

function compte_SuiviEvent() {

	$('#suivi input[type=checkbox]').click(function() {

		nombre = parseInt($('span#suivi_nb').text());
		id = $(this).attr('id').replace('vdm','');
		if ($(this).is(':checked') == true) {
			nombre++;
			$.get("/apps/togglesuivi.php?type=vdm&id="+id);
		} else {
			nombre--;
			$.get("/apps/togglesuivi.php?type=vdm&id="+id);
		}
		$('span#suivi_nb').html(nombre);

	});

}

function displayValidInfos() {

	$('#valid_no_infos').parent('div.champ').css('height','108px');
	$('#valid_no_infos').parent('div.champ').find('label').css('height','80px');
	$('#valid_no_infos').html('Sans valider votre adresse, vous ne pouvez pas laisser de commentaires sur le blog ou les VDM. Si votre adresse est bonne, <a href="javascript:sendValid();">cliquez ici pour recevoir</a> le mail de validation. Si elle est incorrecte, modifiez-la, vous recevrez un e-mail dans l\'instant.');

}

function sendValid() {

	$('#valid_no_infos').slideUp(function() {
		$('#valid_no_infos').parent('div.champ').css('height','68px');
		$('#valid_no_infos').parent('div.champ').find('label').css('height','40px');
		$.get("/apps/valid_send.php",function() {
			$('#valid_no_infos').html('Nous venons de vous envoyer un e-mail pour valider votre adresse e-mail, vous devriez le recevoir dans quelques minutes.');
			$('#valid_no_infos').slideDown();
		});
	});

}

function deleteRequest() {
	$.get("/compte/suppression/demande",function(html) {
		if(html == "ok") {
			$('#deleteinstruction').fadeOut();
			$('#deleterequest').css('display','none');
			$('#deleterequest').html('Un mail vous a été envoyé avec toutes les instructions pour valider la suppression. Vous le recevrez dans quelques minutes. Vous pouvez, si vous le souhaitez, <a href="javascript:deleteAnnul()">annuler cette procédure</a>.');
		}
		$('#deleterequest').fadeIn();
	});	
}

function deleteAnnul() {
	$.get("/compte/suppression/annulation",function(html) {
		if(html == "ok") {
			$('#deleterequest').css('display','none');
			$('#deleterequest').before('<span id="deleteinstruction">Vous pouvez supprimer votre compte à tout moment. Une fois la demande effectuée via le lien ci-dessous, vous recevrez un lien par mail vous permettant de confirmer cette suppression.<br></span>');
			$('#deleterequest').html('<a href="javascript:deleteRequest();">Demandez la suppression de votre compte</a>');
		}
		$('#deleterequest').fadeIn();
	});		
}

function compte_FormatNL() {

	$.get("/apps/format_nl.php",function(html) {
		if (html == 'Texte') {
			$('#format_nl').html('Texte');
			$('#formater_nl').html('changer en HTML');
		} else {
			$('#format_nl').html('HTML');
			$('#formater_nl').html('changer en texte');
		}
	});

}

function afCountdown() {

	if ($('#alerte_af span#secondes')) {
		nombre = parseInt($('#alerte_af span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) nombre = '0';
			$('#alerte_af span#secondes').html(nombre);
			if (nombre == 1) $('#alerte_af span#secondes_txt').html('seconde');
			setTimeout('afCountdown();',1000);
		} else {
			$('#alerte_af').html('Vous pouvez à nouveau commenter ;)');
		}
	}

}

function afCountdownComment(id) {

	if ($('#commentEdit'+id+' span#secondes')) {
		nombre = parseInt($('#commentEdit'+id+' span#secondes').html());
		if (nombre > 0) {
			nombre = nombre-1;
			if (nombre == 0) {
				nombre = '0';
				$('#commentEdit'+id).fadeOut();
			}
			$('#commentEdit'+id+' span#secondes').html(nombre);
			if (nombre == 1) 
				$('#commentEdit'+id+' span#secondes_txt').html('seconde');
			setTimeout('afCountdownComment('+id+');',1000);
		}			
	}

}

function AbusDesc(id) {
	$('#abusdesc').css('display','none');
	$.get("/apps/compte_abus_desc.php?id="+id,function(html) {
		$('#abusdesc').html('Abus signalé');
	});
	$('#abusdesc').fadeIn();
}

function ClosePub(){
	$.get("/apps/megaban_close.php",function(html) {
		$('#pub_megaban').slideUp();
	});
} 

function DTCvalid(id){
	$.get("/apps/concoursDTC_valid.php?id="+id,function(html) {
		if(html == "ok")
			$('#dtc'+id).slideUp( function() { $('#dtc'+id).html('<p style="text-align:center; color:#85c527">Mise à jour effectuée !</p>'); $('#dtc'+id).slideDown(); });
	});
}

function noel2009valid(id){
	$.get("/apps/concours_noel2009_valid.php?id="+id,function(html) {
		if(html == "ok")
			$('#noel2009'+id).slideUp( function() { $('#noel2009'+id).html('<p style="text-align:center; color:#85c527">Vous êtes inscrit(e) pour le tirage au sort !</p>'); $('#noel2009'+id).slideDown(); });
	});
}


function fbs_click(u,t) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	pageTracker._trackEvent("Actions", "Facebook", u);
	return false;
}

function addslashes( str ) {
    return (str+'').replace(/([\\"'])/g, "\\$1");   
}

function stripslashes( str ) {
    return str.replace('/\(.)/g', '$1');
}