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

var FormUsrAuth = Class.create(FormCtrl,{
	initialize : function ($super) {
		$super();
		this.formId = 'FormUsrAuth';
	},
	chk : function () {
		//if (!$F('login').length)
			//return _Main.err('L\'adresse e-mail est obligatoire !');
		//if (!$F('pass').length)
			//return _Main.err('Le mot de passe est obligatoire !');
//alert(this.formId);
//alert(this._JSON.send);
		this._JSON.send('m=Usr&c=FormUsrAuth&f=jsonChkCredentials',{
			url: 'index.php?json=true&',
			formId: this.formId,
			method: 'post',
			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=StatsPagesAdm&f=edit';
			}
		});
	},
	logout : function () {
		if (confirm('Comfirmer la déconnexion ?'))
			href('reset=1');
	},
	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();
		//if ($(_FormUsrAuth.id)) {
			//var fields='login,pass,remember,security_code,change_code,buttonConnect'.split(',');
			//_Form.setTabIndex(_FormUsrAuth.id,fields);
			//_Form.fillHash(_FormUsrAuth.id,fields,[],true);
			//$('remember').checked=false;
		//}
	}
});

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

