var msgShow = false ;
var idTimer = null ;

function logIn() {
	var login	= $F('inputCnxId');
	var psw		= $F('inputCnxPass');
	var options = { 
		method: "post" ,
		postBody: 'Login=' + login + '&Psw=' + psw + '&Action=logIn' , 
		onSuccess: function (xhr) {
			switch( xhr.responseText ) {
				default :							
					$('msgConnexion').innerHTML = "<p>" + xhr.responseText + "</p>";
					Cufon.set( 'fontFamily', 'Label' ).replace( 'div#ss_menu div.msg p', { hover: true } );
					Effect.SlideDown( 'msgConnexion', { 
						duration: 0.2, 
						afterFinish: function() { 	
							msgShow = true ;
							idTimer = window.setTimeout( removeMsgCnx, 5000 ) ;
						} 
					});			
				break ;
				case "LOG_OK" :
					var ajaxAvatar	= new Ajax.Request( "add_Commentaires.php", { 
						method: "post" ,	
						postBody: 'Login=' + login + '&Action=getInfos' , 
						onSuccess: function (xhr) { 
							$( 'divConnexion' ).hide() ;
							Effect.SlideUp( 'ss_menu_2', { 
								duration: 0.2, 
								afterFinish: function() { 	
									var html2 ;			
									html2 = '<a href="' + urlSite + 'Profil" title="Modifier mon profil">Profil</a>' ;
									html2+= '<a href="' + urlSite + '?uDeconnect=1" title="Me déconnecter">Déconnexion</a>' ;												
									$( 'ss_menu_2' ).update( html2 ) ;
									Cufon.set( 'fontFamily', 'Menu' ).replace( '#ss_menu_2 a', { hover: true } );
									Effect.SlideDown( 'ss_menu_2', { 
										duration: 0.2, 
										afterFinish: function() { 	
											var html ;
											var Infos		= xhr.responseText ;
											var tabInfos	= Infos.split( "###" );	
											html = '<div style="height: 10px;"></div><span class="log">Bienvenue ' + login + '</span>';
											$( 'divConnexion' ).update( html ) ;
											Cufon.set( 'fontFamily', 'Label' ).replace( '#ss_menu span.log' );
											Effect.Appear( 'divConnexion', { duration: 0.2 } ) ;
										} 
									});		
								}
							});
						} 
					});	
				break ;
			}			
		}
	} 
	
	clearTimeout( idTimer ) ;
	if( msgShow ) {
		Effect.SlideUp( 'msgConnexion', { 
			duration: 0.2, 
			afterFinish: function() { 	
				$('msgConnexion').innerHTML = "" ;
				msgShow						= false ;
				var ajaxCall				= new Ajax.Request( "add_Commentaires.php", options );
			}
		});
	}
	else {
		var ajaxCall = new Ajax.Request( "add_Commentaires.php", options );
	}

}

function removeMsgCnx() {
	if( msgShow ) {
		Effect.SlideUp( 'msgConnexion', { 
			duration: 0.2, 
			afterFinish: function() { 	
				$('msgConnexion').innerHTML = "" ;
				msgShow						= false ;
			}
		});
	}
}

function verifLog() {
	var options = { 
					method: "post" ,
					postBody: 'Action=verifLog' ,
					onSuccess: function (xhr)
					{
						switch( xhr.responseText ) 
						{
							case "LOG_KO" :
								
								ouvreBoite( 'formInscription', false, false ) ;

							break ;

							case "LOG_OK" :
								
								ouvreBoite( 'formCommentaire', true, false ) ;

							break ;
						}
					}
				  } 

	var ajaxCall = new Ajax.Request( "add_Commentaires.php", options );
}
