Survey
    .StylesManager
    .applyTheme("modern");

//Add a property a text property into all questions types and into page

function showDescription(element) {
    document
        .getElementById("questionDescriptionText")
        .innerHTML = element.popupdescription;
    $("#questionDescriptionPopup").modal();
}

var json = {
    "locale": "it",
    "pages": 
   [
        {
            "name": "page1",
            "navigationTitle":"Iscrizione evento",
            "elements": 
            [
                     
               {
                 "type": "text",
                 "name": "Nome",
                 "title": "Nome",
                 "isRequired": true,
                 "maxLength": 100
                },
                {
                 "type": "text",
                 "name": "Cognome",
                 "title": "Cognome",
                 "isRequired": true,
                 "maxLength": 100
                },
                {
               "name": "Email",
               "type": "text",
               "isRequired": true,
                "title": "Indirizzo email",
                "inputType": "email"    
               },
               {
               "type": "html",
               "name": "Informativa privacy",
               "title": "Newsletter",
               "html": "<a href=\"https://www.arcafondi.it/s/informativa-privacy\\\"> Consulta l'informativa privacy</a>"
              },
              {
              "type": "checkbox",
              "name": "Consenso al trattamento dei dati personali",
              "isRequired": true,
              "choices": [
              "Conferisco il consenso al trattamento dei miei dati personali da parte di Arca Fondi SGR S.p.a. per la gestione di tutte le attività connesse all’organizzazione dell’evento."
               ]
            } 
          ]
        }
    ],
    "showCompletedPage": false
};

window.survey = new Survey.Model(json);

survey
    .onComplete
    .add(function (result) {
  document.getElementById('surveyResult_formEventiNuovo').value = JSON.stringify(result.data);
  document.getElementById("SurveyForm_eventiNuovo").submit(); 
    });

survey
    .onAfterRenderQuestion
    .add(function (survey, options) {
        //Return if there is no description to show in popup
        if (!options.question.popupdescription)
            return;

        //Add a button;
        var btn = document.createElement("button");
        btn.type = "button";
        btn.className = "btn btn-info btn-xs";
        btn.id = "info_button";
        btn.innerHTML = "Info";
        var question = options.question;
        btn.onclick = function () {
             showDescription(question);
           
        }
        var header = options
            .htmlElement
            .querySelector("h5");
        var span = document.createElement("span");
        span.innerHTML = "  ";
        header.appendChild(span);
        header.appendChild(btn);
  });

$("#surveyElement").Survey({model: survey});

//Mario
document.addEventListener('DOMContentLoaded', (event) => {
    var completeButton = document.querySelector('.sv-footer__complete-btn');
    if (completeButton) {
        completeButton.value = 'Iscriviti';
    }
});