function countChar() 
{
  
  var count_char_textarea = document.getElementById("count_char_textarea");
  var count_char = count_char_textarea.value.length;
  
  if (count_char >= 20 && count_char <= 39){
    
    count_char_textarea.rows = 2;
    
  }
  
  if (count_char >= 40 && count_char <= 69){
    
    count_char_textarea.rows = 3;
    
  }
  
  if (count_char >= 70 && count_char <= 99){
    
    count_char_textarea.rows = 4;
    
  }
  
  if (count_char >= 100){
    
    count_char_textarea.rows = 5;
    
  }
  
  if (count_char <= 1){
    
    count_char_textarea.rows = 1;
    
  }

}

$(document).on('click', '.bb2', function(e){
  
  var button_id = $(this).attr("alt");    
  var start = ''+button_id+'';
  
  insert(start);
  
  return false;

});

function insert(start) {
  
  element = document.getElementById('count_char_textarea');
  
  if (document.selection) {
    
    element.focus();
    sel = document.selection.createRange();
    sel.text = start + sel.text;
  
  } else if (element.selectionStart || element.selectionStart == '0') {
    
    element.focus();
    var startPos = element.selectionStart;
    
    element.value = element.value.substring(0, startPos) + start + element.value.substring(startPos) + element.value.substring(element.value.length);
  
  }else{
    
    element.value += start;
  
  }

}