var Login = {
	show: function(){
		$('loginError').hide();
		$('loginForm').reset();
		$('otcoverlayer').show();
		new Effect.Appear('otlogin')
	},
	
	submit: function(cmsPath){
		$('loginError').hide();
		
		new Ajax.Request($('loginForm').action, {
			method: 'post',
			parameters: $('loginForm').serialize(),
			onComplete: function(transport){
				if(transport.responseText.strip() == 'ok'){
					new Effect.Fade('otlogin');
					setTimeout("$('otcoverlayer').hide()", 1000);
					var actualLocation = window.location.pathname;
					if(!actualLocation.endsWith('home.jsp')){
						window.location = actualLocation.substring(0, actualLocation.indexOf('_') + 3) + "/home.jsp";
					} else{
						Login.showWelcomeBox(cmsPath);
					}
				} else{
					$('loginError').show();
				}
			}
		});
	},
	
	showWelcomeBox: function(cmsPath){
		new Ajax.Updater('otwelcome', cmsPath + 'dettagliUtenteInSessionAjah.do', {
			onComplete: function(transport){
				if(transport.responseText.strip() != 'ko'){
					$('otwelcome').show();
					new Effect.Pulsate('otwelcome', {
						pulses: 4,
						from: 0.1,
						duration: 3
					});
				}
			}
		});
	}
};