function affiche_recherche() {
	$( "liste_chat" ).style.display			= "none" ;
	$( "liste_recherche" ).style.display	= "block" ;
	
	$( 'CHomme' ).removeClassName( "homme_hover" ) ;
	$( 'CFemme' ).removeClassName( "femme_hover" ) ;
	$( 'CCouple' ).removeClassName( "couple_hover" ) ;

	$( 'CLoupe' ).addClassName( "loupe_hover" ) ;
}

function tipLoad(e) {
	var User = Event.element( e ).id ;
	if( User != "" )
	{
		if( $( "divT" + User ) != null )	
		{	
			$( "divT" + User ).show() ;
			Event.observe( User, "mouseout", function(e) { tipUnLoad(User); } );
		}
	}
}

function tipUnLoad(User) {
	if( User != "" )
	{
		$( "divT" + User ).hide() ;
	}
}

function explode( item, delimiter ) {
	tempArray		= new Array(1);
	var Count		= 0;
	var tempString	= new String( item );

	while ( tempString.indexOf( delimiter ) > 0 ) {
		tempArray[ Count ]	= tempString.substr( 0, tempString.indexOf( delimiter ) );
		tempString			= tempString.substr( tempString.indexOf( delimiter )+1, tempString.length-tempString.indexOf( delimiter ) + 1 );
		Count				= Count+1
	} 
	
	tempArray[ Count ] = tempString ;
	
	return tempArray;
} 

function in_array ( needle, haystack, argStrict ) {
    var key = '', strict = !!argStrict; 
   
	if (strict) {
        for ( key in haystack ) {
            if ( haystack[key] === needle ) return true ; 
        }
    } 
	else {
        for ( key in haystack ) {
            if ( haystack[ key ] == needle)	return true;
        }
    }
    
	return false;
}

function chatLoad( aPoste ) {
	
	if( aPoste != "CSave=1" )
		Event.stopObserving( "liste_chat" );

	if( aPoste == "CSearch=1" )		
		aPoste		= Form.serialize( 'recherche_chat' ) + "&CSearch=1" ;
	
	var RecupGet	= aPoste ;
	var TabGet		= explode( aPoste, '&' ) ;
	
	if( aPoste != "CSave=1" )
	{
		$( 'CHomme' ).removeClassName( "homme_hover" ) ;
		$( 'CFemme' ).removeClassName( "femme_hover" ) ;
		$( 'CCouple' ).removeClassName( "couple_hover" ) ;
		$( 'CLoupe' ).removeClassName( "loupe_hover" ) ;
		$( 'CLibre' ).removeClassName( "libre" ) ;
		$( 'CLibre' ).removeClassName( "non_libre" ) ;

		if( in_array( "CLibre=1", TabGet ) )	
		{
			var LienJs	= RecupGet.replace( "&CLibre=1", "" );
			LienJs		= LienJs.replace( "&CPage=1", "" ) + "&CLibre=0&CPage=1" ;

			$( 'CLibre' ).addClassName( "libre" ) ;
			$( 'CLibre' ).href	= "javascript: chatLoad( '" + LienJs + "' );" ;
			$( 'CHomme' ).href	= "javascript: chatLoad( 'CType=1&CLibre=1' );" ;
			$( 'CFemme' ).href	= "javascript: chatLoad( 'CType=2&CLibre=1' );" ;
			$( 'CCouple' ).href = "javascript: chatLoad( 'CType=3&CLibre=1' );" ;
		}
		else if( in_array( "CLibre=0", TabGet ) )
		{
			var LienJs	= RecupGet.replace( "&CLibre=0", "" );
			LienJs		= LienJs.replace( "&CPage=1", "" ) + "&CLibre=1&CPage=1" ;

			$( 'CLibre' ).addClassName( "non_libre" ) ;
			$( 'CLibre' ).href	= "javascript: chatLoad( '" + LienJs + "' );" ;
			$( 'CHomme' ).href	= "javascript: chatLoad( 'CType=1&CLibre=0' );" ;
			$( 'CFemme' ).href	= "javascript: chatLoad( 'CType=2&CLibre=0' );" ;
			$( 'CCouple' ).href = "javascript: chatLoad( 'CType=3&CLibre=0' );" ;
		}
		else
		{
			$( 'CLibre' ).href	= "javascript: chatLoad( '" + RecupGet.replace( "&CLibre=1", "" ) + "&CLibre=1&CPage=1" + "' );" ;
			$( 'CLibre' ).addClassName( "non_libre" ) ;
		}
	}
	
	if( ! in_array( "CSearch=1", TabGet ) )
	{
		if( in_array( "CType=1", TabGet ) )	$( 'CHomme' ).addClassName( "homme_hover" ) ;
		if( in_array( "CType=2", TabGet ) )	$( 'CFemme' ).addClassName( "femme_hover" ) ;
		if( in_array( "CType=3", TabGet ) )	$( 'CCouple' ).addClassName( "couple_hover" ) ;
	}
	else $( 'CLoupe' ).addClassName( "loupe_hover" ) ;

	var HtmlLoading = "<div id='AjaxLoading'><img src='" + urlSite + "medias/1.0/images/loading_chat.gif' width='32' height='32' /><br />Chargement des utilisateurs du chat en cours ...</div>" ;
	
	$( 'AjaxChat' ).update( HtmlLoading );

	var options = { 
		method: "get" ,
		parameters: aPoste ,
		onSuccess: function (xhr) {
			$( 'AjaxChat' ).update( xhr.responseText ) ;
			Event.observe( "liste_chat", "mouseover", function(e) { tipLoad(e); } );
		}
	} 
	var ajaxCall = new Ajax.Request( "Bloc_Chat", options );
}
