function checkRows(theArea, maxRows, maxLineChars) {
    var val = "" + theArea.value;
    var rows = val.split('\n');
    var rowIndex;
    var counter = 0;
    for (var i = 0; i < rows.length; i++) {

        if (rows[i].length > maxLineChars) {
            // alert('line '+ i.toString() + ' is longer and counter is ' + counter.toString());
            counter = counter + Math.ceil(rows[i].length / maxLineChars);
            // alert('Counter is now: ' + counter.toString() + ' and maxrows is : ' + maxRows.toString());
            if (counter > maxRows) {
                rowIndex = i;
                var counterThisLine = 0;
                counterThisLine = counterThisLine + Math.ceil(rows[i].length / maxLineChars);
                rows[i] = rows[i].substr(0, ((counterThisLine - (counter - maxRows)) * maxLineChars));
                break;
            }
        }
        else {
            counter++;
            if (counter > maxRows) {
                rowIndex = i - 1;
                break;
            }
        }
    }
    if (counter > maxRows) {
        theArea.value = "";
        for (var k = 0; k <= rowIndex; k++) {
            theArea.value += rows[k] + '\n';
        }
        theArea.value = theArea.value.substr(0, theArea.value.length - 1);
    }
}
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();