/**
 * This function will check whether user is start a chat when s/he try to leave
 * the visual class room. If yes, system will pop up a warning message.
 * 
 * @param callback
 * @return
 */

function chatChangePage(callback) {
	
	if (typeof(modifyFlag)!='undefined' && modifyFlag == true) {
		confirmEditMyProfile("This action takes you away from this screen. Before you leave, any changes to your account information on this screen should be saved.",
				function () {ajaxUpdateUserAccount(callback);},function () {if ($.isFunction(callback)){return callback.apply();}});
		return true;
	}
	
	if (typeof(chatConversation)=='undefined' || chatConversation.status!='P') {
		if ($.isFunction(callback)) {
			return callback.apply();
		}
		return true;
	}
	
	if (chatConversation.isInstructor() && chatConversation.status!='D') {
		confirmLeaveChat(
				"You are leaving the classroom now. Do you want to preserve the chat session and come back later or you want to end all chat now?",
				function() {
					if ($.isFunction(callback)) {
						return callback.apply();
					}
				},function() {
					chatConversation.end();
					if ($.isFunction(callback)) {
						return callback.apply();
					}
				});
	}

	if (!chatConversation.isInstructor() && chatConversation.status!='D') {
		confirmMsg(
				"If you leave the classroom now, your chat session will be terminated. Are you sure you want to continue?",
				function() {
					timer.end();
					if ($.isFunction(callback)) {
						return callback.apply();
					}
				});
	}

}

function getFunctionName(func) {
	var str = $.trim(func.toString());
	str = str.substring(8,str.indexOf("("));
	return str; 
}

