$( function() { //fCheckObbligatori( 1 ); $("form").submit( function() { fLoading(1); if( fCheckObbligatori() ) fSaveData(); else fLoading(0); return false; }); // Mostra domanda $('.showdomanda').click(function() { var campo = $(this).attr('id').substr(12); $('#box_'+campo).hide(); $('#boxlista_'+campo).show(); }); // Mostra lista domande $('.listadomande').change(function() { var campo = $(this).attr('id').substr(13); $('#'+campo).val( $(this).val() ); $('#boxlista_'+campo).hide(); $('#lbl'+campo).html(''); $('#box_'+campo).show(); $('#'+campo).focus(); }); // Controllo URL $('.url').change(function() { var campo = $(this).attr('id'); if ( $('#'+campo).val().substr(0,7) != 'http://' && $('#'+campo).val() != '' ) $('#'+campo).val( 'http://' + $('#'+campo).val() ); }); $('#form-spedizione-but').click(function() { $('.form-spedizione-but-box').hide(); $('.form-spedizione-hide-box').show(); $('.form-spedizione-box').show(); }); $('#form-spedizione-hide').click(function() { var blnSpHide = false; var blnSpFull = ( $.trim( $('#txtSpIndirizzo').val() ) != '' || $.trim( $('#txtSpCap').val() ) != '' || $.trim( $('#txtSpCitta').val() ) != '' || ! $('#cmbSpProvincia option:first').attr('selected') ); if ( blnSpFull ) blnSpHide = confirm( "Vuoi cancellare i campi per la spedizione ed utilizzare solo l'indirizzo principale?" ); else blnSpHide = true; if ( blnSpHide ) { $('.form-spedizione-hide-box').hide(); $('.form-spedizione-but-box').show(); $('.form-spedizione-box').hide(); $('.sp-input').val(''); $('.sp-select option:first, #cmbSpNazione option:first').attr('selected', true); } }); $('#txtNome').focus(); }); function fSaveData() { $('submit').focus(); var data; var blnSaved = false; $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/sendSubscription.php", data: $("#frmOggetto").serialize(), success: function(data) { strDestination = data.destination; 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() ) == "" ) { $( "#lbl" + $(this).attr("name") ).html("Campo obbligatorio"); $( "#show_" + $(this).attr("name") + ", #showdomanda_" + $(this).attr("name") ).hide(); blnReturn = false; strAlert += '- ' + $( "#lbl" + $(this).attr("name") ).attr("title") + ' \n'; } else { $( "#lbl" + $(this).attr("name") ).html(""); $( "#show_" + $(this).attr("name") + ", #showdomanda_" + $(this).attr("name") ).show(); } }); // Controllo password if ( $('#txtPassword').val() != '' || $('#txtConfermaPassword').val() != '' ) { if ( $('#txtPassword').val() != $('#txtConfermaPassword').val() ) { $('#lbltxtConfermaPassword').removeClass("conferma").addClass("errore").html("La password non e' uguale."); blnReturn = false; strAlert += '- ' + $('#lbltxtPassword').attr("title") + ' \n'; } else $('#lbltxtConfermaPassword').addClass("conferma").removeClass("errore").html(""); } // Controllo URL if ( $('.url').length ) { $('.url').each(function() { var campo = $(this).attr('id'); if ( $('#'+campo).val().substr(0,7) != 'http://' && $('#'+campo).val() != '' ) $('#'+campo).val( 'http://' + $('#'+campo).val() ); }); } // Controllo privacy if( ! $('#privacy').attr('checked') ) { $('#lblprivacy').html("Accettazione obbligatoria."); blnReturn = false; strAlert += "- Privacy - Accettazione obbligatoria. \n"; } else $('#lblprivacy').html(''); var strID_Contatto = ( $('#id_cliente').length ? $('#id_cliente').val() : '' ); // Controllo Codice fiscale if ( $('#txtCodiceFiscale').val() != '' ) { $('#lbltxtCodiceFiscale').removeClass("conferma").removeClass("errore").html(''); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkContatto.php", data: "action=checkCodiceFiscale&pstrCodiceFiscale=" + $("#txtCodiceFiscale").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intExists = data.codice_fiscale_exists; strTmp = data.status; if ( intExists == 1 ) { // ERRORE : valore NON unico $('#lbltxtCodiceFiscale').removeClass('conferma').addClass('errore').html("Il valore è già in archivio."); blnReturn = false; strAlert += "- Codice fiscale / P.IVA gia' in archivio \n"; } else { // OK : valore unico $('#lbltxtCodiceFiscale').removeClass('errore').addClass('conferma').html("Il valore è unico. Ok."); } if ( data.status == 'ok' ) blnSaved = true; else alert("Verifica non riuscita"); }, error: function(data){ alert("errore: " + data); } }); } // Controllo Email if ( $('#txtEmail').val() != '' ) { $('#lbltxtEmail').removeClass("conferma").removeClass("errore").html(''); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/ajax/checkContatto.php", data: "action=checkEmail&pstrEmail=" + $("#txtEmail").val() + "&pstrID_Contatto=" +strID_Contatto, success: function(data) { intCheck = data.email_check; intExists = data.email_exists; intErrore = data.email_errore; strTmp = data.status; if ( intCheck == 0 ) { // Email non corretta 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 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 { // Email corretta if ( intExists == 1 ) { // ERRORE : email non unica blnReturn = false; $('#lbltxtEmail').removeClass('conferma').addClass('errore').html("Il valore è già in archivio."); strAlert += "- Email gia' in archivio \n"; } else { // OK : Email unica e corretta $('#lbltxtEmail').removeClass('errore').addClass('conferma').html("L'indirizzo sembra corretto. Ok."); } } if ( data.status == 'ok' ) blnSaved = true; else alert("Verifica non riuscita"); }, error: function(data){ alert("errore: " + data); } }); } if ( ! blnReturn && ! intHideAlert ) alert( strAlert ); return blnReturn; }