/**************************************************************************\
BUILD 4
Copyright (c) Enigma Interactive 2005

Filename:		user.js
Description:	Interfaces with the serverside user object.

History
ver	date		who			comment
-----------------------------------------------------------------------------
1	15/12/05	AJL			Created
\**************************************************************************/

var USER = { };
USER.UserController = function() {
	this.inherit(OO.Listener);
}
USER.UserController.prototype = {
	initSelf: function() {
		//CC.messenger.registerListener(this, 'status');
		//this.requestLoginStatus();
	},

	requestLoginStatus: function() {
		CC.messenger.sendRequest('user', 'loginStatus');
	},
	
	logout: function() {
		CC.messenger.sendRequest('user', 'logout');
	},
	
	setLoginInfo: function(data) {
		if (data.loginstatus) {
			this.username = data.username;
			this.fullname = data.fullname;
			this.loggedIn = true;
		} else {
			this.username = '';
			this.fullname = '';
			this.loggedIn = false;
		}
		this.displayStatus();
	},
	
	displayStatus: function() {
		var statusArea = DOM.get('sbUserLoginStatus');
		var loginStatus = (this.loggedIn) ? 'Logged in as: '+this.fullname : 'Not logged in';
		if (statusArea) statusArea.innerHTML = loginStatus;
	},
	
	listenToMessage: function(message, p1, p2) {
		switch (message) {
			case 'loginInfo'	:	this.setLoginInfo(p1);
		}
	}
}