$(document).keypress(function(key){
  if(key.charCode == 13){
    if(!$('textarea').is(':focus')){
      $('.submit').trigger('click');
    }
  }
});

function contactus_validate(){
  var input_email = $("[name='_email']");
  var input_subject = $("[name='_subject']");
  var input_message = $("[name='_message']");
  var captcha = $("[name='captcha_input']");
  if(!rcube_check_email(input_email.val())){
    rcmail.display_message(rcmail.gettext('noemailwarning','contactus'),'error');
    return false;
  }
  if(input_subject.val() == ""){
    rcmail.display_message(rcmail.gettext('nosubjectwarning','contactus'),'error');
    return false;
  }  
  if(input_message.val() == ""){
    rcmail.display_message(rcmail.gettext('nomessagewarning','contactus'),'error');
    return false;
  }
  if(typeof captchaValidate == 'function'){
    if(captcha.val() == ''){
      captcha.select();
      var msg = rcmail.gettext('captchainput','captcha');
      rcmail.display_message(msg,'error');
      return false;
    }
    else{
      captchaValidate('contactus_callback()');
      return false;
    }
  }
  else{
    return true;
  }
}

function contactus_callback(){
  document.forms.contactus.submit();
  return false;
}