// <![CDATA[

jQuery(document).ready(function(){
  hide_fields();

  show_on_selection( $("#contact_us_subject").val() );

  $("#contact_us_subject").change( function(event) {
    show_on_selection( $("#contact_us_subject").val() );
  });

  $('form#contact_us').submit(function() {
    if (($("form#contact_us select#contact_us_subject").val() == "Anything else") 
      && ($('#faq_response').data('faqs_loaded') == null)
      && ($('form#contact_us textarea#contact_us_comments').val() != '')
    ) {
      var encodedString = encodeURIComponent($('form#contact_us textarea#contact_us_comments').val());
      encodedString.replace(/%20/g, "+");
      $('#faq_response').load('/faqs_search?q=' + encodedString);
      $('#faq_response').data('faqs_loaded', 'true');
      return false;
    }
  });

});

function show_on_selection( subject ) {

  hide_fields();

  if (subject == 'Customer Services') {
    $("#booking_ref").show();
  }
  else if (subject == 'Corporate Enquiries') {
    $("#company").show();
  }
  else if (subject == 'Charity Requests') {
    $("#charity_number").show();
  }
  else if (subject == 'Invoice Accounts') {
    $("#account_number").show();
  };

}

function hide_fields() {
  $("#booking_ref").hide();
  $("#contact_us_booking_ref").val('');
  $("#company").hide();
  $("#contact_us_company").val('');
  $("#account_number").hide();
  $("#charity_number").hide();
  $("#contact_us_account_number").val('');
}


// ]]>
