/*	
	======================================================================
	
	javascript/community.js

	======================================================================
	Copyright 2006, 2005, 2004 FQXi
	======================================================================
*/


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ValidateSearchText
	//
	/////////////////////////////////////////////////////////
	
 		function ValidateSearchText () {
 		
 			var searchText = Trim (document.searchForm['searchText'].value);
 			
 			if (searchText == '') {
 			
 				alert ("Please enter search text before clicking the 'go' button");
 			}
 			
 			else {
 			
 				document.searchForm.submit();
 			}
 		}
 		
 
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  HideMailingListRegistration
	//
	/////////////////////////////////////////////////////////
	
 		function HideMailingListRegistration () {
 		
 			HideDiv ('mailingListRegistration');
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ShowMailingListRegistration
	//
	/////////////////////////////////////////////////////////
	
 		function ShowMailingListRegistration () {
 		
 			ShowDiv ('mailingListRegistration');
 		}

 		
 	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Preview_Post
	//
	/////////////////////////////////////////////////////////
	
 		function Preview_Post (processingScript, postDivIdentifier) {
 		
 			ShowDiv ("previewPost_" + postDivIdentifier);
 		
 			var addPostText = document["addPostForm_" + postDivIdentifier]["postText_" + postDivIdentifier].value;

 			var addPostTextEscaped = escape (addPostText);

 			var ajaxRequestString = processingScript + "?postDivIdentifier=" + postDivIdentifier + "&text=" + addPostTextEscaped;
 			
 			AJAX_Make_Request (ajaxRequestString);
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  AJAX_Handle_Response
	//
	/////////////////////////////////////////////////////////
	
		function AJAX_Handle_Response (responseArray) {
		
		// ---------------------------------------------
		// parse response
		// ---------------------------------------------

 			responseParts = responseArray.split ('_#_#_#_');
 			
 			source = responseParts[0];

 			response = responseParts[1];

		// ---------------------------------------------
		// forum post preview
		// ---------------------------------------------
 		
			if (source == 'previewPost') {
				
 				subResponseParts = response.split ('_###_');
 				
 				divSuffix = subResponseParts[0];
 				
 				divContent = subResponseParts[1];
 				
 				completeDivID = 'previewPostText_' + divSuffix;
 				
				document.getElementById(completeDivID).innerHTML = unescape (divContent);
			}

		// ---------------------------------------------
		// show thread reply form
		// ---------------------------------------------
 		
			if (source == 'showThreadReplyForm') {
				
 				subResponseParts = response.split ('_###_');
 				
 				divSuffix = subResponseParts[0];
 				
 				divContent = subResponseParts[1];
 				
 				completeDivID = 'threadReplyForm_' + divSuffix;
 			
				document.getElementById(completeDivID).innerHTML = unescape (divContent);
			}
		}
 		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ShowEquationHelp
	//
	/////////////////////////////////////////////////////////
	
 		function ShowEquationHelp (postDivIdentifier) {
 		
 			ShowDiv ('equationHelp_' + postDivIdentifier);
 		}
 		
 		
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  HideEquationHelp
	//
	/////////////////////////////////////////////////////////
	
 		function HideEquationHelp (postDivIdentifier) {
 		
 			HideDiv ('equationHelp_' + postDivIdentifier);
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Clear_Equation
	//
	/////////////////////////////////////////////////////////
	
 		function Clear_Equation (postDivIdentifier) {
 		
			var equationField = Get_Element_Reference ('equation_' + postDivIdentifier);

			equationField.value = ''; 			
 		}
  		
 		
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Insert_Into_Post
	//
	/////////////////////////////////////////////////////////
	 
		function Insert_Into_Post (postDivIdentifier) {
		
			var equationField = Get_Element_Reference ('equation_' + postDivIdentifier);
			
 			if (equationField.value != '') {
 			
				var equationText = "\n\n[equation]" + equationField.value + "[/equation]\n\n";
			
				Insert_At_Cursor ('postText_' + postDivIdentifier, equationText);
			}
			
			else {
			
				alert ("Please enter a LaTeX equation into the text field before inserting into your post");
			}
		}
 		
 
 	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Update_Equation
	//
	/////////////////////////////////////////////////////////
	
 		function Update_Equation (postDivIdentifier) {
 		
			var equationField = Get_Element_Reference ('equation_' + postDivIdentifier);
			
			if (equationField.value != '') {
 			
	 			document["equationImage_" + postDivIdentifier].src = "/cgi-bin/mimetex.cgi?" + equationField.value;
	 		}
 			
			else {
			
				alert ("Please enter a LaTeX equation into the text field before previewing");
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Show_Images_Div
	//
	/////////////////////////////////////////////////////////
	
 		function Show_Images_Div (postDivIdentifier) {
 		
 			ShowDiv ('addEditImages_' + postDivIdentifier);

 			HideDiv ('addEditImagesLink_' + postDivIdentifier);
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Hide_Images_Div
	//
	/////////////////////////////////////////////////////////
	
 		function Hide_Images_Div (postDivIdentifier) {
 		
 			ShowDiv ('addEditImagesLink_' + postDivIdentifier);
 		
 			HideDiv ('addEditImages_' + postDivIdentifier);
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Show_Attachments_Div
	//
	/////////////////////////////////////////////////////////
	
 		function Show_Attachments_Div (postDivIdentifier) {
 		
 			ShowDiv ('addEditAttachments_' + postDivIdentifier);

 			HideDiv ('addEditAttachmentsLink_' + postDivIdentifier);
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Hide_Attachments_Div
	//
	/////////////////////////////////////////////////////////
	
 		function Hide_Attachments_Div (postDivIdentifier) {
 		
 			ShowDiv ('addEditAttachmentsLink_' + postDivIdentifier);

 			HideDiv ('addEditAttachments_' + postDivIdentifier);
 		}


		
 