/* ------------------
	JS - localStorage
--------------------*/
$.fn.isValid = function() {
  return this[0].checkValidity();
}

function register() {
  if ($('#registerForm').isValid()) {
    var username = $('#username').val();
    var password = $('#password').val();
    var companyName = $('#companyName').val();
    var email = $('#email').val();
    var phone = $('#phone').val();
    var street = $('#street').val();
    var postalCode = $('#postalCode').val();
    var city = $('#city').val();
    var country = $('#country').val();
    $.ajax({
      url: '../../../pmarket/api/client/add',
      type: 'POST',
      dataType: "json",
      contentType: "application/json; charset=utf-8",
      data: JSON.stringify({
        "username": username,
        "password": password,
        "companyName": companyName,
        "email": email,
        "phone": phone,
        "street": street,
        "postalCode": postalCode,
        "city": city,
        "country": country
      }),
      success: function(response) {
        if (response.notice) {
          $('#alertError').html('Votre compte a été créé avec succès');
        } else {
          $('#alertError').html(response.error.text);
        }
      }
    })
  }
}