$(function() {
	// effet de fondu pour les message
	$('p.success, p.info, p.warning, p.error').css('background-color', 'transparent');
	
	$('p.success').animate({backgroundColor: '#D4FFD4'}, 2000);
	$('p.info').animate({backgroundColor: '#DFF4FF'}, 2000);
	$('p.warning').animate({backgroundColor: '#FFFFD4'}, 2000);
	$('p.error').animate({backgroundColor: '#FFD4D4'}, 2000);
});

/**
 * Place la bonne icone devant les liens ayant la class "document" (en fonction de l'extension du href)
 * Pris en charge : .txt, .pdf, .doc(x), .xsl(x), .ppt(x), .rb, .php, .sql, .zip, .rar, .gz, .jpg, .png, .gif, .swf
 */
function set_document_icons()
{
	$('a.document').each(function() {
		var href = $(this).attr('href'),
			ext = href.substring(href.lastIndexOf('.')+1, href.length);
		$(this).addClass(ext);
	});
}

/**
 * Extraire l'id numérique de l'attribut id d'un élément
 * @return article_comment_42 -> 42
 */
function id_from_element(element)
{
	var string_with_id = element.attr('id')
	return string_with_id.substr(string_with_id.lastIndexOf('_') + 1);
}

function flash(element, color)
{
	element.animate({backgroundColor: color + ' !important'}, function() {$(this).animate({'backgroundColor': 'white'}); });
}

/**
 * Récupérer la date de naissance depuis les 3 selects du formulaire
 * @return une chaine de caractère contenant la date de naissance au format jj/mm/aaaa
 */
function getBirth()
{
	birth = $('select#birth1').val() + '/' + $('select#birth2').val()
		+ '/' + $('select#birth3').val();
	return birth;
}

/**
 * Calculer l'age a partir d'une date de naissance
 * @param birth_date: une chaine de caractère contenant la date de naissance au format jj/mm/aaaa
 * @return l'age
 */
function getAge(birth_date)
{
	today = new Date;
	var current_day = today.getDate();
	var current_month = today.getMonth() + 1;
	var current_year = today.getFullYear();
	
	var birth_infos = birth_date.split('/');
	var birth_day = birth_infos[0];
	var birth_month = birth_infos[1];
	var birth_year = birth_infos[2];
	
	if(current_month > birth_month) {
		return (current_year - birth_year);
	}
	else if(current_month < birth_month) {
		return (current_year - birth_year)-1;
	}
	else {
		if(current_day >= birth_day)
			return (current_year - birth_year);
		else
			return (current_year - birth_year)-1;
	}
}


