$(function() { //fCheckObbligatori( 1 ); $("#frmContacts").submit( function() { if( fCheckObbligatori(1) ) fSaveData(); return false; }); // Evidenzia privacy $('#showprivacy').click(function() { if ( $('#box_privacy').hasClass('fprivacy') ) $('#box_privacy').hide().removeClass('fprivacy').addClass('fprivacyon').fadeIn('slow'); else $('#box_privacy').hide().removeClass('fprivacyon').addClass('fprivacy').fadeIn('slow'); if( ! $('#privacy').attr('checked') ) { blnReturn = false; $('#lblPrivacy').html("Accettazione obbligatoria."); } else $('#lblPrivacy').html(''); }); $(document).bind('keydown', 'Ctrl+n', function() { $('#frmContacts textarea').lorem({ type: 'paragraphs',amount:'4',ptags:false}); $('#frmContacts input[type=checkbox]').attr('checked',true); $('#txtNominativo').val('Lorem Ipsum'); $('#txtCitta').val('Lorem ipsum dolor sit amet'); $('#txtTelefono').val('+39 000 00000000'); $('#txtEmail').val('info@dynform.it'); //fCheckObbligatori( 1 ); }); $(document).bind('keydown', 'Ctrl+k', function() { $('#frmContacts input[type!=submit]').val(''); $('#frmContacts textarea').html(''); $('#frmContacts input[type=checkbox]').attr('checked',false); //fCheckObbligatori( 1 ); }); $('#txtNominativo').focus(); }); function fSaveData() { $('submit').focus(); // focus sul submit in modo da lanciare onchange sui vari campi fLoading(1); var strID = ''; var strTmp = ''; var data; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/sendContatti.php", data: $("#frmContacts").serialize(), success: function(data) { strDestination = data.destination; strTmp = data.status; if ( data.status == 'ok' ) blnSaved = true; else alert("Registrazione dati non riuscita"); }, error: function(data){ alert("errore: " + data); } }); if ( blnSaved ) { location.href = strDestination; } else fLoading(0); } //Controllo campi obbligatori function fCheckObbligatori( pintHideAlert ) { var blnReturn = true; var intHideAlert = ( pintHideAlert > 0 ? 1 : 0 ); var strAlert = "Verifica i seguenti campi: \n\n"; $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html("Campo obbligatorio"); strAlert += '- ' + $( "#lbl" + $(this).attr("name") ).attr("title") + ' \n'; } else $( "#lbl" + $(this).attr("name") ).html(""); }); // Controllo privacy if( ! $('#privacy').attr('checked') ) { blnReturn = false; $('#lblprivacy').html("Accettazione obbligatoria."); strAlert += "- Privacy - Accettazione obbligatoria. \n"; } else $('#lblprivacy').html(''); // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#lbltxtEmail').removeClass("conferma").removeClass("errore").html(''); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkEmail.php", data: "action=checkEmail&pstrEmail=" + $("#txtEmail").val(), success: function(data) { intErrore = data.errore; strTmp = data.status; if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').removeClass('conferma').addClass('errore').html("L'indirizzo non è corretto."); strAlert += "- Email non corretta \n"; } else if ( intErrore == 2 ) { // ERRORE : email NON esiste blnReturn = false; $('#lbltxtEmail').removeClass('conferma').addClass('errore').html("L'indirizzo non esiste"); strAlert += "- Email non esiste \n"; } else { // OK : email corretta $('#lbltxtEmail').removeClass('errore').addClass('conferma').html("L'indirizzo sembra corretto. Ok."); // OK : Email unica e corretta } if ( data.status == 'errore' ) blnSaved = false; else if ( data.status == 'ok' ) blnSaved = true; else alert("Verifica non riuscita"); }, error: function(data){ alert("errore: " + data); } }); } if ( ! blnReturn ) { $('#submitLoad').hide(); $('#submitResult').show(); $("html,body").animate({scrollTop: 0}, 1500, "bounceout"); if ( ! intHideAlert ) alert( strAlert ); } return blnReturn; }