function countLines(strtocount) {
    var hard_lines = 1;
    var last = 0;
    while ( true ) {
        last = strtocount.indexOf("\n", last+1);
        hard_lines ++;
        if ( last == -1 ) break;
    }
    return hard_lines;
}


function resizeTextarea(oTextArea, iMinRows) {
  var iLineBreaks  = countLines(oTextArea.value);

	if (iMinRows < iLineBreaks) {
		oTextArea.rows = iLineBreaks;
  }
	else if (iLineBreaks < iMinRows) {
		oTextArea.rows = iMinRows;
  }
}