var PregWeeks = new Class({
    initialize: function(day, month, year, acc) {
    	this.date_acc = new Date(year, month - 1, day);
    	if (!acc) this.date_acc.setTime(this.date_acc.getTime() + 24192000000);
			this.diff = this.date_acc - new Date().getTime();
      this.months = new Array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre');
    },
    semGro: function() {
    	return 38 - Math.round(this.diff / 604800000);
    },
    semAmen: function() {
    	return this.semGro() + 2;
    },
    dateEvo: function() {
    	var date_evo = new Date();
    	date_evo.setTime(this.date_acc - 12096000000); //20sa
    	return date_evo.getDate() + ' ' + this.months[date_evo.getMonth()];
    },
    dateSingle: function() {
    	var date_single = new Date();
    	date_single.setTime(this.date_acc - 7862400000); // 27sa
    	return date_single.getDate() + ' ' + this.months[date_single.getMonth()];
    }
});

function calculateDate() {
	var ans = new PregWeeks($('edtDay').value, $('edtMonth').value, $('edtYear').value, $('radAcc').checked);
	$('weeksText').setHTML('Vous êtes à ' + ans.semGro() + ' semaines de grossesse, soit ' + ans.semAmen() + ' semaines d\'aménorrhée.<br /><br />Le meilleur moment pour débuter vos séances <a href="./tarifs">Evolution</a> se situe vers le ' + ans.dateEvo() + '. Pour une <a href="./tarifs">séance unique</a> d\'échographie souvenir en 4 dimensions, votre rendez-vous devrait être aux allentours du ' + ans.dateSingle() + '.<br /><br /><a href="#' + ans.semGro() + '">Cliquez ici pour découvrir à quel stade de développement se situe votre bébé.</a>');
	$('weeksText').style.display = "block";
}
