/*
	Function: CheckText(thefield,evt)
	Purpose: This function is used to prohibit the use of the enter key in
	   	     text areas and to parse out any carriage returns or line feeds
			 a user may have put into a textarea when they cut and pasted
			 from a word document.
	Returns: Nothing.
	Modifies: changes value of formfield specified
	Usage: CheckText(thefield,evt)
	Parameteres: thefield is a required parameter, evt is optional
			
	Explanation:
	this function works two ways:
	
	1) passing in thefield only - useful for onsubmit functions
	CheckText(thefield)
	i.e. onsubmit="CheckText(document.<formname>.<formfieldname>)"
	- using the method causes the function to parse out all return or line feeds
	from the text field value 
	
	2)passing both thefield and evt - useful for onkeyup() events
	CheckText(thefield,evt)
	i.e.
	<textarea name="textstuff" cols="30" rows="4" onKeyUp="CheckText(0,event)" wrap="virtual"></textarea>
	- when using this method, make thefield value 0, the function implicitly
	determines the src of the function call.
	*/
	function CheckText(thefield,evt)
	{
	var thebtn = "";
	var newvalue = "";
	var thesrc = "";
	var just_found_13=0;
	var isNav = (navigator.appName == "Netscape") ? true: false;
	var last_value = 0;
	
	//if the user passed in the evt value (this is being used on a textarea
	//via onkeyup event).
	if (evt)
	{
		if (isNav)
		{
			thebtn = evt.which;
		    thesrc= evt.target;
		}
		else
		{
			if (evt.srcElement.type == "textarea")
			{
				thebtn = evt.keyCode;
				thesrc = evt.srcElement;
			}
		}
		//display the value in the status bar
		//status = thebtn;
	}
	//the user is calling function via onsubmit or from another function
	else
		thesrc = thefield;
	
	//loop through each character for the current field one by one, checking 
	//its value
	for (var i=0;i<thesrc.value.length; i++)
	{
		if ((thesrc.value.charCodeAt(i) != 13) && (thesrc.value.charCodeAt(i) != 10))
		{	
			newvalue += thesrc.value.charAt(i);		
			just_found_13=0;
		}	
		else
		{
			if (thesrc.value.charCodeAt(i) == 13)
				just_found_13=1;
			if (thesrc.value.charCodeAt(i) == 10)
			{
				if (just_found_13 == 1)
				{
					newvalue += "<br>";
					just_found_13=0;
				}
			}
		}	
	}
	thesrc.value = newvalue;
}
