//------------------------------------------------------------------------------
// Class:  TopicGroup
//------------------------------------------------------------------------------
// Author:  CL
// Date:  2007/02/21
// Description:  This class defines the functions used by the Topic Group.
//------------------------------------------------------------------------------
function TopicGroup()
{
	// Variables:
	var maxMsgLength = 4000;
	
	//--------------------------------------------------------------------------

	// Methods:
	this.updateCharCount = updateCharCount;
	this.createTopicGroup = createTopicGroup;
	this.showEditTopicGroup = showEditTopicGroup;
	this.popUpTopicGroup = popUpTopicGroup;
	this.popUpReOrderTopicGroup = popUpReOrderTopicGroup;
	this.addTopicGroup = addTopicGroup;
	this.updateTopicGroup = updateTopicGroup;
	this.goCancel = goCancel;
	
	//--------------------------------------------------------------------------
	
	function updateCharCount(textarea, alertField, isEdit)
	{
		if (textarea.value.length > maxMsgLength)
		{
			textarea.value = textarea.value.substr(0, maxMsgLength);
			alertField.value = maxMsgLength - textarea.value.length;
			if(isEdit)
			{
				document.getElementById('editGroupErr').style.display = "block";
				document.getElementById('editGroupErr').innerHTML = '* Your message must have ' + maxMsgLength + ' chars or less.';
			}
			else
			{
				document.getElementById('createGroupErr').style.display = "block";
				document.getElementById('createGroupErr').innerHTML = '* Your message must have ' + maxMsgLength + ' chars or less.';
			}
		}
		else
		{
			alertField.value = maxMsgLength - textarea.value.length;
		}
	}
	
	//--------------------------------------------------------------------------

	function createTopicGroup(prevIdString,idString)
	{
		theNewTopicGroup = document.getElementById(idString);
		prevTopicGroup = document.getElementById(prevIdString);
		
		if (prevTopicGroup.style.display == "block")
		{
			prevTopicGroup.style.display = "none";
		}
		
		if (theNewTopicGroup.style.display == "none")
		{
			theNewTopicGroup.style.display = "block";
		}
			
		document.frmTopicGroup.newTopicGroup.focus();
	}
	
	//--------------------------------------------------------------------------

	function showEditTopicGroup(prevIdString, idString, topicGroupString, topicGroupDescription, topicGroupID)
	{
		theNewTopicGroup = document.getElementById(idString);
		prevTopicGroup = document.getElementById(prevIdString);
		
		if (prevTopicGroup.style.display == "block")
		{
			prevTopicGroup.style.display = "none";
		}
			
		if (theNewTopicGroup.style.display == "none")
		{
			theNewTopicGroup.style.display = "block";
		}
		
		document.frmTopicGroup.editTopicGroup.value = document.getElementById(topicGroupString).value;
		document.frmTopicGroup.editTopicGroupDescription.value = document.getElementById(topicGroupDescription).value;
		updateCharCount(document.frmTopicGroup.editTopicGroupDescription, document.frmTopicGroup.charCount2, true);
		document.frmTopicGroup.editTopicGroupID.value = topicGroupID;
		document.frmTopicGroup.editTopicGroup.focus();
	}
	
	//--------------------------------------------------------------------------

	function popUpTopicGroup(URL)
	{
		var popUp = window.open(URL, 'Forum', 'toolbar=no,scrollbars=0,location=0,status=0,menubar=0,resizable=1,width=700,height=350,left=122,top=0');
		popUp.focus();
	}
	
	//--------------------------------------------------------------------------
		
	function popUpReOrderTopicGroup(URL)
	{
		var popUp = window.open(URL, 'TopicGroup', 'toolbar=no,scrollbars=0,location=0,status=0,menubar=0,resizable=1,width=700,height=610,left=122,top=0');
		popUp.focus();
	}

	//--------------------------------------------------------------------------
	
	function addTopicGroup()
	{
		var topicGroup = document.frmTopicGroup.newTopicGroup.value;
			
		if((topicGroup.length == 0) || (topicGroup.match(/^\s+$/)))
		{
			//alert('Please enter a group name.');
			document.getElementById('createGroupErr').style.display = "block";
			document.getElementById('createGroupErr').innerHTML = '* Please enter a discussion board name.';
		}
		else
		{
			document.frmTopicGroup.isAddTopicGroup.value = "1";
			document.frmTopicGroup.action = "";
			document.frmTopicGroup.target = '_self';
			document.frmTopicGroup.submit();
		}
	}
	
	//--------------------------------------------------------------------------
		
	function updateTopicGroup()
	{
		var topicGroup = document.frmTopicGroup.editTopicGroup.value;
			
		if((topicGroup.length == 0) || (topicGroup.match(/^\s+$/)))
		{
			//alert('Please enter a group name.');
			document.getElementById('editGroupErr').style.display = "block";
			document.getElementById('editGroupErr').innerHTML = '* Please enter a discussion board name.';
		}
		else
		{
			document.frmTopicGroup.isUpdateTopicGroup.value = "1";
			document.frmTopicGroup.action = "#" + document.frmTopicGroup.editTopicGroupID.value;
			document.frmTopicGroup.target = '_self';
			document.frmTopicGroup.submit();
		}
	}

	//--------------------------------------------------------------------------
		
	function goCancel()
	{
		window.location.href = "index.cfm";
	}
	
}

// Create object.
oTopicGroup = new TopicGroup();

