$(function() { $("#frmContacts").submit( function() { if( fCheckObbligatori() ) 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("Acceptance required."); } 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(); $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); var data; var strDestination = ''; 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; if ( data.status == 'ok' ) blnSaved = true; else alert("Data logging failed"); }, error: function(data) { alert("Procedura non completata."); } }); if ( blnSaved ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } } // Controllo campi obbligatori function fCheckObbligatori() { var blnReturn = true; $('.required').each(function() { if ( $.trim( $(this).val() ) == "" ) { blnReturn = false; $( "#lbl" + $(this).attr("name") ).html( fHTMLErrore( "Required field" ) ); } else $( "#lbl" + $(this).attr("name") ).html(""); }); // Controllo privacy if( ! $('#privacy').attr('checked') ) { blnReturn = false; $('#lblprivacy').html( fHTMLErrore( "Acceptance required." ) ); } else $('#lblprivacy').html(""); // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#lbltxtEmail').html( '' ); var intErrore = ''; $.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; if ( intErrore == 1 ) { // ERRORE : email NON corretta blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "The address is not correct." ) ); } else if ( intErrore == 2 ) { // ERRORE : email NON esiste blnReturn = false; $('#lbltxtEmail').html( fHTMLErrore( "The address does not exists" ) ); } else { // OK : email corretta $('#lbltxtEmail').html(''); // OK : Email unica e corretta } if ( data.status == 'errore' ) blnSaved = false; else if ( data.status == 'ok' ) blnSaved = true; else alert("Verification failed"); }, error: function(data) { alert("Procedura non completata."); } }); } if ( ! blnReturn ) { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); } return blnReturn; } function fHTMLErrore( pstr ) { return '
' + pstr + '
'; }