document.addEventListener('check-step-1', checkValuesStep1);
document.addEventListener('check-step-2', checkValuesStep2);
document.addEventListener('check-step-3', checkValuesStep3);
document.addEventListener('check-step-4', checkValuesStep4);
document.addEventListener('check-step-5', checkValuesStep5);
document.addEventListener('check-step-6', checkValuesStep6);
document.addEventListener('before-form-submit', function (event){
const { body, errors }=checkValues();
if(errors.length > 0){
alert(errors.join('\n'));
return;
}
const wpcf7submit=new CustomEvent('wpcf7submit', {
detail: {
contactFormId: '9886',
body: body
}});
document.dispatchEvent(wpcf7submit);
});
function goToNextStep(stepToGo, stepNumber=6){
if(stepToGo < stepNumber){
updateStepVisibility(stepToGo);
}}
function goToPreviousStep(currentStep){
if(currentStep > 1){
updateStepVisibility(currentStep - 1);
}}
function updateStepVisibility(stepToDisplay){
const stepList=document.querySelectorAll(".step");
stepList.forEach((step, index)=> {
if(index===stepToDisplay){
step.style.display='';
let stepIndicators=document.querySelectorAll(".stepIndicator");
for (let i=0; i < stepIndicators.length; i++){
stepIndicators[i].classList.remove("active");
}
let currentStepIndicator=document.getElementsByClassName("stepIndicator" + (index + 1))[0];
let lastStepIndicator=document.getElementsByClassName("stepIndicator5")[0];
if((index + 1) > 5){
lastStepIndicator.classList.add("active");
}
else if(currentStepIndicator){
currentStepIndicator.classList.add("active");
}}else{
step.style.display='none';
}});
}
function checkValuesStep1(){
const errors=[];
const documentNumber=parseInt(document.querySelector('input[name="numero-documenti"]').value);
if(isNaN(documentNumber)){
errors.push('Numero documenti non valido');
}
if(documentNumber < 1){
errors.push('Numero documenti non può essere negativo');
}
const percentagePrintedDocument=parseFloat(document.querySelector('input[name="percentuale-documenti-stampati"]').value);
if(isNaN(percentagePrintedDocument)){
errors.push('Percentuale documenti stampati non valida');
}
if(percentagePrintedDocument < 0||percentagePrintedDocument > 100){
errors.push('Percentuale documenti stampati non può essere negativa o superiore a 100');
}
const printedDocumentNumber=parseInt(document.querySelector('input[name="numero-totale-stampe"]').value);
if(isNaN(printedDocumentNumber)){
errors.push('Numero totale stampe non valido');
}
if(printedDocumentNumber < 1){
errors.push('Numero totale stampe non può essere negativo');
}
if(errors.length > 0){
document.getElementById('errorSection1').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection1').innerHTML='';
goToNextStep(1);
}}
function checkValuesStep2(){
const errors=[];
const averageHourlyPersonCost=parseFloat(document.querySelector('input[name="costo-persona-staff"]').value);
if(isNaN(averageHourlyPersonCost)){
errors.push('Costo medio staff non valido');
}
if(averageHourlyPersonCost < 0){
errors.push('Costo medio staff non può essere negativo');
}
const averageDocumentHandlingMinutes=parseInt(document.querySelector('input[name="tempo-medio-gestione-documento"]').value);
if(isNaN(averageDocumentHandlingMinutes)){
errors.push('Tempo medio gestione documento non valido');
}
if(averageDocumentHandlingMinutes < 1){
errors.push('Tempo medio gestione documento non può essere negativo');
}
if(errors.length > 0){
document.getElementById('errorSection2').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection2').innerHTML='';
goToNextStep(2);
}}
function checkValuesStep3(){
const errors=[];
const averageManualDocumentHandlingCost=parseFloat(document.querySelector('input[name="costo-medio-gestione-manuale"]').value);
if(isNaN(averageManualDocumentHandlingCost)){
errors.push('Costo medio gestione manuale non valido');
}
if(averageManualDocumentHandlingCost < 0){
errors.push('Costo medio gestione manuale non può essere negativo');
}
if(errors.length > 0){
document.getElementById('errorSection3').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection3').innerHTML='';
goToNextStep(3);
}}
function checkValuesStep4(){
const errors=[];
const averagePrintingCost=parseFloat(document.querySelector('input[name="costo-medio-stampa-documento"]').value);
if(isNaN(averagePrintingCost)){
errors.push('Costo medio stampa documento non valido');
}
if(averagePrintingCost < 0){
errors.push('Costo medio stampa documento non può essere negativo');
}
const printingCostReduction=parseFloat(document.querySelector('input[name="percentuale-riduzione-costi-stampa"]').value);
if(isNaN(printingCostReduction)){
errors.push('Percentuale riduzione costi stampa non valida');
}
if(printingCostReduction < 0||printingCostReduction > 100){
errors.push('Percentuale riduzione costi stampa non può essere negativa o superiore a 100');
}
if(errors.length > 0){
document.getElementById('errorSection4').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection4').innerHTML='';
goToNextStep(4);
}}
function checkValuesStep5(){
const errors=[];
const timeSavingsEfficiencyGain=parseFloat(document.querySelector('input[name="percentuale-risparmio-tempo"]').value);
if(isNaN(timeSavingsEfficiencyGain)){
errors.push('Percentuale risparmio tempo non valida');
}
if(timeSavingsEfficiencyGain < 0||timeSavingsEfficiencyGain > 100){
errors.push('Percentuale risparmio tempo non può essere negativa o superiore a 100');
}
if(errors.length > 0){
document.getElementById('errorSection5').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection5').innerHTML='';
goToNextStep(5);
}}
function checkValuesStep6(){
const errors=[];
const emailRegex=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const email=document.querySelector('input[name="email"]').value;
if(email===""||!emailRegex.test(email)){
errors.push('Email non valida');
}
if(errors.length > 0){
document.getElementById('errorSection6').innerHTML=errors.join('<br>');
}else{
document.getElementById('errorSection6').innerHTML='';
}}
function checkValues(){
const body={}
const errors=[];
const documentNumber=parseInt(document.querySelector('input[name="numero-documenti"]').value);
if(isNaN(documentNumber)){
errors.push('Numero documenti non valido');
}
if(documentNumber < 1){
errors.push('Numero documenti non può essere negativo');
}
body.managedDocuments=documentNumber;
const percentagePrintedDocument=parseFloat(document.querySelector('input[name="percentuale-documenti-stampati"]').value);
if(isNaN(percentagePrintedDocument)){
errors.push('Percentuale documenti stampati non valida');
}
if(percentagePrintedDocument < 0||percentagePrintedDocument > 100){
errors.push('Percentuale documenti stampati non può essere negativa o superiore a 100');
}
const printedDocumentNumber=parseInt(document.querySelector('input[name="numero-totale-stampe"]').value);
if(isNaN(printedDocumentNumber)){
errors.push('Numero totale stampe non valido');
}
if(printedDocumentNumber < 1){
errors.push('Numero totale stampe non può essere negativo');
}
body.printedDocuments=printedDocumentNumber;
const averageHourlyPersonCost=parseFloat(document.querySelector('input[name="costo-persona-staff"]').value);
if(isNaN(averageHourlyPersonCost)){
errors.push('Costo medio staff non valido');
}
if(averageHourlyPersonCost < 0){
errors.push('Costo medio staff non può essere negativo');
}
body.averageHourlyPersonCost=averageHourlyPersonCost;
const averageDocumentHandlingMinutes=parseInt(document.querySelector('input[name="tempo-medio-gestione-documento"]').value);
if(isNaN(averageDocumentHandlingMinutes)){
errors.push('Tempo medio gestione documento non valido');
}
if(averageDocumentHandlingMinutes < 0){
errors.push('Tempo medio gestione documento non può essere negativo');
}
body.averageDocumentHandlingMinutes=averageDocumentHandlingMinutes;
const averageManualDocumentHandlingCost=parseFloat(document.querySelector('input[name="costo-medio-gestione-manuale"]').value);
if(isNaN(averageManualDocumentHandlingCost)){
errors.push('Costo medio gestione manuale non valido');
}
if(averageManualDocumentHandlingCost < 0){
errors.push('Costo medio gestione manuale non può essere negativo');
}
body.averageManualDocumentHandlingCost=averageManualDocumentHandlingCost;
const averagePrintingCost=parseFloat(document.querySelector('input[name="costo-medio-stampa-documento"]').value);
if(isNaN(averagePrintingCost)){
errors.push('Costo medio stampa documento non valido');
}
if(averagePrintingCost < 0){
errors.push('Costo medio stampa documento non può essere negativo');
}
body.averagePrintingCost=averagePrintingCost;
const printingCostReduction=parseFloat(document.querySelector('input[name="percentuale-riduzione-costi-stampa"]').value);
if(isNaN(printingCostReduction)){
errors.push('Percentuale riduzione costi stampa non valida');
}
if(printingCostReduction < 0||printingCostReduction > 100){
errors.push('Percentuale riduzione costi stampa non può essere negativa o superiore a 100');
}
body.printingCostReduction=printingCostReduction / 100;
const timeSavingsEfficiencyGain=parseFloat(document.querySelector('input[name="percentuale-risparmio-tempo"]').value);
if(isNaN(timeSavingsEfficiencyGain)){
errors.push('Percentuale risparmio tempo non valida');
}
if(timeSavingsEfficiencyGain < 0||timeSavingsEfficiencyGain > 100){
errors.push('Percentuale risparmio tempo non può essere negativa o superiore a 100');
}
body.timeSavingsEfficiencyGain=timeSavingsEfficiencyGain / 100;
const emailRegex=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const email=document.querySelector('input[name="email"]').value;
if(email===""||!emailRegex.test(email)){
errors.push('Email non valida');
}
body.email=email;
return {
body: body,
errors: errors
}}
document.addEventListener('wpcf7submit', function (event){
if(event.detail.contactFormId=='9886'){
const endpoint="https://www.gruppodr.it/wp-json/custom-api/data";
const headers={
'Content-Type': 'application/json'
};
const body=event.detail.body;
console.log(body);
fetch(endpoint, {
method: 'POST',
headers: headers,
body: JSON.stringify(body)
}).then(response=> {
if(response.ok){
alert('Richiesta inviata con successo');
}}).catch(error=> {
console.error(error);
alert('Errore durante l\'invio della richiesta');
});
}}, false);
document.addEventListener('DOMContentLoaded', function (){
const roiForm=document.getElementById('roi-form');
if(!roiForm){
console.log('ROI Form non trovato');
return;
}
const documentNumberElement=roiForm.querySelector('input[name="numero-documenti"]');
const percentagePrintedDocumentElement=roiForm.querySelector('input[name="percentuale-documenti-stampati"]');
const printedDocumentNumberElement=roiForm.querySelector('input[name="numero-totale-stampe"]');
function calculateValuesManagerDocument(event){
if(percentagePrintedDocumentElement.value===""){
documentNumberElement.value="";
printedDocumentNumberElement.value="";
documentNumberElement.disabled=false;
printedDocumentNumberElement.disabled=false;
return;
}
if(documentNumberElement.value===""){
printedDocumentNumberElement.value="";
printedDocumentNumberElement.disabled=false;
return;
}
const documentNumber=parseInt(documentNumberElement.value);
const percentagePrintedDocument=parseFloat(percentagePrintedDocumentElement.value) / 100;
printedDocumentNumberElement.value=Math.ceil(documentNumber * percentagePrintedDocument);
printedDocumentNumberElement.disabled=true;
return;
}
function calculateValuesManagerPrintedDocument(event){
if(percentagePrintedDocumentElement.value===""){
documentNumberElement.value="";
printedDocumentNumberElement.value="";
documentNumberElement.disabled=false;
printedDocumentNumberElement.disabled=false;
return;
}
if(printedDocumentNumberElement.value===""){
documentNumberElement.value="";
documentNumberElement.disabled=false;
return;
}
const percentagePrintedDocument=parseFloat(percentagePrintedDocumentElement.value) / 100;
const printedDocumentNumber=parseInt(printedDocumentNumberElement.value);
documentNumberElement.value=Math.ceil(printedDocumentNumber / percentagePrintedDocument);
documentNumberElement.disabled=true;
return;
}
function calculateValuerManagerPercentage(event){
if(percentagePrintedDocumentElement.value===""){
documentNumberElement.value="";
printedDocumentNumberElement.value="";
documentNumberElement.disabled=false;
printedDocumentNumberElement.disabled=false;
return;
}
const documentNumber=parseInt(documentNumberElement.value);
const percentagePrintedDocument=parseFloat(percentagePrintedDocumentElement.value) / 100;
if(documentNumberElement.value!==""&&printedDocumentNumberElement.value!==""){
printedDocumentNumberElement.value=Math.ceil(documentNumber * percentagePrintedDocument);
return;
}}
documentNumberElement.addEventListener('input', calculateValuesManagerDocument);
printedDocumentNumberElement.addEventListener('input', calculateValuesManagerPrintedDocument);
percentagePrintedDocumentElement.addEventListener('input', calculateValuerManagerPercentage);
});