!function(){"use strict";function l(i,u){for(var f=new exprEval.Parser,e=0;e<u.length;e++){var a=function(e){for(var a={},t=0;t<e.elements.length;t++){var l,r,n,o=e.elements[t];o.name&&!o.disabled&&"button"!=o.type&&"file"!=o.type&&"reset"!=o.type&&"submit"!=o.type&&-1!=o.name.indexOf("cf[")&&((l=o.closest(".cf-control-group"))&&(r=o.dataset.calcValue||o.value,"checkbox"!=o.type&&"radio"!=o.type||(r=o.checked?o.dataset.calcValue:0),"select-one"==o.type&&(r=o.options[o.selectedIndex].dataset.calcValue),o=l.dataset.key,r=parseFloat(r),r=isNaN(r)?0:r,a.hasOwnProperty(o)&&(n=a[o].field_value,r+=n),a[o]={field_value:r,field_name:l.dataset.name}))}return a}(i),t=u[e],p={};if(n=t.dataset.calc){for(var l=0,v=Object.entries(a);l<v.length;l++){var r=v[l],m=r[0],r=r[1],y=new RegExp("{field."+r.field_name+"}","gi"),n=n.replace(y,"{field"+m+"}");p["field"+m]=r.field_value}n=(n=n.replace(/{/g,"")).replace(/}/g,"");var o,c,s,g,d,a=void 0;try{a=f.evaluate(n,p)}catch(e){console.error("Convert Forms failed to evalute calculation formula:",n,"- Make sure you're usign the correct syntax: {field.FIELDNAME}")}isNaN(a)||(o=t.dataset.thousand_separator||null,c=t.dataset.decimal_separator||null,d=t.dataset.precision||2,s=t.dataset.prefix||null,g=t.dataset.suffix||null,a=parseFloat(a).toFixed(d),d=a=c&&"."!=c?a.replace(".",c):a,o&&(d=d.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o)),s&&(d=s+d),g&&(d+=g),"INPUT"===t.nodeName?(ConvertForms.Helper.setValue(t,d),t.dataset.calcValue=a):t.innerHTML=d)}}}ConvertForms.Helper.onReady(function(e){e.forEach(function(e){var a=e.querySelector("form"),t=a.querySelectorAll("*[data-calc]");0<t.length&&(a.addEventListener("input",function(){l(a,t)}),a.addEventListener("change",function(e){l(a,t)}),e.addEventListener("beforeSubmit",function(){l(a,t)}),l(a,t))})})}(document);

