// ====================================================================
//                      FUNZIONI DI VALIDAZIONE FORM
//                  copyright Antares di Sbrana Saverio
// ====================================================================

function checkFormContatti(elemento)
{	
	if(conSeVuoto(elemento.nome))
	{
		erroreMsg("Inserire il nome",elemento.nome)
		return false;
	}
	if(conSeVuoto(elemento.cognome))
	{
		erroreMsg("Inserire il cognome",elemento.cognome)
		return false;
	}
	if(conSeVuoto(elemento.sesso))
	{
		erroreMsg("Inserire il sesso",elemento.sesso)
		return false;
	}
	if(conSeVuoto(elemento.dataDiNascita))
	{
		erroreMsg("Inserire la data di nascita",elemento.dataDiNascita)
		return false;
	}
	if(conSeVuoto(elemento.email))
	{
		erroreMsg("Inserire l'email",elemento.email)
		return false;
	}
	if(conEmail(elemento.email))
	{
		erroreMsg("Inserire l'email correttamente",elemento.email)
		return false;
	}
	if(conSeVuoto(elemento.messaggio))
	{
		erroreMsg("Inserire il messaggio",elemento.messaggio)
		return false;
	}
	if(elemento.privacy[2].checked)
	{
		erroreMsg("E' necessario accettare la legge sulla privacy",elemento.privacy[1])
		return false;
	}	
	inviaEmail();
	return false;
}

function inviaEmail()
{
	url = 'script/contact.js.php';
	
	variabili = 'nome=' + document.contatti.nome.value + '&cognome=' + document.contatti.cognome.value ;
	variabili += '&dataDiNascita=' + document.contatti.dataDiNascita.value + '&sesso=' + document.contatti.sesso.value ;
	variabili += '&email=' + document.contatti.email.value + '&messaggio=' + document.contatti.messaggio.value ;
	
	new Ajax.Request(url,{method:'post', postBody:variabili , onSuccess: function(transport)
	{
		var risposta = '';
		if (transport.responseText != "errore" && transport.responseText == "ok")
		{
			ShowTip(this, "<b>Invio eseguito con successo</b>:<br/> Email inviata correttamente.",true);
		}
		else
			ShowTip(this, "<b>Errore</b>:<br/> Email <b>NON</b> inviata!<br/>Riprovare pił tardi."+transport.responseText,true);
		
	}
	, onUninitialized: function(transport)
	{
		ShowTip(this,"Caricamento in corso.",false);
	}				
	, onLoading: function(transport)
	{
		ShowTip(this,"Caricamento in corso..",false);
	}		
	
	} );
}
