var MIN_ROWS = 1 ;
var MAX_ROWS = 3000 ;
var MIN_COLS = 55 ;
var MAX_COLS = 55;
function CheckTab(el) 
{
  if ((form1.document.all) && (9==event.keyCode))
  {
	// Cache the selection
	el.selection=form1.document.selection.createRange(); 
	setTimeout("ProcessTab('" + el.id + "')",0);
  }
}
function ProcessTab(id) 
{
	// Insert tab character in place of cached selection
	form1.document.all[id].selection.text=String.fromCharCode(9);
	// Set the focus
	form1.document.all[id].focus();
}
function changeTextAreaLength ( e ) {
// The function is called and we pass in a 
// reference to the calling element.

    var txtLength = e.value.length;
	var numRows = 0 ;
    //Split the textarea value at each linebreak.
    var arrNewLines = e.value.split("\n");
    
    for(var i=0; i<=arrNewLines.length-1; i++)
	{
		// Iterate through the array for each element in the
		//array we add 1 row to the TEXTAREA..
        numRows++;
        if(arrNewLines[i].length > MAX_COLS-5) {
        // Within each element in our array, determine
        // whether the length of text is greater that our
        // MAX_COLS value.  If so, then we need another
        // row for each time that the length is greater than
        // the MAX_COLS value.
            numRows += Math.floor(arrNewLines[i].length/MAX_COLS)
        }   
    } 
    
    if(txtLength == 0){
    // If there is no text in the TEXTAREA we default
    // to our minimum values.
        e.cols = MIN_COLS ;
        e.rows = MIN_ROWS ;
    } else {
    // If there is only 1 row, then all we need to
    // determine is how many COLS we need.  It will be
    // somewhere between our MIN_COLS & MAX_COLS 
    // values.
        if(numRows <= 1) {
            e.cols = (txtLength % MAX_COLS) + 1 >= MIN_COLS 
                ? ((txtLength % MAX_COLS) + 1) 
                : MIN_COLS ;
        }else{
        // If there is more than 1 row then we immediately
        // default to our MAX_COLS value, and then determine
        // how many ROWS we need.
            e.cols = MAX_COLS ;    
            e.rows = numRows > MAX_ROWS ? MAX_ROWS : numRows ;
        }
    }
	
}
function CheckTab(el) 
{
  if ((form1.document.all) && (9==event.keyCode))
  {
	// Cache the selection
	el.selection=form1.document.selection.createRange(); 
	setTimeout("ProcessTab('" + el.id + "')",0);
  }
}
