﻿
/* Au chargement de la page */
Event.observe(window, 'load', function(){

	if($('compteOui') && $('compteNon')) {
		$('compteOui').observe('click', function (_ev){
			possedeUnCompte();
		});
		$('compteNon').observe('click', function (_ev){
			nePossedePasDeCompte();
		});
		
		if($('compteOui').checked) {
			possedeUnCompte();
		}
		else if($('compteNon').checked) {
			nePossedePasDeCompte();
		} else {
			pasDeChoix();
		}
			
		formEmail = new formEmail();
	}

});


/* Affiche les informations lorsque l'utilisateur possède un compte banquaire */
function possedeUnCompte()
{
	$('textePossedeCompte').setStyle({display: 'block'});
	$('textePasDeCompte').setStyle({display: 'none'});
	if($$('span.important')) $$('span.important')[0].setStyle({display: 'none'});
}

/* Affiche les informations lorsque l'utilisateur ne possède pas de compte banquaire */
function nePossedePasDeCompte()
{
	$('textePossedeCompte').setStyle({display: 'none'});
	$('textePasDeCompte').setStyle({display: 'block'});
}

/* Masque tous, lorsque l'utilisateur n'a pas choix oui ou non */
function pasDeChoix()
{
	$('textePossedeCompte').setStyle({display: 'none'});
	$('textePasDeCompte').setStyle({display: 'none'});
	if($$('span.important')) $$('span.important')[0].setStyle({display: 'none'});
}

var formEmail = Class.create(Validate,{

	initialize: function($super, options){
		$super();
		this.reqire_fields = {};
		this.in_form = 'formEmail';
		this.form = $(this.in_form);
		this.btn_submit = $('submit_formEmail');
		this.btn_submit.observe('click', function (_ev){
			_ev.stop();
			
			this.reqire_fields.format_of = {};
			
			this.reqire_fields.format_of.emailMdp = {use: 'email', message: 'Le format de votre adresse email n\'est pas correct.'};
			
			this.check_form();
		}.bind(this));
	},
	
	submit_form: function()
	{
		this.form.submit();
    }
});