var where = 'commentFormContainer';

Event.observe(window, "load", function() {
	$("commentFormContainerHidden").hide();
	Event.observe( $("add-comment"), "click", togle_comment_form );	
});


function togle_comment_form()
{
	if( where == 'commentFormContainer' )
	{
		$("commentFormContainer").hide();
		$('commentFormContainerHidden').appendChild($('commentForm'));
		where = 'commentFormContainerHidden';		
	}
	else
	{
		$(where).hide();
		$('commentFormContainer').appendChild($('commentForm'));
		$("commentFormContainer").show();		
		where = 'commentFormContainer';
		$('parent_id').value = 0;
	}		
}

function update_answers(id)
{
	var s_new_place =  'answers-list-' + id;
	//$(s_new_place).update( "" );
	//return;
		
	//alert(URL + "ajax/answers.ajax.php")	
		
	new Ajax.Request(
	URL + "ajax/answers.ajax.php",
	{
		method: "get",
		parameters: {parent_id: id},    
    	onSuccess: function(transport){ 
    		var response = transport.responseText;
    		if( response )
    		{ 
	    		$(s_new_place).update( response );
    		} 
    		else
	    	{
	    		$(s_new_place).update( "" );	    		
			}
		},
		onFailure: function(){ alert("Something went wrong...") }
  	});	
	
}

function show_answer_form(id)
{
	var s_new_place =  'answers-container-' + id;
	
	if( s_new_place == where )
	{
		$(s_new_place).hide();
		$('commentFormContainerHidden').appendChild($('commentForm'));
		where = 'commentFormContainerHidden';
		$('parent_id').value = 0;		
	}
	else
	{
		if( where != '' )
			$(where).hide();
		$('answers-form-container-' + id).appendChild($('commentForm'));
		$('parent_id').value = id;
		where = s_new_place;
		$('answers-list-' + id).update( '<img align="left" src="' + URL + 'images/loading.gif">' );
		$(s_new_place).show();
		update_answers(id);		
	}
	return false;		
}

