function getAllPost() {
	var name = $('#popular-recommended').attr('class');
	if (name == 'popular-menu selected') {
		location.href = '/allpost/'+'pop/';	
	} else {
		location.href = '/allpost/'+'disc/';
	}
}


function postComment(prefix, action) {
	var form = 'PostComment'
	if (prefix.length > 0) {
		form = prefix+form;
	}
	
	AjaxRequest.send(form, action, '', true, { prefix: prefix, comment: FCKeditorAPI.GetInstance(prefix+'CommentTextarea').GetHTML() });
	return false;
}

function dropComment(table, comment_id, hash) {
	AjaxRequest.send(null, '/action/blog/drop_comment/', '', true, { table: table, comment_id: comment_id, hash: hash });
}

function postCommentError(prefix, error) {
	$('#'+prefix+'PostCommentError').html(error);
}

function clearCommentError() {
	$('#PostCommentError').html('');
	$('#FloatPostCommentError').html('');
	$('#EditPostCommentError').html('');
}

function postCommentOk(prefix, html, comment_id, new_comment_id) {
	$('#no_comments_yet').hide();
	if (prefix.length > 0) {
		$('#'+prefix+'PostCommentForm').hide();
		$('#comment_'+comment_id).append(html);
	} else {
		$('#AfterComments').before(html);
	}
	$('#'+prefix+'CommentTextarea').val('');
	FCKeditorAPI.GetInstance(prefix+'CommentTextarea').SetHTML('')
	
	$.scrollTo('#comment_'+new_comment_id+' div.comment', { duration: 300, offset: -100 })
	$('#comment_'+new_comment_id+' div.middle-content').animate( { backgroundColor: '#fcf5b7' }, 300).animate( { backgroundColor: '#ffffff' }, 100)
}

function replyComment(comment_id) {
	$('#FloatPostCommentForm').appendTo('#comment_form_container_'+comment_id).fadeIn()
	$('#FloatPostCommentForm input[name=comment_id]').val(comment_id);
	$('#FloatPostCommentForm textarea').focus();
	clearCommentError();
}

function editComment(table, comment_id, hash) {
	$('#EditPostCommentForm').appendTo('#comment_form_container_'+comment_id).show()
	//pause()
//	$('#EditPostCommentForm input[name=comment_id]').val(comment_id);
//	FCKeditorAPI['Instances']['EditCommentTextarea'].SetHTML($('#comment-content-'+comment_id).html());
//	alert(FCKeditorAPI.GetInstance('EditCommentTextarea'))
//	if (FCKeditorAPI.GetInstance('EditCommentTextarea')) {
	FCKeditorAPI.GetInstance('EditCommentTextarea').SetHTML('aaa');
//	FCKeditorAPI.GetInstance('EditCommentTextarea').SetHTML($('#comment-content-'+comment_id).html());
//	}
//	$('#EditPostCommentForm textarea').focus();
	clearCommentError();
}

function pause(numberMillis)
{
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true)
{
now = new Date();
if (now.getTime() > exitTime)
return;
}
}

function hideReplyComment() {
	$('#FloatPostCommentForm').fadeOut()
}

function hideEditComment() {
	$('#EditPostCommentForm').fadeOut()
}

function onGroupChange(group_id, blog_id) {
	AjaxRequest.send(null, '/action/blog/get_blogs_in_group/', '', true, { group_id: group_id, blog_id: blog_id });
}

function onBlogChange(blog_id) {
	if(blog_id == -1) {
		$('#create_new_blog').show()
		$('#new_blog_name').focus()
	} else {
		$('#create_new_blog').hide()
	}
}

function ratePost(post_id, rate) {
	AjaxRequest.send(null, '/action/blog/rate_post/', '', true, { post_id: post_id, rate: rate });
	return false;
}

function rateComment(table, comment_id, rate) {
	AjaxRequest.send(null, '/action/blog/rate_comment/', '', true, { table: table, comment_id: comment_id, rate: rate });
	return false;
}

function ratePostOk(post_id, rate) {
	$('#post_rate_'+post_id).html(rate)
}

function rateCommentOk(comment_id, rate) {
	$('#comment_rate_'+comment_id).html(rate)
}

function rateUser(user_id, rate) {
	AjaxRequest.send(null, '/action/blog/rate_user/', '', true, { user_id: user_id, rate: rate });
	return false;
}

function rateUserOk(user_id, rate) {
	$('#user_rate_'+user_id).html(rate)
}

function setTopMode(mode) {
	$('.popular-menu').removeClass('selected')
	$('#popular-'+mode).addClass('selected')
	$('.popular-layer').hide()
	$('#top-'+mode).show()
	return false
}

function addToFriends(user_id) {
	AjaxRequest.send(null, '/action/blog/add_to_friends/', '', true, { user_id: user_id });
	return false;
}

function removeFromFriends(user_id) {
	AjaxRequest.send(null, '/action/blog/remove_from_friends/', '', true, { user_id: user_id });
	return false;
}

function postUserMessage() {
	AjaxRequest.send('UserMessageForm', '/action/blog/post_message/', '', true, {  });
	$('#UserMessageTextarea').val('')
	return false;
}

function togglePostFavourite(post_id) {
	AjaxRequest.send(null, '/action/blog/toggle_post_favourite/', '', true, { post_id: post_id });
	return false;
}


//var oFCKeditorCommentTextarea = null;
//var oFCKeditorFloatCommentTextarea = null;
//var oFCKeditorEditCommentTextarea = null;
//
function integrateFckEditor(textarea, height, toolbar_set, table, language, object_id ) {
	
//	eval("
//		oFCKeditor"+textarea+" = new FCKeditor( '"+textarea+"' );
//		var oFCKeditor = oFCKeditor"+textarea+";
//	");
	
	var oFCKeditor = new FCKeditor( textarea ) ;

//	eval("oFCKeditor"+textarea+" = new FCKeditor( '"+textarea+"' ); var oFCKeditor = oFCKeditor"+textarea+"; ");

	
	oFCKeditor.BasePath	= '/js/shared/fckeditor/';
	oFCKeditor.Config["CustomConfigurationsPath"] = "/js/shared/fck-config/blog.js?v7"  ;
	
	oFCKeditor.ToolbarSet = toolbar_set ;
	oFCKeditor.Height = height ;
	
	oFCKeditor.Config['CmsObjectId'] = object_id ;
	oFCKeditor.Config['CmsObjectTempId'] = createUniqCode();
	byId('temp_id_'+textarea).value = oFCKeditor.Config['CmsObjectTempId'];
	oFCKeditor.Config['CmsObjectTable'] = table ;
	oFCKeditor.Config['CmsObjectEditLanguage'] = language ;
	oFCKeditor.Config['CmsObjectImageUploader'] = '/action/editor/fck/image_upload/' ;
	oFCKeditor.Config['CmsObjectFlashUploader'] = '/action/editor/fck/flash_upload/' ;
	
	oFCKeditor.ReplaceTextarea() ;
}

function TogglePostRssExport(post_id) {
	AjaxRequest.send(null, '/action/blog/toggle_post_rss_export/', '', true, { post_id: post_id });
}

function sendPostToFriend(referer, post_id) {
	$('#send_post_id').val(post_id);
	var form = $('#send-post-to-friend');
	form.css('top', $(referer).offset().top - 40);
	form.css('left', $(referer).offset().left - 50);
	form.fadeIn('fast');
}

function sendPostToFriendExecute() {
	AjaxRequest.send('SendPostToFriendForm', '/action/blog/send_to_friend/', '', true, { });
}

function inviteFriend(referer) {
	var form = $('#invite-friend');
	form.css('top', $(referer).offset().top - 40);
	form.css('left', $(referer).offset().left - 50);
	form.fadeIn('fast');
}

function inviteFriendExecute() {
	AjaxRequest.send('InviteFriendForm', '/action/blog/invite_friend/', '', true, { });
}

function orderCustomDesign(referer) {
	var form = $('#customn-design-descr');
	form.css('top', $(referer).offset().top - 60);
	form.css('left', $(referer).offset().left - 170);
	form.fadeIn('fast');
}

function orderCustomDesignExecute() {
	AjaxRequest.send('CustomDesignOrderForm', '/action/blog/order_custom_design/', '', true, { });
}

function loadPostCalendar(month, year, showing_date, user_id, blog) {
	AjaxRequest.send(null, '/action/blog/show_post_calendar/', '', true, {month: month, year: year, showing_date: showing_date, user_id: user_id, blog: blog});
}

function loadAutoCalendar(month, year, showing_date) {
	AjaxRequest.send(null, '/action/blog/show_auto_calendar/', '', true, {month: month, year: year, showing_date: showing_date});
}
