<script type='text/javascript'>
window.onload = function()
{
taInit(false);
}
// Initialize all textareas.
// If bCols is false then columns will not be resized.
function taInit(bCols)
{
var i, ta = document.getElementsByTagName('textarea');
for (i = 0; i < ta.length; ++i)
{
ta[i]._ta_resize_cols_ = bCols;
ta[i]._ta_default_rows_ = ta[i].rows;
ta[i]._ta_default_cols_ = ta[i].cols;
ta[i].onkeyup = taExpand;
ta[i].onmouseover = taExpand;
ta[i].onmouseout = taRestore;
ta[i].onfocus = taOnFocus;
ta[i].onblur = taOnBlur;
}
}
function taOnFocus(e)
{
this._ta_is_focused_ = true;
this.onmouseover();
}
function taOnBlur()
{
this._ta_is_focused_ = false;
this.onmouseout();
}
// Set to default size if not focused.
function taRestore()
{
if (!this._ta_is_focused_)
{
this.rows = this._ta_default_rows_;
if (this._ta_resize_cols_)
{
this.cols = this._ta_default_cols_;
}
}
}
// Resize rows and cols to fit text.
function taExpand()
{
var a, i, r, c = 0;
a = this.value.split('\n');
if (this._ta_resize_cols_)
{
for (i = 0; i < a.length; i++) // find max line length
{
if (a[i].length > c)
{
c = a[i].length;
}
}
if (c < this._ta_default_cols_)
{
c = this._ta_default_cols_;
}
this.cols = c;
r = a.length;
}
else
{
for (i = 0; i < a.length; i++)
{
if (a[i].length > this.cols) // find number of wrapped lines
{
c += Math.floor(a[i].length / this.cols);
}
}
r = c + a.length; // add number of wrapped lines to number of lines
}
if (r < this._ta_default_rows_)
{
r = this._ta_default_rows_;
}
this.rows = r;
}
</script>
</head>
<body>