$(document).ready(function() {
	var opts = {lines: 10, length: 1, width: 3, radius: 12, trail: 90, top: 0, left: 0,};
	var trget = document.getElementById('login-loader');
	var flag = true;
	var base = $(".site_base").text().trim();

	$("#lock-form #userPass").keyup(function(e) {
		if( $("#userPass").val().length > 0 && flag && ( e.which !== 13 || e.keyCode !== 13 ) ) {
			$("p.lgn-error").remove();
		}
	});

	$("#lock-form").submit(function() {

		if( $("#userPass").val().length <= 0 ) {
			$("p.lgn-error").remove();
			$(".dm-lockscreen-item").after("<p class='lgn-error'>Enter password</p>");
			$("#userPass").focus();
		}
		else {
			if(flag) {
				flag = false;
				var spnr = new Spinner(opts).spin(trget);
				$.ajax({
					url: base + "lock/auth",
					type: "post",
					data: $("#lock-form").serialize(),
					dataType: "JSON",
					encode: true
				})
				.done(function(data) {

					if( data.status ) {

						window.location = base + "patron/party";
					}
					else {
						$("p.lgn-error").remove();
						$(".dm-lockscreen-item").after("<p class='lgn-error'>Invalid Password</p>");
						$("#userPass").focus();
						$("#token").val(data.token);
						$("p#login-loader").html("");
						flag = true;
					}
				});
			}
		}

		return false;
	});
});