jQuery( document ).ready(function( $ ) {
   $('#form-guide').submit(function(event){
      event.preventDefault();
      var form = $(this);
      let url = 'http://cloudagesolutions.com/class/ajaxInsertRecords.php';
      var serializedData = form.serialize();
      
      $.ajax({
         url: url,
         dataType: 'json',
         type: 'post',
         data: serializedData,
         success: function( data, textStatus, jQxhr ){
             var message = data.message;
            if(data.status == 'success')
            {
               $('#form-alert-message').removeClass('alert alert-danger');
               $('#form-alert-message').addClass('alert alert-success');
               
               // setTimeout(function () { window.open('http://cloudagesolutions.com/success-stories/download.php?downloadFile=' + data.fileName, '_blank'); }, 1000);
               setTimeout(function () { location.href = 'http://cloudagesolutions.com/success-stories/download.php?downloadFile=' + data.fileName; }, 1000);
            }
            else
            {
               var errorMessage = message.join('</li><li>');
               message = 'Please fix the following errors:';
               message += "<ul style='margin-bottom: 0;'>" +
                          '<li>' + errorMessage + '</li>' +
                          '</ul>';
               
               $('#form-alert-message').removeClass('alert alert-success');
               $('#form-alert-message').addClass('alert alert-danger');
               
               $('#firstname').val('');
               $('#lastname').val('');
               $('#email').val('');
               
               
            }
               
         
            $('#form-alert-message').html(message);
         },
         error: function( jqXhr, textStatus, errorThrown ){
           console.log( errorThrown );
         }
      });
      
   })

});