ADD premier commit
[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 $(document).ready(
47 function() {
48 var util = new cl7.Util();
49 $('form#formulaireInscription').submit(function() {
50 return cl7.verification_formulaire_inscription(util);
51 });
52
53 $('form#formulaireInscription select[name="clanChoix"]').change(function() {
54 if ($(this).val() === '0') {
55 return;
56 }
57 $clan = $(this).val().split(';');
58 $('form#formulaireInscription input[name="clan_nom"]').val($clan [0]);
59 $('form#formulaireInscription input[name="clan_tag"]').val($clan [1]);
60 });
61
62 // inscrit les emails codés (page contact)
63 $('a#contactPifou').attr('href', util.rot13('znvygb:tert.oheev@tznvy.pbz'))
64 $('a#contactLePiaf').attr('href', util.rot13('znvygb:tyrcvns695@zfa.pbz'))
65
66 // permet d'éviter de faire plus de choix qu'il n'en faut sur la page des jeux joués
67 var nbVotesMax = 3;
68 var coches = [];
69 $('#formulaireJeuxJoues input:checked').each(function() {
70 coches.unshift(parseInt($(this).attr("value")));
71 });
72 $('#formulaireJeuxJoues input[name="votes[]"]').change(function() {
73 if($(this).attr("checked")) {
74 if (coches.length >= nbVotesMax) {
75 $('#formulaireJeuxJoues input[value="' + coches.pop() + '"]').attr("checked", false);
76 }
77 coches.unshift(parseInt($(this).attr("value")));
78 } else {
79 for (var i = 0; i < coches.length; i ++) {
80 if (coches[i] == parseInt($(this).attr("value"))) {
81 coches.splice(i, 1);
82 break;
83 }
84 }
85 }
86 });
87 }
88 );