	function DestroyDictionaryDisplay()
	{
		if(ModalFunctionFire == false)
			document.getElementById('toolbar_dictionary_pane').style.display = 'none';
	}
	
	function DestroyStickiesDisplay()
	{
		if(ModalFunctionFire == false)
			document.getElementById('toolbar_stickies_pane').style.display = 'none';
	}
	
	function DestroyDiscussDisplay()
	{
		if(ModalFunctionFire == false)
			document.getElementById('toolbar_discussions_pane_view').style.visibility = 'hidden';
	}
	
	function DestroyFoldersDisplay()
	{
		if(ModalFunctionFire == false)
			document.getElementById('toolbar_my_folders_pane').style.display = 'none';
	}
	
	function SwitchToolBar(e,_selectedToolBar)
	{		
		//TO HANDLE DICTIONARY - USER DOES NOT NEED TO BE SIGNED IN TO UTILIZE DICTIONAR
		//if(_selectedToolBar == 'dictionary')
			//ShmoopUser_auth = true;
		if(ShmoopUser_auth || _selectedToolBar == 'dictionary')
		{
			// 'no_event' shows authentication was just performded and stopPropagatiion has been called
			if (e != 'no_event') {
				if (e) {
					var me = new Event(e);
				} else {
					var me = new Event(window.event);
				}
				me.stopPropagation();
			}
	
			switch(_selectedToolBar)
			{
				case 'discuss':
					_fx = 'Discuss';
					SwitchToolBar_target = _fx;

					var url = '/ajax/template/ToolBar?fx=' + _fx + '&item_id=' + ShmoopObject_id + '&item_genus=' + ShmoopObject_genus + '&item_type=' + ShmoopObject_type;
					var xhrcall = new Ajax(url, {onComplete:SwitchToolBar_Response}).request();

					//SAVE RIGHT BLOCK CLICKED VALUE IN HIDDEN FIELD TO USE WHEN USER CLICKS OUTSIDE OF INPUTBOX, (WHEN RETURN TO REST JS FUNCTION IS FIRED).
					document.getElementById('input_right_block_value').value = _fx;
					ModalFunctionFire = false;
					break;
				case 'stickie':
					_fx = 'Stickie';
					SwitchToolBar_target = _fx;
					ResetToolBar('stickie');
					refreshStickies();
					
					document.getElementById('input_right_block_value').value = _fx;
					ModalFunctionFire = false;
					break;
				case 'myfolders':
					_fx = 'MyFolders';
					SwitchToolBar_target = _fx;
					document.getElementById('input_right_block_value').value = _fx;
					ModalFunctionFire = false;
					
					ResetToolBar('myfolders');
					break;
				case 'dictionary':
					_fx = 'Dictionary';
					SwitchToolBar_target = _fx;
					ResetToolBar('dictionary');
					OpenDictionary(e);
					document.getElementById('input_right_block_value').value = _fx;
					ModalFunctionFire = false;
					break;
			}
			
		}
		else
		{
			window.location = '/login.php';
		}
	}
	
	function KeepDictionaryPaneInView(e)
	{
		if(!e)
			var me = new Event(window.event);
		else
			var me = new Event(e);
		me.stopPropagation();
		ResetToolBar('dictionary');
		document.getElementById('input_right_block_value').value = 'Dictionary';
	}

	function SwitchToolBar_Response(_response)
	{
		//switch the viewer
		
		if(SwitchToolBar_target == 'Stickies')
		{

		}
		else if(SwitchToolBar_target == 'Discuss')
		{
			if(_response == 'error')
			{
			}
			else if(_response.match(/no\smember/i))
			{
				//REDIRECT TO LOGIN PAGE
				RedirectLogin();
			}
			else
			{
				//alert(_response);
				document.getElementById('toolbar_discussions_group').innerHTML = _response;
				ResetToolBar('discuss');
				ModalFunctionFire = false;
			}
		
		}
		else if(SwitchToolBar_target == 'Dictionary')
		{


		}
		else if(SwitchToolBar_target == 'MyFolders')
		{
		
		}
	}
	
	function ResetToolBar(_selectedToolBar)
	{
		switch(_selectedToolBar)
		{
			case 'discuss':
				document.getElementById('toolbar_discussions_pane_view').style.display = 'block';
				document.getElementById('toolbar_stickies_pane').style.display = 'none';
				document.getElementById('toolbar_dictionary_pane').style.display = 'none';
				document.getElementById('toolbar_my_folders_pane').style.display = 'none';
				break;
			case 'stickie':
				document.getElementById('toolbar_discussions_pane_view').style.visibility = 'hidden';
				document.getElementById('toolbar_stickies_pane').style.display = 'block';
				document.getElementById('toolbar_dictionary_pane').style.display = 'none';
				document.getElementById('toolbar_my_folders_pane').style.display = 'none';
				break;
			case 'dictionary':
				document.getElementById('toolbar_discussions_pane_view').style.visibility = 'hidden';
				document.getElementById('toolbar_stickies_pane').style.display = 'none';
				document.getElementById('toolbar_dictionary_pane').style.display = 'block';
				document.getElementById('toolbar_my_folders_pane').style.display = 'none';
				break;
			case 'myfolders':
				document.getElementById('toolbar_discussions_pane_view').style.visibility = 'hidden';
				document.getElementById('toolbar_stickies_pane').style.display = 'none';
				document.getElementById('toolbar_dictionary_pane').style.display = 'none';
				document.getElementById('toolbar_my_folders_pane').style.display = 'block';
				break;
		}
	}
	function DiscussionForm()
	{
		this.activeConversationPid = -1;
		this.activePostPid = -1;
		
		/****************************************************************
		 *	SHOW CREATE NEW FORM
		 *
		 *	Display form input fields associated with creating a new 
		 *	conversation
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.showCreateNewForm = function() {
			//document.getElementById('div_startconversation_form').style.display = 'block';
			document.getElementById('toolbar_discussions_pane').style.display = 'block';
			document.getElementById('toolbar_discussions_pane_view').style.display = 'none';
			//document.getElementById('divViewDiscussions').style.display = 'none';
			//document.getElementById('divSearchDiscussion').style.display = 'none';
			return false;
		};
		
		/****************************************************************
		 *	HIDE CREATE NEW FORM
		 *
		 *	Remove from display form input fields associated with creating 
		 *	a new conversation
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.hideCreateNewForm = function() {
			//document.getElementById('div_startconversation_form').style.display = 'none';
			document.getElementById('toolbar_discussions_pane').style.display = 'none';
			document.getElementById('toolbar_discussions_pane_view').style.display = 'block';
			//document.getElementById('divViewDiscussions').style.display = 'block';
			//document.getElementById('divSearchDiscussion').style.display = 'block';
			return false;
		};
		
		/****************************************************************
		 *	RESET CREATE NEW FORM
		 *
		 *	Reset form input fields associated with creating a new 
		 *	conversation to default values
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.resetCreateNewForm = function() {
			document.getElementById('txt_discussion_title').value = 'Subject';
			document.getElementById('txt_discussion_body').value = 'First post';
		};
		
		/****************************************************************
		 *	TOGGLE CONVERSATION REPLY FORM
		 *
		 *	Toggle display of form input fields associated with making 
		 *	a reply in a conversation
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.toggleConversationReplyForm = function(_convo_pid, _override) {
			var div = document.getElementById('div_reply_container_'+_convo_pid);
			if((div.style.display.match(/block/i) && _override == undefined) || _override == false)
				div.style.display = 'none';
			else
			{
				this.toggleConversationDetail(_convo_pid, true);
				div.style.display = 'block';
				document.getElementById('txt_reply_conversation_'+_convo_pid).focus();
			}
				
		};

		/****************************************************************
		 *	TOGGLE CONVERSATION DETAIL
		 *
		 *	Toggle display of conversation thread
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.toggleConversationDetail = function(_convo_pid, _override) {
			var div = document.getElementById('ConversationEntry_Detail_'+_convo_pid);
			
			if((div.style.display.match(/block/i) && _override == undefined) || _override == false)
				div.style.display = 'none';				
			else
			{
				this.fetchConversationDetails(_convo_pid);
				div.style.display = 'block';
			}

		};

		/****************************************************************
		 *	FETCH CONVERSATION DETAILS
		 *	FINISH CONVERSATION DETAILS
		 *
		 *	Fetch all replys to the selected conversation, indicated by
		 *	the parameter _convo_pid
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.fetchConversationDetails = function(_convo_pid) {
			if(this.activeConversationPid == -1)
			{
				var url = '/ajax/template/rightblock?fx=get_conversation_detail&item_id='+_convo_pid;
				this.activeConversationPid = _convo_pid;
				
				var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
				// Map ajax response to class function for execution in local context
				AjaxResponseMap.mapRequest(xhrcall, this.finishConversationDetails, this);
				
				xhrcall.request();
			}
		};
		
		this.finishConversationDetails = function(_response) {
			if(_response.match(/error/i))
				alert('An error occured while looking for conversation details.');
			else if(this.activeConversationPid > 0)
			{
				var div = document.getElementById('ConversationEntry_Detail_'+this.activeConversationPid);
				div.innerHTML = _response;
			}

			this.activeConversationPid = -1;
		};

		/****************************************************************
		 *	START NEW CONVERSATION
		 *	FINISH NEW CONVERSATION
		 *
		 *	Validates the new conversation form and, if correct, submits
		 *	a new conversation for persistence
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.startNewConversation = function() {
			if(ShmoopUser_auth)
			{			
				var subject = document.getElementById('txt_discussion_title').value;
				var body = document.getElementById('txt_discussion_body').value;
				
				var error = (subject == '' || subject == 'Subject');
				if(error)
					document.getElementById('txt_discussion_title').style.borderColor = 'red';
		
				error = (body == '' || body == 'First post');
				if(error)
					document.getElementById('txt_discussion_body').style.borderColor = 'red';
	
				if(error == false)
				{
					body = body.replace(/\>/g, '&gt;').replace(/\</g, '&lt;').replace(/\r?\n/g, '<br />');
					params = 'item_id=' + ShmoopObject_id;
					params += '&item_type=' + encodeURIComponent(ShmoopObject_type);
					params += '&item_genus=' + encodeURIComponent(ShmoopObject_genus);
					params += '&subject=' + encodeURIComponent(subject);
					params += '&body=' + encodeURIComponent(body);
					
					var url = '/ajax/template/ToolBar?fx=new_discussion&'+params;
					var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
					// Map ajax response to class function for execution in local context
					AjaxResponseMap.mapRequest(xhrcall, this.finishNewConversation, this);
					
					xhrcall.request();
				}
			}
			else
			{
				//window.location = '/login.php';
			}
		};
		
		this.finishNewConversation = function(_response) {
			if(_response == "error")
			{
				alert("there was an error");
			}
			else if(_response.match(/no\smember/i))
			{
				//REDIRECT TO LOGIN PAGE
				RedirectLogin();
			}
			else{
				this.hideCreateNewForm();
				this.resetCreateNewForm();

				document.getElementById('toolbar_discussions_group').innerHTML = _response;
				ResetToolBar('discuss');
				ModalFunctionFire = false;
			}
		};

		/****************************************************************
		 *	START NEW CONVERSATION
		 *	FINISH NEW CONVERSATION
		 *
		 *	Redirect to display all discussion topics
		 *					
		 *	date:			August 14, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.showAllDiscussionCategories = function(_allURL)
		{
			window.location = _allURL;
		}
		/****************************************************************
		 *	START NEW REPLY
		 *	FINISH NEW REPLY
		 *
		 *	Validates the new reply form and, if correct, submits
		 *	a reply to the conversation indicated by the parameter
		 *	_convo_pid for persistence
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.startNewReply = function(_convo_pid) {
			var body = document.getElementById('txt_reply_conversation_'+_convo_pid);
	
			if(body.value != '' && this.activeConversationPid == -1)
			{
				var val = body.value.replace(/\>/g, '&gt;').replace(/\</g, '&lt;').replace(/\r?\n/g, '<br />');
				var params = '&id=' + _convo_pid;
				params += '&body=' + encodeURIComponent(val);
				this.activeConversationPid = _convo_pid;
				var url = '/ajax/template/rightblock?fx=reply_conversation'+params;
				
				var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
				// Map ajax response to class function for execution in local context
				AjaxResponseMap.mapRequest(xhrcall, this.finishNewReply, this);
				
				xhrcall.request();
			}
			else
				body.style.borderColor = 'red';
    	};
    	
    	this.finishNewReply = function(_response) {
			if(_response == "error")
				alert("An error occured while saving your reply to conversations.");
			else if(this.activeConversationPid > 0)
			{
				var div = document.getElementById('ConversationEntry_Detail_'+this.activeConversationPid);
				this.toggleConversationReplyForm(this.activeConversationPid, false);
				
				div.innerHTML = _response + div.innerHTML;
			}

			this.activeConversationPid = -1;
		};
		
		/****************************************************************
		 *	START FLAG CONVERSATION
		 *	FINISH FLAG CONVERSATION
		 *
		 *	Submits conversation pid for flagging
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.startFlagConversation = function(_convo_pid) {
			if(this.activeConversationPid == -1 && confirm('You are flagging a conversation, something rub you wrong?'))
			{
				var url = '/ajax/template/rightblock?fx=flag_conversation_master&item_id='+_convo_pid;
				this.activeConversationPid = _convo_pid;
	
				var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
				// Map ajax response to class function for execution in local context
				AjaxResponseMap.mapRequest(xhrcall, this.finishFlagConversation, this);
	
				xhrcall.request();
			}
		};
		
		this.finishFlagConversation = function(_response) {
			if(_response.match(/error/i))
				alert("An error has occured while flagging a conversation");
			else if(this.activeConversationPid > 0)		
				document.getElementById('ico_flag_master_'+this.activeConversationPid).style.display = 'none';
			
			this.activeConversationPid = -1;
		};
		
		/****************************************************************
		 *	START FLAG POST
		 *	FINISH FLAG POST
		 *
		 *	Submits conversation post pid for flagging
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.startFlagPost = function(_post_pid) {
			if(this.activePostPid == -1 && confirm('You are about to flag a posting in this conversation, mmkay?'))
			{
				var url = '/ajax/template/rightblock?fx=flag_conversation_detail&item_id='+_post_pid;
				this.activePostPid = _post_pid;
				
				var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
				// Map ajax response to class function for execution in local context
				AjaxResponseMap.mapRequest(xhrcall, this.finishFlagPost, this);
				
				xhrcall.request();
			}
		};
		
		this.finishFlagPost = function(_response) {
			if(_response.match(/error/i))
				alert("An error has occured while flagging a post");
			else if(this.activePostPid > 0)
				document.getElementById('ico_flag_'+this.activePostPid).style.display = 'none';
		
			this.activePostPid = -1;
		};

		/****************************************************************
		 *	START DELETE POST
		 *	FINISH DELETE POST
		 *
		 *	Submits conversation post pid for deletion. On successful
		 *	deletion acknowledgement from the server, removes posting
		 *	from display. 
		 *					
		 *	date:			April 24, 2008
		 *	author:			NPE
		 ****************************************************************/
		this.startDeletePost = function(_post_pid, _convo_pid) {
			if(this.activePostPid == -1 && this.activeConversationPid == -1)
			{
				if(confirm("Are you sure you want to delete this post? Because, like, it's not coming back dude."))
				{
					var url = '/ajax/template/rightblock?fx=deletereply&pid='+_post_pid;
					this.activePostPid = _post_pid;
					this.activeConversationPid = _convo_pid;
					
					var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
					// Map ajax response to class function for execution in local context
					AjaxResponseMap.mapRequest(xhrcall, this.finishDeletePost, this);
					
					xhrcall.request();
				}
			}
		};
		
		this.finishDeletePost = function(_response) {
			if(_response.match(/error/i))
				alert("An error has occured while deleting a post");
			else if(this.activePostPid > 0 && this.activeConversationPid > 0 && _response.match(/ok/i))
			{
				var div = document.getElementById('div_message_'+this.activeConversationPid+'_'+this.activePostPid);
				div.parentNode.removeChild(div);
			}
			this.activePostPid = -1;
			this.activeConversationPid = -1;
		};
	}
	Discussions = new DiscussionForm();
