(function(){"use strict";var e=document.querySelectorAll(".mailster-ajax-form");Array.prototype.forEach.call(e,function(a,e){a.addEventListener("submit",function(e){e.preventDefault();var t=o(a),r,s=a.querySelector(".mailster-form-info");if(!s){s=document.createElement("div");s.classList.add("mailster-form-info")}if("function"===typeof window.mailster_pre_submit){r=window.mailster_pre_submit.call(this,t);if(r===false)return false;if(typeof r!=="undefined")t=r}a.classList.add("loading");a.setAttribute("disabled",true);fetch(a.getAttribute("action"),{method:"POST",headers:{"x-requested-with":"XMLHttpRequest","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},body:t}).then(function(e){if(e.ok){return e.json()}return Promise.reject(e)}).then(i).catch(function(e){var t;try{t=JSON.parse(e);if(!t.data.html){t={data:{html:"There was an error with the response:<br><code>["+t.data.code+"] "+t.data.message+"</code>"},success:false}}}catch(e){t={data:{html:"There was an error while parsing the response:<br><code>"+e+"</code>"},success:false}}i(t)});function i(e){a.classList.remove("loading");a.classList.remove("has-errors");a.removeAttribute("disabled");a.querySelector(".submit-button").removeAttribute("disabled");[].forEach.call(document.querySelectorAll("div.mailster-wrapper"),function(e){e.classList.remove("error")});s.remove();s.classList.remove("error");s.classList.remove("success");if("function"===typeof window.mailster_post_submit){r=window.mailster_post_submit.call(a[0],e);if(r===false)return false;if(typeof r!=="undefined")e=r}if(e.data.html){s.innerHTML=e.data.html}if((window.pageYOffset||document.documentElement.scrollTop)<a.getBoundingClientRect().top){a.insertBefore(s,a.firstChild)}else{a.insertBefore(s,a.lastChild)}if(e.success){setTimeout(function(){s.classList.add("success")},0);if(e.data.redirect){window.location.href=e.data.redirect;return}if(!a.classList.contains("is-profile")){a.classList.add("completed");a.reset()}}else{if(e.data.fields){a.classList.add("has-errors");Object.keys(e.data.fields).forEach(function(e){var t=a.querySelector(".mailster-"+e+"-wrapper");t&&t.classList.add("error")})}setTimeout(function(){s.classList.add("error")},0)}}})});function o(e){var t={};var r=new FormData(e);for(var s of r.keys()){t[s]=r.getAll(s).slice(-1)[0]}return Object.keys(t).map(function(e){return encodeURIComponent(e)+"="+encodeURIComponent(t[e])}).join("&")}})();