function showStatus(error, message) {
	$('#status_bar').removeClass();
	$('#status_bar').addClass(error ? 'txt_Error' : 'txt_Info');
	$('#status_bar').html(message);
	$('#status_bar').show();
}
function hideStatus() {
	$('#status_bar').hide();
}

function showError(where, message) {
	var elementID = '#error_' + where;
	$(elementID).html(message);
	$(elementID).show();
	$('input[name="'+where+'"]').addClass('errorInput');
	$(window).scrollTop(320);
}
function hideError(where) {
	var elementID = '#error_' + where;
	$(elementID).hide();
	$('input[name="'+where+'"]').removeClass('errorInput');
}

function SubmitForm() {
	hideStatus();

	if ($('input[name="nome"]').val() == '') {
		showError('nome', 'Campo "Nome" non valorizzato');
		return;
	} else {
		hideError('nome');
	}
	
	if ($('input[name="mail"]').val() == '') {
		showError('mail', 'Campo "eMail" non valorizzato');
		return;
	} else if (!emailCheck($('input[name="mail"]').val())) {
		showError('mail', "L'email inserita non \u00E8 un'email corretta");
		return;
	} else {
		hideError('mail');
	}
	
	if ($('input:radio[name="destinatario"]:checked').length==0) {
		showError('destinatario', 'Scegliere il destinatario del messaggio');
		return;
	} else {
		hideError('destinatario');
	}
	
	if (($('textarea[name="corpo"]').val()) == '') {
		showError('corpo', 'Inserire il testo del messaggio');
		return;
	} else {
		hideError('corpo');
	}
	
	var params = $('#mailForm').serialize();
	$('#mailForm').attr("disabled","disabled");
	showStatus(false, "Invio del messaggio in corso");
	
	$.ajax({
		type: 'POST',
		url: '/dinamiche/SendEmailTS',
		data: params,
		success: function(){
			showStatus(false, "Messaggio inviato correttamente");
		},
		fail: function() {
			howStatus(true, "Purtroppo di &egrave; verificato un errore di invio.");
		}
	});
}

