// Purpose:		Hides and unhides the menu selection by updating the display parameter within the object's style attribute
// Referenced:	onClick event
// Input:		obj - the object to hide or unhide
// Output:		void
function hideMenu(e)
{
	var obj = document.getElementById(e + '_h2');
	if (obj)
	{
		if (obj.style.display == 'none')
		{
			obj.style.display = 'inline';
		}
		else if (obj.style.display == 'inline')
		{
			obj.style.display = 'none';
		}
		else
		{
			obj.style.display = 'none';
		}
	}
}

// Purpose:		Launches a window that will contain the media to view
// Referenced:	hyperlink
// Input:		str - the string name of the media to view
// 				intWidth - the width of the window that will be opened
//				intHeight - the height of the window that will be opened
// Output:		void
function launchWindow(str,intWidth,intHeight)
{
	window.open(str,'viewmedia','height=' + intHeight + ',width=' + intWidth + ',scrollbars=no,resizeable=no,titlebar=no,menubar=no');
}

function validateEdit()
{
	usr = document.getElementById('inputEditUserName').value;
	pwd = document.getElementById('inputEditPassword').value;
	dn = document.getElementById('inputEditDisplayName').value;
	msg = 'The following errors occurred:\n\n';
	allAlpha = /^[a-zA-Z]+$/;
	allAlphaNumeric = /^[0-9a-zA-Z]+$/;
	errFlag = false;
	
	if (usr.length == 0)
	{
		msg = msg + 'You must enter a user name.\n';
		errFlag = true;
	}
	else
	{
		if (usr.length < 3)
		{
			msg = msg + 'The user name must be at least 3 characters long.\n';
			errFlag = true;
		}
		if (!usr.substr(0,1).match(allAlpha))
		{
			msg = msg + 'The user name must begin with an alphabetic character.\n';
			errFlag = true;
		}
		if (!usr.match(allAlphaNumeric))
		{
			msg = msg + 'The user name cannot contain non-alphanumeric characters.\n';
			errFlag = true;
		}
	}
	
	if (pwd.length > 0)
	{
		if (pwd.length < 5)
		{
			msg = msg + 'The password must be at least 5 characters long.\n';
			errFlag = true;
		}
		if (!pwd.match(allAlphaNumeric))
		{
			msg = msg + 'The password cannot contain non-alphanumeric characters.\n';
			errFlag = true;
		}
	}
	
	if (dn.length == 0)
	{
		msg = msg + 'You must enter a display name.\n';
		errFlag = true;
	}
	else if (dn.length < 3)
	{
		msg = msg + 'The display name must be at least 3 characters long.\n';
		errFlag = true;
	}
	
	if (errFlag == true)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}

// Purpose:		Validates the input to the create user functionality
// Referenced:	onSubmit event from the form object
// Input:		user - the user name to be validated
// 				pwd - the password to be validated
// Output:		boolean return (pass or fail)
function validateCreate()
{
	usr = document.getElementById('inputCreateUserName').value;
	pwd = document.getElementById('inputCreatePassword').value;
	dn = document.getElementById('inputCreateDisplayName').value;
	msg = 'The following errors occurred:\n\n';
	allAlpha = /^[a-zA-Z]+$/;
	allAlphaNumeric = /^[0-9a-zA-Z]+$/;
	errFlag = false;
	
	if (usr.length == 0)
	{
		msg = msg + 'You must enter a user name.\n';
		errFlag = true;
	}
	else
	{
		if (usr.length < 3)
		{
			msg = msg + 'The user name must be at least 3 characters long.\n';
			errFlag = true;
		}
		if (!usr.substr(0,1).match(allAlpha))
		{
			msg = msg + 'The user name must begin with an alphabetic character.\n';
			errFlag = true;
		}
		if (!usr.match(allAlphaNumeric))
		{
			msg = msg + 'The user name cannot contain non-alphanumeric characters.\n';
			errFlag = true;
		}
	}
	
	if (pwd.length == 0)
	{
		msg = msg + 'You must enter a password.\n';
		errFlag = true;
	}
	else
	{
		if (pwd.length < 5)
		{
			msg = msg + 'The password must be at least 5 characters long.\n';
			errFlag = true;
		}
		if (!pwd.match(allAlphaNumeric))
		{
			msg = msg + 'The password cannot contain non-alphanumeric characters.\n';
			errFlag = true;
		}
	}
	
	if (dn.length == 0)
	{
		msg = msg + 'You must enter a display name.\n';
		errFlag = true;
	}
	else if (dn.length < 3)
	{
		msg = msg + 'The display name must be at least 3 characters long.\n';
		errFlag = true;
	}
	
	if (errFlag == true)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}

// Purpose:		Passes the delete form when called from a hyperlink
// Referenced:	onClick event from a hyperlink
// Input:		id - the id of the form input element that will be updated
// Output:		void
function passDeleteForm(id)
{
	document.getElementById('inputDeleteUserID').value = id;
	document.formDelete.submit();
}