/*
	Script: richiesta.js
	Applicazione: Meinardi
	Versione: 1.01
	Data: 21/10/2009
	Scopo: Controlli di validazione del form di iscrizione alla newsletter
*/
$('document').ready(function() {
	$('form#newsletter').submit(function() {
		$('#submit-message').remove();
		intErrors = 0;
		strMsg = '';
		$('input.obbl').each(function() {
			var strTitle = $(this).attr('title');
			if (this.value == strTitle) {
				$(this).addClass('error');
				strMsg += '<li>Il campo ' + strTitle + ' &egrave; obbligatorio</li>';
				intErrors++;
			}
		});
		if (intErrors > 0) {
			$('<div id="submit-message">Per favore correggi gli errori seguenti:<ul>' 
			+ strMsg + '</ul></div>').insertBefore('#invia');
			return false;
		}
		else {
			$('input[title]').each(function() {
				var strTitle = $(this).attr('title');
				if (this.value == strTitle)
					this.value = '';
			});
		}
	});
});
