// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function showCauses(field) {
  if($(field).val() != '') {
    $('#causes').appear('slow');
  } else {
    $('#causes').fade('slow');
  }
}

function postBoxKeyPress(event) {
  return (event.which == 8 || event.which == 0) || ($('#post-text').val().length < 255);  
}

function postBoxDirectKeyPress(event) {
  return (event.which == 8 || event.which == 0) || ($('#post-text-direct').val().length < 500);  
}

function updatePostBoxDirectCounter(counter) {
  counter = $('#'+counter);
  text_length = $('#post-text-direct').val().length;
  
  if (500 - text_length >= 0) {
    counter.text(500 - text_length);
  } else {
   counter.text(0);
  }
}


function updatePostBoxCounter(counter) {
  counter = $('#'+counter);
  text_length = $('#post-text').val().length;
  
  if (255 - text_length >= 0) {
    counter.text(255 - text_length);
  } else {
   counter.text(0);
  }
}

function load_thickboxes() {
  var tb_pathToImage = "images/loadingAnimation.gif";
  tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
  imgLoader = new Image();// preload image
  imgLoader.src = tb_pathToImage;
}

function reply_to_message(user_login) {
  text_area = $('#post-text')
  text_area.focus();
  text_area.text('@'+user_login+' ');
  
  scroll(0,0);
}