(function(){

Skelax.Auth = new Hash;
Skelax.Auth.extend({
	login: function (formElements) {
		if ((formElements.get('login') == '') || (formElements.get('passwd') == '')) return false;
		MooTools.lang.set('en-US', 'repasrc', {error: 'ERROR', wronglogin: 'Bad credentials'});
		MooTools.lang.set('fr-FR', 'repasrc', {error: 'ERREUR', wronglogin: 'Identifiant ou mot de passe invalide'});
		var params = {};
		params.action = 'auth';
		params.login = formElements.get('login'); 
		params.password = formElements.get('passwd');
		var sl = new Skelax.JSON.Query({remoteUrl: 'remoting.php', onComplete: function(authRequest) { 
			if (authRequest.error) {
				Skelax.UI.Notification.show({title: MooTools.lang.get('repasrc', 'error'), message: MooTools.lang.get('repasrc', 'wronglogin')});
			} else {
				var a = Cookie.write('userKey', authRequest.userKey);
				Skelax.HTML.batch(authRequest.htmlElements);
				$exec(authRequest.js);
			}
		}});
		sl.doRequest(params);
	},
	logout: function() {
		var params = {};
		params.action = 'logout';
		var sl = new Skelax.JSON.Query({remoteUrl: 'remoting.php', onComplete: function(req) { 
			var a = Cookie.write('userKey', '');
			top.document.location.href='';
		}});
		sl.doRequest(params);
	},
	getUserKey: function() {
		return Cookie.read("userKey");
	}
});

})()

