var blnSubmit = false; $( function() { // Cattura il submit $('#formRecord').bind('submit',function(event) { event.preventDefault(); if ( ! blnSubmit ) fCheckObbligatori( 1, 0 ); }); // Cattura i change $("input,select,textarea").change(function() { if ( ! blnSubmit ) fCheckObbligatori( 0, 1 ); }); // 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).removeClass('errore').addClass('conferma').html(''); $('#box_'+campo).show(); }); // 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(''); }); // Controllo campi //fCheckObbligatori( 0, 1 ); $("#nominativo").focus(); }); //--- Controllo campi obbligatori function fCheckObbligatori( pintSubmit, pintHideAlert ) { var blnReturn = true; var intHideAlert = ( pintHideAlert > 0 ? 1 : 0 ); var strAlert = "Verifica i seguenti campi:\n"; // Campi obbligatori $(".obbligatorio").each(function() { if ( $(this).val() == "" ) { $( "#lbl" + $(this).attr("name") ).removeClass("conferma").addClass("errore").html("Campo obbligatorio"); blnReturn = false; strAlert += '- ' + $( "#lbl" + $(this).attr("name") ).attr("title") + ' \n'; } else $( "#lbl" + $(this).attr("name") ).html( "" ); }); // Controllo password if ( $('.showpassword').length ) { $('.showpassword').each(function() { var campo = $(this).attr('id').substr(5); if ( campo.substring(0,8) != 'conferma' ) { if ( $('#'+campo).val() != $('#conferma_'+campo).val() ) { $('#lblconferma_'+campo).removeClass("conferma").addClass("errore").html("La password non è uguale."); blnReturn = false; strAlert += '- ' + $('#lbl'+campo).attr("title") + ' \n'; } } }); } // 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(''); // AJAX var strAjaxData = '&id_contatto=' + $('#id_cliente').val(); // Controllo email if ( $('#email').val() != '' ) { strAjaxData += '&email=' + $('#email').val(); $('#lblemail').html('...'); } // Controllo username if ( $('#username').val() != '' ) { strAjaxData += '&username=' + $('#username').val(); $('#lblusername').html('...'); } // Chiamata Ajax unica se ci sono campi unici o email if ( $('#email').val() || $('#username').val() ) { $.ajax({ url: 'include/ajax/checkContatto.php' ,data: 'command=checkContatto' + strAjaxData ,success: function(data) { //--- Ajax Results : Inizio update = data.split('|'); if( update[0] == "checkContatto" ) { // Controllo email if ( $('#email').val() != "" ) { if ( update[2] == 0 ) { // ERRORE : email NON corretta $('#lblemail').removeClass('conferma').addClass('errore').html('L\'indirizzo non è corretto.'); blnReturn = false; strAlert += '- Email non corretta.\n \n'; } else { // OK : email corretta if ( update[3] == 1 ) { // ERRORE : email non unica $('#lblemail').removeClass('conferma').addClass('errore').html('Il valore è già in archivio.'); blnReturn = false; strAlert += '- Email e\' gia\' in archivio.\n \n'; } else { // OK : Email unica e corretta $('#lblemail').removeClass('errore').addClass('conferma').html('L\'indirizzo sembra corretto. Ok.'); } } } // Controllo username if ( $('#username').val() != "" ) { if ( update[5] == 1 ) { // ERRORE : valore NON unico $('#lblusername').removeClass('conferma').addClass('errore').html('Il valore è già in archivio.'); blnReturn = false; strAlert += '- Username e\' gia\' in archivio.\n \n'; } else { // OK : valore unico $('#lblusername').removeClass('errore').addClass('conferma').html('Il valore è unico. Ok.'); } } } if ( ! blnReturn && ! pintHideAlert ) { alert( strAlert ); $("html,body").animate({scrollTop: 0}, 1500, "bounceout"); } if ( blnReturn && pintSubmit ) { blnSubmit = true; $('#formRecord').unbind('submit'); $('#formRecord').submit(); } return blnReturn; //--- Ajax Results : Fine } }); } else { if ( ! blnReturn && ! intHideAlert ) { alert( strAlert ); $("html,body").animate({scrollTop: 0}, 1500, "bounceout"); } if ( blnReturn && pintSubmit ) { blnSubmit = true; $('#formRecord').unbind('submit'); $('#formRecord').submit(); } return blnReturn; } }