// RAB PAS UTILISE
function fenetre_resize () {
	//window.innerWidth
}
function accueil_article_toggle (rubrique, article) {
	$('#' + rubrique + ' .article p').slideUp('fast');
	$('#article_' + article + ' p').slideDown('fast');
}
function accueil_articles_request (rubrique, limite) {
	$.post('Modules/Accueil_articles.php', {rubrique: rubrique, limite: limite}, function (retour) {
			$('#chat #messages').html(retour);
			$('#' + rubrique + ' .titre').after(retour);
	});
}

// MASQUE
function masque () {
	if ($('#masque').css('display') == 'block') {
		$('#masque').fadeOut('slow');
	}
	if ($('#masque').css('display') == 'none') {
		$('#masque').fadeIn('slow');
	}
}

// MENU
function menu () {
	masque();
	
	if ($('#menu').css('height') == '88px') {
		$('#menu #menu_bas').animate({
			opacity: 0
		}, 100, function () {
			/*$('#menu #menu_rubriques').animate({
				height: 512
			}, 500, function () {
			});*/
			$('#menu').animate({
				height: 512
			}, 500, function () {
				$('#menu #menu_fermeture').animate({
					opacity: 1
				}, 250, function () {
				});
				$('#menu #menu_autres a').css('display', 'inline-block');
			});
		});
	} else {
		$('#menu #menu_autres a').css('display', 'none');
		$('#menu #menu_fermeture').animate({
			opacity: 0
		}, 10, function () {
			/*$('#menu #menu_rubriques').animate({
				height: 88
			}, 500, function () {
			});*/
			$('#menu').animate({
				height: 88
			}, 500, function () {
				$('#menu #menu_bas').animate({
					opacity: 1
				}, 250, function () {
				});
			});
		});
	}
}

// LISTE DE RUBRIQUES
function rubriques_liste_js () {
	if (document.getElementById('rubriques_liste').style.display == 'block') {
		$('#rubriques_liste').slideUp("fast");
	} else {
		$('#rubriques_liste').slideDown("fast");
	}
}

// AJOUT / SUPPRESSION DE RUBRIQUE
function rubriques_clic_js (tag) {
	regex = new RegExp(tag, 'g');
	rubrique_ok = document.getElementById('formulaire').rubriques.value;
	if (regex.test(rubrique_ok)) {
		// Si contient la rubrique, alors suppression
		rubrique_ok = rubrique_ok.replace(regex, '');
	} else {
		// Si ne contient pas la rubrique, alors rajout
		rubrique_ok += '+' + tag;
	}
	rubrique_ok = rubrique_ok.replace(/\++/g, '+');
	rubrique_ok = rubrique_ok.replace(/(^\+|\+$)/, '');
	document.getElementById('formulaire').rubriques.value = rubrique_ok;
}

// PREVIEW ARTICLE
function article_preview () {
	chapeau = $('textarea[name=chapeau]').val();
	contenu = $('textarea[name=contenu]').val();
	$.post('Modules/Preview.php', {texte: chapeau}, function (retour) {
		$('#preview .chapeau').html(retour);
	});
	$.post('Modules/Preview.php', {texte: contenu}, function (retour) {
		$('#preview .contenu').html(retour);
	});
}

// PREVIEW PROPOSITION
function proposition_preview () {
	contenu = $('textarea[name=contenu]').val();
	$.post('Modules/Preview.php', {texte: contenu}, function (retour) {
		$('#preview .contenu').html(retour);
	});
}

// PREVIEW ESPACE PERSONNEL
function espace_preview () {
	contenu = $('textarea[name=contenu]').val();
	$.post('Modules/Preview.php', {texte: contenu}, function (retour) {
		$('#preview .contenu').html(retour);
	});
}

// VALIDATION SUPPRESSION
function popup_validation (message, lien) {
	if (confirm(message)) {
		window.location.href = lien;
	}
}

// COMMENTAIRES ARTICLES
function commentaire_affichage_form () {
	$('#commentaires form > p').slideUp('slow');
	$('#commentaires form > div').slideDown('slow');
	
	$('#commentaires form > p').before('<script type="text/javascript">setInterval(commentaire_carac_restants, 500);</script>');
}
function commentaire_focus_champ (champ) {
	if ($(champ).val() == 'Pseudo' || $(champ).val() == 'Message') {
		$(champ).val('');
	}
}
function commentaire_carac_restants () {
	if ($('#commentaire_form .message').val() == 'Message') {
		$('#commentaire_form .caracteres_restants span').html(500);
	} else {
		carac_restants = 500 - $('#commentaire_form .message').val().length;
		if (carac_restants > 0) {
			$('#commentaire_form .caracteres_restants span').html(carac_restants);
			$('#commentaire_form .caracteres_restants span').css('background', 'rgb(0,50,0)');
		}
		if (carac_restants <= 0) {
			$('#commentaire_form .caracteres_restants span').html('0');
			$('#commentaire_form .caracteres_restants span').css('background', 'rgb(255,0,0)');
		}
	}
}
function commentaire_supprimer (article, commentaire) {
	if (confirm('Etes-vous sur de vouloir supprimer ce commentaire ?')) {
		$.post('Modules/Commentaire_supprimer.php', {commentaire: commentaire}, function () {
			window.location.href = window.location.href;
		});
	}
}

// DEFILEMENT EVENEMENTS PROFIL
function evenements_boutons () {
	alpha_prec = 0.25;
	alpha_suiv = 0.25;
	bulle_prec = 'Il n\'y a aucun évènement plus récent';
	bulle_suiv = 'Il n\'y a aucun évènement plus ancien';
	if (profil_evenements_actuel > 1) {
		alpha_prec = 1;
		bulle_prec = 'Voir les évènements plus récents';
	}
	if (profil_evenements_actuel + profil_evenements_max < profil_evenements_nb) {
		alpha_suiv = 1;
		bulle_suiv = 'Voir les évènements plus anciens';
	}
	$('#evenements .page_prec').css({'opacity' : alpha_prec});
	$('#evenements .page_suiv').css({'opacity' : alpha_suiv});
	$('#evenements .page_prec').attr('title', bulle_prec);
	$('#evenements .page_suiv').attr('title', bulle_suiv);
}
function evenements_defilement (sens) {
	if (true) {
		position = $('#evenements .defileur').css('top');
		position = parseInt(position.replace(/px/gi, ''));
		if (sens == 'prec' && profil_evenements_actuel > 1) {
			position += 26;
			profil_evenements_actuel--;
		}
		if (sens == 'suiv' && profil_evenements_actuel + profil_evenements_max < profil_evenements_nb) {
			position -= 26;
			profil_evenements_actuel++;
		}
		$('#evenements .defileur').animate({
			top: position
		}, 100, function () {
		});
		evenements_boutons();
	}
}

// ENVOI MESSAGE PRIVE
function message_envoi () {
	if ($('#messages form input[name=destinataire]').val() != '' && $('#messages form input[name=titre]').val() != '' && $('#messages form textarea[name=contenu]').val() != '') {
		if ($('#messages form input[name=destinataire]').val() == 0) {
			if (confirm('Ce message privé va être envoyé à tous les membres.')) {
				$('#messages form').submit();
			}
		} else {
			$('#messages form').submit();
		}
	} else {
		alert('Vous devez remplir tous les champs.');
	}
}

// RECHERCHE
function recherche_submit () {
	if ($('#recherche_champ form input[name=recherche]').val() == '') {
		alert ('Une recherche doit comporter au moins un mot-clé.');
	} else {
		$('#recherche_champ form').submit();
	}
}

/* POPIN INSCRIPTION */
function popin_inscription (action) {
	if (action == 1) {
		$('#masque').show();
		$('#popin_inscription').show();
		$('#menu').css('z-index', '19');
	} else {
		$('#masque').hide();
		$('#popin_inscription').hide();
		$('#menu').css('z-index', '30');
	}
}
