if (!Kwo) var Kwo = {};

var Pea = {};

Pea.Questionnaire = {
  communicationValidate : function (type) {
    var type = type || null;
    if (!type) {
      alert('Veuillez répondre à toutes les questions.');
      return false;
    }
    var score = 0;
    var nbr_reponse = 0;
    var names = [];
    var elements = $$('.columns .bigcol .document .questionnaire .questions input[type="radio"]');
    elements.each(function(elt) {
      names.push($(elt).getAttribute('name'));
      if (elt.checked) {
        nbr_reponse++;
        var point = Number(elt.readAttribute('data-point'));
        score = score + point;
      }
    });
    if (names.uniq().length != nbr_reponse || nbr_reponse < 1) {
      alert('Veuillez répondre à toutes les questions.');
      return false;
    }
    Kwo.exec('/pea/data_questionnaire_' + type,
             {score:score},
             {container:$$('.columns .bigcol .document .questionnaire .scores_reponses')[0],
              callback:function(){ Pea.Questionnaire.hideQuestion(); Pea.Questionnaire.showScore(); }
             })
  },
  returnToQuestion : function() {
    Pea.Questionnaire.showQuestion();
    Pea.Questionnaire.hideScore();
  },
  showQuestion : function() {
    $$('.columns .bigcol .document .questionnaire .questions')[0].show();
  },
  hideQuestion : function() {
    $$('.columns .bigcol .document .questionnaire .questions')[0].hide();
  },
  showScore : function() {
    $$('.columns .bigcol .document .questionnaire .scores_reponses')[0].show();
  },
  hideScore : function() {
    $$('.columns .bigcol .document .questionnaire .scores_reponses')[0].hide();
  }
};

