d482fdc34671d62db2f804644474c84e03a05207
[cl7.git] / js / cl7.js
1 /**
2 * coding: utf-8
3 * Quelques bouts de JS pour le site de la corcelles-lan 7.
4 * Necessite la lib jQuery.
5 */
6
7 var cl7 = {};
8
9 cl7.verification_formulaire_inscription = function(util) {
10 if ($('#formulaireInscription input[name="pseudo"]').val() === "") {
11 util.messageDialogue("Le pseudo ne peut pas être vide");
12 return false;
13 }
14 if ($('#formulaireInscription input[name="pass1"]').val() === "" &&
15 $('#formulaireInscription input[name="pass2"]').val() === "") {
16 util.messageDialogue("Le password ne peut pas être vide");
17 return false;
18 }
19 if ($('#formulaireInscription input[name="pass1"]').val() !== $('#formulaireInscription input[name="pass2"]').val()) {
20 util.messageDialogue("Les passwords ne correspondent pas");
21 return false;
22 }
23 if ($('#formulaireInscription input[name="pass1"]').val().length < 3) {
24 util.messageDialogue("La taille de password doit être d'au moins 3 caractères");
25 return false;
26 }
27 if ($('#formulaireInscription input[name="nom"]').val() === "") {
28 util.messageDialogue("Le nom ne peut pas être vide");
29 return false;
30 }
31 if ($('#formulaireInscription input[name="prenom"]').val() === "") {
32 util.messageDialogue("Le prénom ne peut pas être vide");
33 return false;
34 }
35 if ($('#formulaireInscription input[name="e_mail"]').val() === "") {
36 util.messageDialogue("L'email ne peut pas être vide");
37 return false;
38 }
39 if ($('#formulaireInscription input[name="accord"]').length === 1 && !$('#formulaireInscription input[name="accord"]').attr("checked")) {
40 util.messageDialogue("Vous devez être d'accord avec le préambule");
41 return false;
42 }
43 return true;
44 };
45
46 cl7.maj_prix_inscription = function() {
47 var nbPeriodes = $('#formulaireInscription input[name="periodes[]"]:checked').length;
48 var prix = 5;
49 if (nbPeriodes === 3) {
50 prix = 40;
51 } else if (nbPeriodes != 0) {
52 prix = 15 * nbPeriodes;
53 }
54 $('#formulaireInscription span#prix').html(prix.toString());
55 };
56
57 $(document).ready(
58 function() {
59 var util = new cl7.Util();
60 $('form#formulaireInscription').submit(function() {
61 return cl7.verification_formulaire_inscription(util);
62 });
63
64 var messageUtilisateur = $('meta[name="messageUtilisateur"]').attr('content');
65 if (messageUtilisateur !== undefined) {
66 util.messageDialogue(messageUtilisateur);
67 }
68
69 $('form#formulaireInscription select[name="clanChoix"]').change(function() {
70 if ($(this).val() === '0') {
71 return;
72 }
73 $clan = $(this).val().split(';');
74 $('form#formulaireInscription input[name="clan_nom"]').val($clan[0]);
75 $('form#formulaireInscription input[name="clan_tag"]').val($clan[1]);
76 });
77
78 // inscrit les emails codés (page contacts)
79 $('a#contactPifou').attr('href', util.rot13('znvygb:tert.oheev@tznvy.pbz'));
80 $('a#contactLePiaf').attr('href', util.rot13('znvygb:tyrcvns695@zfa.pbz'));
81
82 $('#formulaireInscription input[name="periodes[]"]').change(function() {
83 cl7.maj_prix_inscription();
84 });
85 // met à jour le prix d'inscription
86 cl7.maj_prix_inscription();
87
88 // permet d'éviter de faire plus de choix qu'il n'en faut sur la page des jeux joués
89 var nbVotesMax = 3;
90 var coches = [];
91 $('#formulaireJeuxJoues input[name="votes[]"]:checked').each(function() {
92 coches.unshift(parseInt($(this).attr("value")));
93 });
94 $('#formulaireJeuxJoues input[name="votes[]"]').change(function() {
95 if($(this).attr("checked")) {
96 if (coches.length >= nbVotesMax) {
97 $('#formulaireJeuxJoues input[value="' + coches.pop() + '"]').attr("checked", false);
98 }
99 coches.unshift(parseInt($(this).attr("value")));
100 } else {
101 for (var i = 0; i < coches.length; i ++) {
102 if (coches[i] == parseInt($(this).attr("value"))) {
103 coches.splice(i, 1);
104 break;
105 }
106 }
107 }
108 });
109 }
110 );