function doShowFastReply(mailid){
	
	//var session = $('#mail_session_id_'+mailid);
	//if (session.length > 0){
	//	if (session.hasClass('mail_session_collapse')){
	//		//alert(session.attr('mailid'));
	//		toggleSession(session);
	//	}
	//}

	doHideMailDetail(mailid);
	//top border
	var obj = $('#mail_session_id_'+mailid);
	/*
	var middle = $('.frame_top_border_middle', obj);
	var left = $('.frame_top_border_left', obj);
	var right = $('.frame_top_border_right', obj);
	middle.addClass('frame_top_border_middle_fast_reply');
	middle.removeClass('frame_top_border_middle');
	left.addClass('frame_top_border_left_fast_reply');
	left.removeClass('frame_top_border_left');
	right.addClass('frame_top_border_right_fast_reply');
	right.removeClass('frame_top_border_right');*/

	var button = $('#mail_fast_reply_button_'+mailid);
	button.removeClass("mail_fast_reply_hide_icon");
	button.addClass("mail_fast_reply_show_icon");
	var fastReply = $('#mail_fast_reply_'+mailid);

	fastReply.animate({height: 'toggle'}, 300, 'swing', function(){
		fastReply.attr('state', 'show');
		adjustMailContentSize(mailid, true);
		var textarea = $('#mail_fast_reply_textarea_'+mailid);
		textarea.focus();
	});
}
function doHideFastReply(mailid, callback){
	var button = $('#mail_fast_reply_button_'+mailid);
	button.removeClass("mail_fast_reply_show_icon");
	button.addClass("mail_fast_reply_hide_icon");
	var fastReply = $('#mail_fast_reply_'+mailid);
	enableFastReplySendButton(mailid, false);

	if (fastReply.attr('state') === 'show') {
		fastReply.animate({height: 'toggle'}, 300, 'swing', function(){
			fastReply.attr('state', 'hide');
			adjustMailContentSize(mailid, true);
			/*
			//top border
			var obj = $('#mail_session_id_'+mailid);
			var middle = $('.frame_top_border_middle_fast_reply', obj);
			var left = $('.frame_top_border_left_fast_reply', obj);
			var right = $('.frame_top_border_right_fast_reply', obj);
			middle.addClass('frame_top_border_middle');
			middle.removeClass('frame_top_border_middle_fast_reply');
			left.addClass('frame_top_border_left');
			left.removeClass('frame_top_border_left_fast_reply');
			right.addClass('frame_top_border_right');
			right.removeClass('frame_top_border_right_fast_reply');*/
			//
			if (callback){
				callback();
			}
		});
	}else{
		if (callback){
			callback();
		}
	}
}
function toggleFastReply(mailid){
	var button = $('#mail_fast_reply_button_'+mailid);
	if (button.hasClass("mail_fast_reply_hide_icon")){
		doShowFastReply(mailid);
	}else{
		doHideFastReply(mailid);
	}
}

function popupFastReply(mailid) {
    doHideFastReply(mailid);
	var mailInfo = $('#mail_info_'+mailid);
	var textarea = $('.mail_fast_reply textarea', mailInfo);
	invokeAppFunction('popupFastReply', {
		mailid: mailid,
		replyAll: true,
		content: textarea.val()
	});
    setTimeout(function(){
        $('.mail_fast_reply textarea').val('');
    }, 300);
}

function enableFastReplySendButton(mailid, bEnable){
	var sendButton = $('#fast_reply_send_button_'+mailid);
	if (bEnable){
		sendButton.removeClass('mail_fast_reply_send_disabled');
		sendButton.addClass('mail_fast_reply_send_enabled');
	}else{
		sendButton.removeClass('mail_fast_reply_send_enabled');
		sendButton.addClass('mail_fast_reply_send_disabled');
	}
}
function sendFastReply(mailid) {
	var mailInfo = $('#mail_info_'+mailid);
	var sendButton = $('.mail_fast_reply_send', mailInfo);
	var textarea = $('.mail_fast_reply textarea', mailInfo);
    if (sendButton.hasClass('mail_fast_reply_send_enabled')){
		invokeAppFunction('sendFastReply', {
			mailid: mailid,
			replyAll: true,
			content: textarea.val()
		});
		doHideFastReply(mailid);
    }
}

function doCheckIsHideFastReply(mailid){
	var fastReply = $('#mail_fast_reply_'+mailid);
	if (fastReply.attr('state') === 'show') {
		return false;
	}else{
		return true;
	}
}

var csDisableFastReplyMenu = 0;
var csShowFastReplyMenu = 1;
var csHideFastReplyMenu = 2;
function checkIsHideFastReply(params){
	var mailid = params.getValue('mailid');
	var loaded = checkMailSessionLoaded(mailid);
	var session = $('#mail_session_id_'+mailid);
	var expand = session.hasClass('mail_session_expand');
	if (!loaded || (!expand)){
		return csDisableFastReplyMenu;
	}else{
		if (doCheckIsHideFastReply(mailid)) return csShowFastReplyMenu;
		else return csHideFastReplyMenu;
	}
}

function showFastReply(params){
	var mailid = params.getValue('mailid');
	//var replyAll = params.getValue('replyAll');
	doShowFastReply(mailid);
}

function hideFastReply(params){
	var mailid = params.getValue('mailid');
	doHideFastReply(mailid);
}