(function( $ ) {
	"use strict";
	$(function() {
		var $loading = '
' + 
					   ' ';
		if( $( "#form-contatti" ).length ) {
			var $contactForm = $( "#form-contatti" );
			$contactForm.on( "submit", function( e ) {
				e.preventDefault();
				$contactForm.after( $loading );
				if( $( "#validation-output" ).length ) {
					$( "#validation-output" ).remove();
				}
				var url = hotelmarteform.ajaxurl;
				var data = "action=hotelmarteform_send&" + $contactForm.serialize();
				$.post( url, data, function( output ){
					$contactForm.after( output );
				}).done( function(){
					$( ".loading" ).remove();
					/* mc stuff */
					// if( $( '#mc' ).is(':checked') ) {
					// 	var $fname = $contactForm.find( 'input[type=text]' ).val();
					// 	var $email = $contactForm.find( 'input[type=email]' ).val();
					// 	var $lang  = hotelmarteform.currlang;
					// 	$.ajax({
					// 		url: hotelmarteform.themepath + '/inc/mc-API-connector.php',
					// 		type: 'POST',
					// 		data: {
					// 			fname: $fname,
					// 			email: $email,
					// 			lang: $lang
					// 		},
					// 		success: function (data) {
					// 			$('#mc-result').html(data);
					// 		},
					// 		error: function (xhr, status, error) {
					// 			console.log(xhr.responseText);
					// 		}
					// 	});
					// }
				});
			});
		}
		if( $( "#form-newsletter" ).length ) {
			var $newsletterForm = $( "#form-newsletter" );
			$newsletterForm.on( "submit", function( e ) {
				e.preventDefault();
				$newsletterForm.after( $loading );
				if( $( "#validation-output" ).length ) {
					$( "#validation-output" ).remove();
				}
				var url = hotelmarteform.ajaxurl;
				var data = "action=hotelmarteform_send&" + $newsletterForm.serialize();
				$.post( url, data, function( output ){
					$newsletterForm.after( output );
				}).done( function(){
					$( ".loading" ).remove();
					/* mc stuff */
					if( $( '#privacy-check' ).is(':checked') ) {
					
						// var $fname = $newsletterForm.find( 'input[type=text]' ).val();
						var $email = $newsletterForm.find( 'input[type=email]' ).val();
						var $lang  = hotelmarteform.currlang;
					
						$.ajax({
							url: hotelmarteform.themepath + '/inc/mc-API-connector.php',
							type: 'POST',
							data: {
								fname: $email,
								email: $email,
								lang: $lang
							},
							success: function (data) {
								$('#mc-result').html(data);
							},
							error: function (xhr, status, error) {
								console.log(xhr.responseText);
							}
						});
					}
					
				});
			});
		}
	});
})( jQuery );
';
		if( $( "#form-contatti" ).length ) {
			var $contactForm = $( "#form-contatti" );
			$contactForm.on( "submit", function( e ) {
				e.preventDefault();
				$contactForm.after( $loading );
				if( $( "#validation-output" ).length ) {
					$( "#validation-output" ).remove();
				}
				var url = hotelmarteform.ajaxurl;
				var data = "action=hotelmarteform_send&" + $contactForm.serialize();
				$.post( url, data, function( output ){
					$contactForm.after( output );
				}).done( function(){
					$( ".loading" ).remove();
					/* mc stuff */
					// if( $( '#mc' ).is(':checked') ) {
					// 	var $fname = $contactForm.find( 'input[type=text]' ).val();
					// 	var $email = $contactForm.find( 'input[type=email]' ).val();
					// 	var $lang  = hotelmarteform.currlang;
					// 	$.ajax({
					// 		url: hotelmarteform.themepath + '/inc/mc-API-connector.php',
					// 		type: 'POST',
					// 		data: {
					// 			fname: $fname,
					// 			email: $email,
					// 			lang: $lang
					// 		},
					// 		success: function (data) {
					// 			$('#mc-result').html(data);
					// 		},
					// 		error: function (xhr, status, error) {
					// 			console.log(xhr.responseText);
					// 		}
					// 	});
					// }
				});
			});
		}
		if( $( "#form-newsletter" ).length ) {
			var $newsletterForm = $( "#form-newsletter" );
			$newsletterForm.on( "submit", function( e ) {
				e.preventDefault();
				$newsletterForm.after( $loading );
				if( $( "#validation-output" ).length ) {
					$( "#validation-output" ).remove();
				}
				var url = hotelmarteform.ajaxurl;
				var data = "action=hotelmarteform_send&" + $newsletterForm.serialize();
				$.post( url, data, function( output ){
					$newsletterForm.after( output );
				}).done( function(){
					$( ".loading" ).remove();
					/* mc stuff */
					if( $( '#privacy-check' ).is(':checked') ) {
					
						// var $fname = $newsletterForm.find( 'input[type=text]' ).val();
						var $email = $newsletterForm.find( 'input[type=email]' ).val();
						var $lang  = hotelmarteform.currlang;
					
						$.ajax({
							url: hotelmarteform.themepath + '/inc/mc-API-connector.php',
							type: 'POST',
							data: {
								fname: $email,
								email: $email,
								lang: $lang
							},
							success: function (data) {
								$('#mc-result').html(data);
							},
							error: function (xhr, status, error) {
								console.log(xhr.responseText);
							}
						});
					}
					
				});
			});
		}
	});
})( jQuery );