$(document).ready(function() {
	$(document).on("submit",".js-form-questions-emitent", function (e) {
		e.preventDefault();
		var form = $(this);
		var data = new FormData(form[0]);
		if (form[0].checkValidity()) {
			$(form).find('input').prop("disabled", true);
			$(form).find('button').prop("disabled", true);
			$(form).find('.js-message').html('').removeClass('error');
			$.ajax({
				url: form.attr('action'),
				type: 'POST',
				data: data,
				async: false,
				success: function (data) {
					// console.log(data);
					$(form).find('input').prop("disabled", false);
					$(form).find('button').prop("disabled", false);
					if (data['result'] === 'success') {
						if (typeof data['message'] !== "undefined") {
                            $(form).find('.js-message').html(data['message']).removeClass('error');
                        }
                        ym(98066448,'reachGoal','questions_emitent_form');
						if (typeof data['redirectURL'] !== "undefined") {
                            window.location.href = data['redirectURL'];
                        }
					} else {
						if (typeof data['message'] !== "undefined") {
                            $(form).find('.js-message').html(data['message']).addClass('error');
                        }
					}
				},
				cache: false,
				contentType: false,
				processData: false
			});
		}
	});
});