$(document).ready(function() { 
  var options = {
    beforeSubmit: function (formData){
      for (var i=0; i < formData.length; i++) { 
        if (!formData[i].value) {
          $("#error-text").html("Tev ir jāaizpilda visi lauki");
          $(".error_box").show();
          return false; 
        } 
      }
    },
    success: function(response){
      if(response[0] == 1){
        $("#error-text").html(response[1]);
        $(".error_box").show();
      } else {
          $(".error_box").hide();
         $("#success-text").html(response[1]);
          $(".cool_box").show();
      }
    },
    dataType: 'json',
    url: '/changepassword/handle'
  };
  $('#registerForm').submit(function () { 
          $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
  
  });
});

