var WordsMonitor = 0;

function WordLengthCheck(s,l) {
	window.WordsMonitor = 0;
	var f = false;
	var ts = new String();
	for(var vi = 0; vi < s.length; vi++) {
		vs = s.substr(vi,1);
		if((vs >= 'A' && vs <= 'Z') || (vs >= 'a' && vs <= 'z') || (vs >= '0' && vs <= '9')) {
			if(f == false)	{
				f = true;
				window.WordsMonitor++;
				if((l > 0) && (window.WordsMonitor > l)) {
					s = s.substring(0,ts.length);
					vi = s.length;
					window.WordsMonitor--;
					}
				}
			}
		else { f = false; }
		ts += vs;
		}
	return s;
}

function InputLengthCheck(fieldname, WordsTypedFieldName, MaxWords) {
	var textfield = 'document.AbstractForm.' + fieldname + '.value';

	if(MaxWords <= 0) { return; }
	var currentstring = new String();
	eval('currentstring = ' + textfield);

	var currentlength = currentstring.length;
	eval('currentstring = WordLengthCheck(' + textfield + ',' + MaxWords + ')');
	if (WordsTypedFieldName.length > 0) {
		eval('document.AbstractForm.' + WordsTypedFieldName + '.value = ' + (MaxWords - window.WordsMonitor));
		if(currentstring.length < currentlength) { eval(textfield + ' = currentstring.substring(0)'); }
	}
} 