/* (c) 2009 - Jean Luc BIELLMANN */

var FormUsrAuth = Class.create(FormCtrl,{
	initialize : function ($super) {
		$super();
		this.formId = 'FormUsrAuth';
	},
	init : function (e) {
		var fields = $A([[
			'login,T,8,200,isEmail',
			'pass,T,8,200,/^[0-9a-z]+$/i',
			'remember,T,0,1,/[01]/',
		],FormCaptchaFields]).flatten();

		$A(fields).each((function (field) {
			this.setField(field);
		}).bind(this));

		this.setTabIndex();
		this.setNotEmpty();
		this.setDatas(this.obsChg,[],1); // use cookie to retrieve old datas
		this.setObserve();

		$('login').focus();
	},
	submit : function () {
		if (this.chkDatas()) {
			this.reset('url');
			this.onSuccess = (function (json) {
				if (json.remember)
					return _Main.err('Nouveau mot de passe envoyé par mail !!!');
				if (json.jsonChkCredentials)
					document.location = 'index.php?m=Stats&c=StatsPages&f=edit';
			}).bind(this);
			this.send('m=Usr&c=FormUsrAuth&f=jsonChkCredentials');
		}
	},
	logout : function () {
		if (confirm('Comfirmer la déconnexion ?'))
			href('reset=1');
	},
});

var _FormUsrAuth = new FormUsrAuth();
Event.observe(window,'load',function () {
	if ($(_FormUsrAuth.formId)) {
		_FormUsrAuth.init();
	}
});

