if (!window.limsjs) {
  window.limsjs = {};
}

if (!limsjs.user) {
  limsjs.user = {};
}


limsjs.user.signIn = function (usernameEl, passwordEl) {
  var status;
  document.getElementById('loginLoader').innerHTML = '<img src="'+webDir+'/images/loader_one.gif" alt="Nahrávám..." style="float: right;">';

  $.ajax({
    type: "POST",
    url: webDir+'/',
    data: ({
      'user_sign_in' : 'true',
      'username' : usernameEl.value,
      'password' : passwordEl.value
    }),
    success: function(status){
      var user = jQuery.parseJSON(status);

      /**
       * pokud prihlaseni probehne v pořádku
       */
      if(user.authenticated == true) {
        afterSuccessSignIn(user);
      }

      /**
       * pokud se prihlaseni nepovede
       */
      else {
        afterIncorrectSignIn(user);
      }
    }
  });
  
}

limsjs.user.signOut = function () {
  $.ajax({
    type: "POST",
    url: webDir+'/',
    data: ({
      'user_signout' : 'true'
    }),
    success: function(status){
      afterSignOut();
    }
  });
}

