//--------------------------------------------------------------------ACCOUNT CLASS
//class to call AJAX PHP account functions, such as login, logout, register, lostpass
function AccountJS(config) {
	this.func = null;
	this.config = config;
}


//---------------------------LOGIN
//logs user in
AccountJS.prototype.login = function(email, pass, target, func) {	
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'login',
					args:			{email:email, pass:pass}, 
					return_target:	this, 
					return_func:	'loginReturn'});
	
}
//finishes above
AccountJS.prototype.loginReturn = function(config) {
	//redirects to appropriate page
	callFunc(this.target, this.func, config);
}



//---------------------------LOGOUT
//logs user out
AccountJS.prototype.logout = function(target, func) {
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'logout',
					args:			null, 
					return_target:	this, 
					return_func:	'logoutReturn'});
}
//finishes above logout process
AccountJS.prototype.logoutReturn = function(config) {
	callFunc(this.target, this.func, config);
}



//---------------------------REGISTER
//when register button pressed
AccountJS.prototype.register = function(email, pass, target, func) {
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'register',
					args:			{email:email, pass:pass}, 
					return_target:	this, 
					return_func:	'registerReturn'});
}

//finishes above register process
AccountJS.prototype.registerReturn = function(config) {
	if (config['success']) {
		this.sendActivation(config);
	} else {
		callFunc(this.target, this.func, config);
	}
}


//---------------------------PASSWORD
//when register button pressed
AccountJS.prototype.changePassword = function(oldpass, pass, target, func) {
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'changePassword',
					args:			{oldpass:oldpass, pass:pass}, 
					return_target:	this, 
					return_func:	'changePasswordReturn'});
}

//finishes above register process
AccountJS.prototype.changePasswordReturn = function(config) {
	callFunc(this.target, this.func, config);
}

//---------------------------DETAILS
//when register button pressed
AccountJS.prototype.changeDetails = function(details, target, func) {
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'changeDetails',
					args:			details, 
					return_target:	this, 
					return_func:	'changeDetailsReturn'});
}

//finishes above register process
AccountJS.prototype.changeDetailsReturn = function(config) {
	callFunc(this.target, this.func, config);
}



//---------------------------LOST
//when register button pressed
AccountJS.prototype.lost = function(email, target, func) {
	this.target = target;
	this.func = func;
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'lost',
					args:			{email:email}, 
					return_target:	this, 
					return_func:	'lostReturn'});
}

//finishes above register process
AccountJS.prototype.lostReturn = function(config) {
	if (config['success']) {
		this.sendActivation(config);
	} else {
		callFunc(this.target, this.func, config);
	}
}



//---------------------------ACTIVATION EMAIL
AccountJS.prototype.sendActivation = function(config) {
	var email =		config['data']['email'];
	var serial =	config['data']['serial'];
	var url =		config['url'];
	
	ajaxRequest({	module:			'account',
					target:			'Account',
					func:			'sendActivation',
					args:			{email:email, url:url}, 
					return_target:	this, 
					return_func:	'sendReturn'});
}

//finishes above register process
AccountJS.prototype.sendReturn = function(config) {
	var email =		config['data']['email'];
	var serial =	config['data']['serial'];
	
	if (config['success']) {
		addLog('<?=DOM_INDEX?>/account_activate/' + email + '/' + serial, 'AccountJS - sendReturn');
	}
	
	if (this.func != null) {
		callFunc(this.target, this.func, config);
	}
}



