var tohideElement;
function hidedelai(element,delai){
	tohideElement = element;
	var delai = delai ? delai : 3000;
	setTimeout(function(){ Effect.Fade(element)},delai);
}
/*
 * Controlleur du login liveId.
 * Version initiée en aout 2010
 */
var AX_LoginFrameController = Class.create();
AX_LoginFrameController.prototype = {
	
	version: 1.0,
	uid: null,
	isWaitingForResponse: false,
	layerCache: null,
	
	initialize: function(){
		
	},
	
	login: function(form){
		
		var pwd = form.password;
		var usr = form.identifiant;
		var vgt = $('user_'+usr);
		
		if(!usr || !pwd || pwd.length < 5)
			{
				alert('Veuillez saisir un mot de passe / identifiant invalide');
				return false;
			}
		this.cloading();
		display('loadingimg');
		xajax__register(form);
		return false;
		
	},
	
	loginResponse: function(uid){
		
		//this.endloading();
		if(!uid)
			{
				alert('Aucune UID transmise - echec de la connexion');
				return false;
			}
		this.uid = uid;
		this.endloading();
		this.waitForRequest(this.uid);
	
	},
	
	errorResponse: function(msg){
		
		var text;
		var container;
		var newDate = new  Date;
		var id = newDate.getTime();
		text = '<div class="err" id="MSG_'+id+'">'+msg+'</div>';
		if(this.isWaitingForResponse == true)
			{
				$('_FRM_CONTENT').innerHTML = this.layerCache;
				this.layerCache = null;
				this.isWaitingForResponse = false;
			}
		else
			{
				this.endloading();
			}
		container = $('console');
		container.innerHTML = text;
		hidedelai('MSG_'+id);
		
	},
	
	cloading: function()
	{
		$('_FRM_CONTENT').addClassName('grey');
	},
	
	endloading: function()
	{
		$('_FRM_CONTENT').removeClassName('grey');
	},
	
	waitForRequest: function(ids)
	{
		var layer = $('_FRM_CONTENT');
		this.layerCache = layer.innerHTML;
		var txt = '';
		txt = '<h2 align="center">Connexion a un service web LiveId</h2>';
		txt+= '<div id="console"></div>';
		txt+= '<div align="center"><img src="http://icos.apconcept.net/normal/loading-1.gif" />';
		txt+= '<div class="sgrey">Connexion au service web en cours,<br />veuillez patienter</div>';
		txt+= '</div>';
		layer.innerHTML = txt;
		this.isWaitingForResponse = true;
		xajax__callRequest(ids);
	},
	
	focusUser: function(id){
		$('user_'+id).addClassName('active');
	},
	
	blurUser: function(id){
		$('user_'+id).removeClassName('active');
	}
	
};
/*
 * Fire ApplController event
 */
var apc = {};
document.observe('dom:loaded', function () {
try{
	//document.fire('dom:axinit');
	apc.lid = new AX_LoginFrameController();
} catch(e){
	//alert(e);
}
});

