var oldStr;
var debug = false;
var newwin = (debug ? window.open('','Name','width=400,height=460,scrollbars=yes') : '');
	if (document.layers)
      document.captureEvents(Event.KEYDOWN);

function fdebug(mes)
{
        if (!debug)
                return;
        newwin.document.write('---'+mes+'---'+'<br>');
        newwin.scrollBy(0,100);
}

function countText(inputStr, counterField, maxChars, maxLine, maxCol) {
	var strLen, actRows, s, c, i, z, l;
	z = 0;
	actRows = 1;
	s = inputStr.value;
	strLen = inputStr.value.length;
	if (strLen == 1 && inputStr.value.substring(0,1) == " ") 
	{
		inputStr.value = "";
		strLen= 0;
	}
	l = strLen;
	for(i=0; i < l; i++)
	{
		z++;
		c = s.slice(i, i + 2);
		if (c == "\r\n")
		{
			i++;
			z = 0;
			actRows++;
		}
		if(z==(maxCol+1))
		{
			z = 1;
			actRows++;
		}
	}
	if (actRows > maxLine)
	{
		inputStr.value = oldStr;
		// alert("Die Nachricht darf nur max. " + maxLine + " Zeilen mit je " + maxCol + " Zeichen enthalten!");
	}
	else 
	{
		oldStr = inputStr.value;
 	  counterField.value = maxChars - ((actRows-1) * maxCol + z);
	}
}
