var login = null;
$(document).ready(function(){
	login = new Login();
	login.init();
});

function Login(){
	var self = this;
	
	Login.prototype.init = function(){
		$('#loginForm').submit(function(){
			
			if($('#login').val() == '' || $('#pass').val() == ''){
				alert($('#alertMessage').val());
				return false;
			}
			
			$.ajax({
				url: '/login/',
				data: {
					login: $('#login').val(),
					password: $('#pass').val()
				},
				type: 'post',
				dataType: 'json',
				success: function (response){
					if(response){
						window.location = '/';
					}else{
						$('#loginTitle').html($('#loginErrorTitleText').val());
						$('#loginForgotBox').show();
					}
				},
				error: function (){
					alert('Unable to access your profile! Try again later!');
				}
			});
			
			return false;
		});
	};
};
