<!-- Character Counter -->
/* 	This program keeps track of how many characters the user has entered into two textboxes.
	When the user has reached the maximum number of allowed characters, the programs prohibits
	them from entering any more. */
	<!-- Date: 5/13/2007 -->
	<!-- Verison: 1.1 -->

	// Returns the length of the quote text box.
	function quoteLength()
	{
		return document.quote.quote.value.length;
	}
	
	// Returns the length of the author text box.
	function authorLength()
	{
		return document.quote.author.value.length;
	}
	
	// Returns the length of the quote text box plus the author text box.
	function textBoxCount()
	{
		return quoteLength() + authorLength();
	}
	
	// Checks the number of characters against the maximum number (197).
	function charAlert(field) // Field 0 -- Quote; Field 1 -- Author
	{
		if ( textBoxCount() > 197)
		{
			alert('The maximum number of characters that can be entered is 197. You\'ve entered ' + textBoxCount() + '.');
			
			// Subtracts the excess characters from the field the user entered them into.
			if (field == 0)
				document.quote.quote.value = document.quote.quote.value.substring(0, quoteLength() - (textBoxCount() - 197) );
			else
				document.quote.author.value = document.quote.author.value.substring(0, authorLength() - (textBoxCount() - 197) );
			
			// Recalculates the remaining characters. 
			charRemaining();
		}
	}
	
	// Calculates the remaining characters.
	function charRemaining()
	{
		document.quote.charCount.value = 197 - (textBoxCount());
	}
	
	// Activated when the user inserts data into the quote or author field.
	function keyPress(field)
	{
		charRemaining();
		charAlert(field);
	}
	
	
<!-- Open Reference Window -->
/*  This program opens the reference window. It takes one parameter: a string of the anchor (w/o the '#' sign)
	that the user will be redirected to. */
	<!-- Date: 5/04/2007 -->

	function openReference(anchorLink)
	{
		window.open('reference.php#' + anchorLink, 'StatusBar', 'toolbar=no, resizable=no, scrollbars=yes, width=600, height=218, left=0, top=0');
	}
	
	function openHud(anchorLink)
	{
		window.open('hud.php#' + anchorLink, 'StatusBar', 'toolbar=no, resizable=no, scrollbars=yes, width=600, height=400, left=0, top=0');
	}
	


<!-- Add News Functions -->
/*  These methods will add the required HTML to add functionality to the news form. */
	<!-- Date: 5/31/2007 -->
	
	function addUrl()
	{
		// Get the text selected by the user.
		selectedText = getSelText();
		
		// Retrieve the contents of the article field.
		var article = document.composeNews.article.value;
		
		// Add the HTML.
		var url = '<a href="' + selectedText + '">LinkNameHere</a>';
		
		// Replace the selected text with the URL.
		if (selectedText != '')
			article = article.replace(selectedText,url);
		else
			article = article + ' <a href=""></a>';
		
		// Print it out.
		document.composeNews.article.value = article;
	}
	
	function addImg()
	{
		// Get the text selected by the user.
		selectedText = getSelText();
		
		// Retrieve the contents of the article field.
		var article = document.composeNews.article.value;
		
		// Add the HTML.
		var img = '<img src="' + selectedText + '">';
		
		// Replace the selected text with the URL.
		if (selectedText != '')
			article = article.replace(selectedText,img);
		else
			article = article + ' <img src="">';
		
		// Print it out.
		document.composeNews.article.value = article;
	}
	
	function boldText()
	{
		// Get the text selected by the user.
		selectedText = getSelText();
		
		// Retrieve the contents of the article field.
		var article = document.composeNews.article.value;
		
		// Add the HTML.
		var boldText = '<b>' + selectedText + '</b>';
		
		// Replace the selected text with the URL.
		if (selectedText != '')
			article = article.replace(selectedText,boldText);
		else
			article = article + ' <b></b>';
		
		// Print it out.
		document.composeNews.article.value = article;
	}
	
	function italicText()
	{
		// Get the text selected by the user.
		selectedText = getSelText();
		
		// Retrieve the contents of the article field.
		var article = document.composeNews.article.value;
		
		// Add the HTML.
		var italicText = '<i>' + selectedText + '</i>';
		
		// Replace the selected text with the URL.
		if (selectedText != '')
			article = article.replace(selectedText,italicText);
		else
			article = article + ' <i></i>';
		
		// Print it out.
		document.composeNews.article.value = article;
	}
	
	function underlineText()
	{
		// Get the text selected by the user.
		selectedText = getSelText();
		
		// Retrieve the contents of the article field.
		var article = document.composeNews.article.value;
		
		// Add the HTML.
		var underlineText = '<u>' + selectedText + '</u>';
		
		// Replace the selected text with the URL.
		if (selectedText != '')
			article = article.replace(selectedText,underlineText);
		else
			article = article + ' <u></u>';
		
		// Print it out.
		document.composeNews.article.value = article;
	}
	
	function getSelText()
	{
    	var txt = '';
     	if (window.getSelection)	
	        txt = window.getSelection();
	    else if (document.getSelection)
			txt = document.getSelection();
    	else if (document.selection)
			txt = document.selection.createRange().text;
			
		return txt;
	}

	
<!-- Auto Focus -->
/*  This method will automatially focus on a form element when a page loads. The call "window.onload = formFocus(elementId);" must be added
	to the header of the page. */
	<!-- Date: 5/10/2007 -->
	
	function formFocus()
	{
      document.getElementById('focus').focus();
    }