$( function() { $("#frmLogin").submit( function() { if( fCheckObbligatori() ) fSaveData(); return false; }); }); function fSaveData() { fLoading( 1 ); $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); var data; var strDestination = ''; var blnSaved = false; $('#submitBut').addClass('hide'); $('#submitLoad').removeClass('hide'); $.ajax({ type: "POST", async: false, dataType: "json", url: "/tpl/default/assets/ajax/loginCliente.php", data: $("#frmLogin").serialize(), success: function(data) { strDestination = data.destination; if ( data.status == 'ok' ) blnSaved = true; else alert("Registrazione dati non riuscita"); }, error: function(data) { alert("Procedura non completata."); } }); if ( blnSaved ) { if ( strDestination != '' ) { location.href = strDestination; } else { $('#submitLoad').addClass('hide'); $('#submitBut').removeClass('hide'); $('#loginErrore').removeClass('hide'); $( ".fg-txtUsernameCliente, .fg-txtPasswordCliente" ).addClass( "has-error" ); fLoading( 0 ); } } //else fLoading(0); } // Controlla campi obbligatori login cliente function fCheckObbligatori() { var blnReturn = true; $( ".form-group" ).removeClass( "has-error" ); $( ".lbl" ).html(""); if( $('#txtUsernameCliente').val() == "" ) { blnReturn = false; $('#effect_box').fadeIn(); $( ".fg-txtUsernameCliente" ).addClass( "has-error" ); $('#txtUsernameCliente').focus(); } else if ( $('#txtPasswordCliente').val() == "" ) { blnReturn = false; $('#effect_box').fadeIn(); $( ".fg-txtPasswordCliente" ).addClass( "has-error" ); $('#txtPasswordCliente').focus(); } return blnReturn; }