$(document).ready(function(){
var okNome = 0;
var okMail = 0;
var regex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
$("#closecontact img").hover(function(){this.src = this.src.replace("_normal","_over");}, function(){this.src = this.src.replace("_over","_normal");});
$("#field_nome").mouseup(function(e){e.preventDefault();});
$("#field_nome").blur(
function checkNome()
{
//alert($("#field_nome").val());
if(jQuery.trim($("#field_nome").val())=="")
{
//myFocus('field_nome');
alertUser('alert', 'Attenzione
compilare il campo Nominativo.');
$("#check_nome").attr("src", "img/check_ko.png");
okNome = 0;
return false;
}
else
{
//alertUser('noalert', 'Compilare i campi contrassegnati con * con le informazioni richieste.');
$("#check_nome").attr("src", "img/check_ok.png");
okNome = 1;
return true;
}
}
);
$("#field_mail").blur(
function checkMail()
{
//alert($("#field_mail").val());
if(jQuery.trim($("#field_mail").val())=="" || !regex.test($("#field_mail").val()))
{
//$("#field_mail").focus();
alertUser('alert', 'Attenzione
compilare il campo E-mail.');
$("#check_mail").attr("src", "img/check_ko.png");
okMail = 0;
return false;
}
else
{
//alertUser('noalert', 'Compilare i campi contrassegnati con * con le informazioni richieste.');
$("#check_mail").attr("src", "img/check_ok.png");
okMail = 1;
return true;
}
}
);
$("#form").submit(
function validate()
{
//alert(document.form.consenso[0].checked);
//alert(okNome+" "+okMail);
if(okNome && okMail)
{
if(document.form.consenso[0].checked==true)
{
//alert(okNome+" "+okMail);
$.post("postContact.php", { nome:$("#field_nome").serialize(), mail:$("#field_mail").serialize(), info:$("#field_info").serialize(), lang:"it" },
function(data)
{
//alert("Data Loaded: " + data);
if(data.indexOf("OK")>-1)
{
clearFieldsContact();
alertUser('mailok', 'Richiesta di informazioni inoltrata con successo.');
setTimeout(function(){shadeOut('shadecontact');}, 2500);
}
else
{
alertUser('mailko', 'Errore durante l\'invio mail. Prego riprovare in seguito.');
//setTimeout(function(){shadeOut('shadecontact');}, 2000);
}
}
);
}
else
{
alertUser('alert', 'Attenzione
il consenso al trattamento dei dati personali è obbligatorio per la richiesta di informazioni.');
return false;
}
}
return false;
}
);
function alertUser(img, frase)
{
$("#feedimg").attr("src", "img/"+img+".png");
$("#feedtext").html(frase);
}
function myFocus(what)
{
alert("no");
var el = document.getElementById(what);
el.select();
el.focus();
}
});
function clearFieldsContact()
{
$("#field_nome").focus();
$("#field_nome").val("");
$("#check_nome").attr("src", "img/check_meh.png");
$("#field_mail").val("");
$("#check_mail").attr("src", "img/check_meh.png");
$("#field_info").val("");
$('input[name="consenso"]')[1].checked = true;
$("#feedimg").attr("src", "img/noalert.png");
$("#feedtext").html('Compilare i campi contrassegnati con * con le informazioni richieste.');
}