function showAddComment() {
	document.getElementById('addComment').style.display = 'block';
	$("#addComment").show();
	
}

function showAllComments() {
	// document.getElementById('hiddenComment').style.display = 'block';
	
	
	$('#comments div.hideClassYes').removeClass('hideClassYes').addClass('hideClassNo');
	
	document.getElementById('currentlyviewingsome').style.display = 'none';
	document.getElementById('currentlyviewingall').style.display = 'inline';
	return false;
}

function hideAllComments() {
	// document.getElementById('hiddenComment').style.display = 'none';
	
	$('#comments div.hideClassNo').removeClass('hideClassNo').addClass('hideClassYes');
	
	document.getElementById('currentlyviewingall').style.display = 'none';	
	document.getElementById('currentlyviewingsome').style.display = 'inline';	
	return false;
}

function addToFavourites(locationRecipeId){
	
	
	if ($('#memberpanel').hasClass('.loggedin')) {
		var newUrl = "/users/add_favourite/"+locationRecipeId;
		
		$.ajax({
			type: "POST",
		   	url: newUrl,
		   	data: "name=nonzerodata",
		   	success: function(msg){
					
					if (msg == 'SUCCESS'){
						$('#addToFavourites').removeClass('hideClassNo').addClass('hideClassYes');
						$('#inMyFavourites').removeClass('hideClassYes').addClass('hideClassNo');					
					}
				
				}
			});
	}
	
	if ($('#memberpanel').hasClass('.loggedout')){
		$('#showNotLoggedInAddFavourite').show();
	}
	
	
}


//this is the main function for admin details
$(document).ready(function(){
	
	

	
	$('#AddCommentSubmit')
		.click(
			function (event) {
				
				
				
				event.preventDefault();
				
				var postData = $('#RecipeCommentAddForm').serialize();	
				
				var newUrl = "/recipe_comments/add/";
				
				$.ajax({
					type: "POST",
				   	url: newUrl,
				   	data: postData,
				   	success: function(msg){
					
						
					
						$('#addCommentText').html(msg);
						
						
						// Fix up the roundcontent height after comment has changed height
						var newHeight = $('#addComment .roundcontent').height();
								
						
						$('#addComment .roundtop').height(newHeight);
						
		  			}
		  		});
				
				
			}); 			
			
	$('#showNotLoggedInAddFavourite')
		.click(function(event){
			
			
			$(this).hide();
			
		});
	
	
	var commentInfo = '<div id="commentInfo" ></div>';
	
	$('label[for=RecipeCommentComment]').append(commentInfo);
	
	$('#RecipeCommentComment').keyup(function(){

		 limitChars('RecipeCommentComment', 100, 'commentInfo');

	});
	
});



function limitChars(textid, limit, infodiv){

	var text = $('#'+textid).val(); 
	
	var textlength = text.length;
	
	if(textlength > limit){
	
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
	
		$('#'+textid).val(text.substr(0,limit));
	
		return false;
	} else {
	
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
	
		return true;
	}

}