function showRestText( )
{
	try
	{
		var odd = 0 ;
		var somePostsExist = 0 ;
		$A( $( 'cTable' ).getElementsByClassName( 'lastEntry' ) ).each( function( element )
		{
			somePostsExist = 1 ;
			if( element.hasClassName( 'entryO' ) )
			{
				odd = 1 ;
				throw $break ;
			}
		} ) ;
		stopObservingAbuseLinks( ) ;
		/* obtain last id*/
		var lastId = 0 ;
		if( $( 'lastId' ) )
		{
			lastId = $F( 'lastId' ) ;
			$( 'lastId' ).remove( ) ;
		}
		
		new Ajax.Request( 'modules/text.cafe.loadrest.module.php' ,
		{
			parameters: 'lastId=' + lastId + '&somePostsExist=' + somePostsExist + '&odd=' + odd ,
			onSuccess: function( transport )
			{
				
				$$( 'tr.lastEntry' ).invoke( 'remove' ) ;
				/*$( 'scrollHere' ).update( '' ) ;*/
				
				
				$( 'cTable' ).insert( transport.responseText ) ;
				/*Effect.ScrollTo( $( 'scrollHere' ) ) ;*/
				observeAbuseLinks( ) ;
				if( $( 'lastId' ) && $( 'oldestId' ) && $F( 'lastId' ) == $F( 'oldestId' ) )
				{
					$( 'scrollHere' ).remove( ) ;
				}
				  
			}
			
		} ) ;
		
	}
	catch( e )
	{

		alert( 'kawiarenka\nshowRest\n' + e.toString( ) ) ;
		
	}
	
	
	
}

function addDays( days )
{
	if( $( 'daysOrUser' ) )
	{
		$( 'daysOrUser' ).value = days ;
		try{
			Validation.validate( 'daysOrUser' ) ;
		}
		catch(e) {	}
	}
}

function answerThisPost( id )
{
	try
	{
		var username = new String( $( 'username' + id ).innerHTML ) ;
		username = username.stripTags( ) ;
		$( 'daysOrUser' ).value = username ;
		Effect.ScrollTo( $( 'kawiarenkaForm' ) ) ;
	
	}
	catch( e )
	{
		alert( "kawiarenka\nanswerThisPost\n" + e.toString( ) ) ;
	}
}

function initKawiarenka( )
{
	
		
}

function observeAbuseLinks( )
{
	
	$$( 'a.zglosPost' ).each( function( zglosPost )
	{
		zglosPost.onclick = function( ) { 

			displayWindow( zglosPost.href , 200 , 50 ) ; 
			return false ; 		
		}
		
	} ) ;
	
}

function stopObservingAbuseLinks( )
{
	
	$$( 'a.zglosPost' ).each( function( zglosPost )
	{
		zglosPost.onclick = null ;
		
	} ) ;
	
}

document.observe( "dom:loaded" , function( )
{
	if( $( 'mustRegister' ) )
		$( 'mustRegister' ).onclick = function( ){ alert( "Zaloguj się by móc pisać." ); return false ; } ; 	
		
	new Ajax.Autocompleter( "daysOrUser" , "recUsernameResponse" , "modules/autocomplete.username.module.php" , { minChars: 3 , paramName: 'username' } ) ;
	new Validation( 'kawiarenkaForm' , {immediate: true} ) ;
	
	observeAbuseLinks( ) ;
	if( $( 'scrollHere' ) )
		$( 'scrollHere' ).show( ) ;
	
} ) ;

