Lib.Login = {
	
	LOGIN : function() {		 
	
		var posta = $(this.form).serialize();
		 
		
		Lib.blockUI('#divHeader',true);
		
		$.post("/json/login/login", posta, function(data) {
			var status = Lib.Json.handleResponse(data);
			
			if (status == Lib.TYPE.SUCCESS) {
				alert(data.msg);
				window.location = data.location;
				return false;
			}else if (status != Lib.TYPE.REDIRECT) {
					alert(data.msg);
					$("input[name^='username']").val('');
					$("input[name^='password']").val('');
			} 
			
			Lib.blockUI('#divHeader',false);
			
		}, 'json');
	 
		return false;
	},
	
	
	LOGOUT : function() {
		
		var posta = null;
		
		Lib.blockUI('#divLogin',true);
		$.post("/json/login/logout", posta, function(data) {
			var status = Lib.Json.handleResponse(data);
			if (status != Lib.TYPE.REDIRECT) {
				Lib.setMessageBox('#MsgBox',data.msg,'warning');
			} 
			 
			Lib.blockUI('#divLogin',false);
			return false;
		}, 'json');
		return false;
	},	
	
	INSERT : function() {
	
		var objData;
		var objName;
		var errorMessage;
		
		var posta = $(this.form).serialize();
		
		Lib.blockUI('#contentPlace',true);
		 
		$.post("/json/user/setdata", posta, function(data) {
			
			$("input").each(function() {				
				$(this).removeClass("error");
			});
			
			var status = Lib.Json.handleResponse(data);			 

			if (status != Lib.TYPE.REDIRECT) {
				for (var obj in data.data ){
						objData = data.data[obj];
						
						$('#'+objData.objName).empty()			
											.addClass('error')
											.fadeIn(100);
					}

				Lib.setMessageBox('.contentMessageBox',data.msg,'error');
				
			} 
			 		
			Lib.blockUI('#contentPlace',false);
			
		}, 'json');
		
		return false;
	},	
	
	
	FORGET : function() {
		
		 
		var posta = $(this.form).serialize();
		
		Lib.blockUI('#contentPlace',true);
		 
		$.post("/json/user/forget", posta, function(data) {
			
			
			var status = Lib.Json.handleResponse(data);			 

			if (status != Lib.TYPE.REDIRECT) {
				
				Lib.setMessageBox('.contentMessageBox',data.msg,'error');
				
			} 
			 		
			Lib.blockUI('#contentPlace',false);
			
		}, 'json');
		
		return false;
	},	
	
	init : function() {
	
    	$('#btnLogin').click(Lib.Login.LOGIN);    	
    	$('#logout-button').click(Lib.Login.LOGOUT);    	
    	
    	$('#btnUserNew').click(Lib.Login.INSERT);
    	$('#btnUserEdit').click(Lib.Login.INSERT);
    	
    	$('#btnForget').click(Lib.Login.FORGET);
    	    	
    	$('input').keydown(function() {
    		 Lib.clearMessageBox('.contentMessageBox');
    	});
    	
    	$('#btnToAdmin').click(function() {
    		if (confirm("Sind Sie Sicher?")) {
    			window.location = '/admin';
    			return false;
    		}
    	});
    	
	}	
	
	
};
