(function () {
	function clearFields(form) {
		if (!form) {
			return;
		}
		form.querySelectorAll('.wpps-simple-captcha-wrap').forEach(function (wrap) {
			var key = wrap.querySelector('input[name="wpps_simple_captcha_key"]');
			var ans = wrap.querySelector('input[name="wpps_simple_captcha_answer"]');
			if (key) {
				key.value = '';
			}
			if (ans) {
				ans.value = '';
			}
		});
	}

	document.addEventListener('DOMContentLoaded', function () {
		document.body.addEventListener('click', function (e) {
			var t = e.target;
			if (!t || !t.matches) {
				return;
			}
			if (t.matches('.comment-reply-link, #cancel-comment-reply-link')) {
				var form = document.getElementById('commentform');
				clearFields(form);
			}
		});
	});
})();
