
// Checks specified numbers of characters in a form textarea box and provides warning and excess text pop up window.

// Variable FieldLengthLimit is the max charcaters allowed
// Variables InputtedFormLength and FormNameAndField are this.value and this, respectively)

function checkTextArea(InputtedFormLength,FieldLengthLimit,FormNameAndField){
  var stringLength = InputtedFormLength.length;
  var lengthLimit = FieldLengthLimit;	
  		if (stringLength > lengthLimit){				
  		var charsCut = stringLength - lengthLimit;
  		var clippedString =	InputtedFormLength.substr(0,lengthLimit);
  		var remainingString = InputtedFormLength.substr(lengthLimit);
  		var popWindow =
  		"<HTML><HEAD><TITLE>Text Retrieval</TITLE></HEAD>"+
  		"<center><BODY BGCOLOR='ffffff'><table border=0>"+
  		"<tr><td width=10% height='22'>"+
  		"<p style='font-family:verdana;font-size:13px;color:#704236;text-align=center'><b>Excess Text Retrieval</b></p>"+
  		"<p style='font-family:verdana;font-size:13px;color:#000000;'>Select the text you wish to retrieve<br>then press CONTROL\+C to copy<br> the text to the "+ "clipboard for later use.</p></td></tr><tr><td valign='top' align='center'><br>"+
  		"<form><textarea name='retrieve' cols='30' rows='7' wrap='PHYSICAL'>"+remainingString+
  		"</textarea><br><br><input type='BUTTON' value='Close' onClick='self.close()' name='BUTTON'></form>"+
  		"</td></tr></table></center></BODY>";				
  		alert('You have exceeded the maximum text allowed for this field by ' +charsCut+ ' characters.\n\n' + 'When you click OK the excess characters will be removed, after which you can submit the form.\n The excess characters will be placed in a holding area, where you can retrieve them.');
  			  FormNameAndField.value = clippedString;					  
  		  popup = window.open("","popDialog","height=300,width=275,scrollbars=no");
  		  popup.document.write(popWindow);
  		  popup.document.close();				
  		}
  }
