/* Script for altering form element visibility on the "Contact Us" page */
/* Form classes correspond to the keys of the select box. */

$(document).ready(function() {
  if ($("#edit-submitted-type-of-enquiry").val() != "") {
    $("#webform-client-form-87").addClass($("#edit-submitted-type-of-enquiry").val());
  } else {
    $("#webform-client-form-87").addClass("general");
  }
/*  $("#edit-submitted-type-of-enquiry option:first").css("display", "none"); */
  $("#edit-submitted-type-of-enquiry").change(function() {
    var formclass = "webform-client-form ";
    formclass += $(this).val();
    $("#webform-client-form-87").removeClass().addClass(formclass);
  });
});

/* The following code produces a warning message on pages with an FCKEditor component, if the editor is used and the user leaves the page (except via the Save/Preview buttons). This protects against the accidental loss of lengthy posts.
   Uses the unofficial but widely-supported onbeforeunload event - see http://www.boutell.com/newfaq/creating/disableclose.html - the same mechanism used by Gmail.
   Caveat: works for pages with one FCK instance - it does *not* work properly for pages with more than 1. */


var editWarningRequired = true;
var theEditor = false;

/* This function is bound iff an editor loads */
function confirmLeavePage() {
  if (editWarningRequired) {
    if (theEditor.IsDirty()) {
      return "You have made changes to the content in the edit window. If you continue, these changes will be lost. Are you sure you wish to navigate away from this page?";
    }
  }
}

/* FCKEditor calls this when it finishes loading */
function FCKeditor_OnComplete(editorInstance) {
  theEditor = editorInstance;
  window.onbeforeunload = confirmLeavePage;
  /* Attach an onclick event to disable the warning */
  $("#edit-submit,#edit-preview").click(function () {
    editWarningRequired = false;
  });
}

