// generic JS fixes

// various JavaScript object.
var Blueprint = {};

// jump to the value in a select drop down
Blueprint.go = function(e) {
  var destination = e.options[e.selectedIndex].value;
  if (destination && destination != 0) location.href = destination;
};

// prevent users from clicking a submit button twice
Blueprint.formCheck = function() {
  // only apply this to node and comment and new user registration forms
  var forms = $("#node-form>div>div>#edit-submit,#comment-form>div>#edit-submit,#user-register>div>#edit-submit");

  // insert the saving div now to cache it for better performance and to show the loading image
  $('<div id="saving"><p class="saving">Saving&hellip;</p></div>').insertAfter(forms);

  forms.click(function() {
    $(this).siblings("input:submit").hide();
    $(this).hide();
    $("#saving").show();

    var notice = function() {
      $('<p id="saving-notice">Not saving? Wait a few seconds, reload this page, and try again. Every now and then the internet hiccups too :-)</p>').appendTo("#saving").fadeIn();
    };

    // append notice if form saving isn't work, perhaps a timeout issue
    setTimeout(notice, 24000);
  });
};

// Global Killswitch.
if (Drupal.jsEnabled) {
  $(document).ready(Blueprint.formCheck);
}

$(document).ready(function() {
  var search_form = $("#search-block-form input.form-text");
  var simplenews_form = $("div.block-simplenews input.form-text");
  
  if (search_form.val() == '') {
    search_form.val('type uw zoekwoord');
  }
  $(search_form).click(function() {
    if (search_form.val() == 'type uw zoekwoord') {
      $(this).val('');
    }
  });
  $(search_form).blur(function() {
    if (search_form.val() == '') {
      $(this).val('type uw zoekwoord');
    }
  });
  
  if (simplenews_form.val() == '') {
    simplenews_form.val('e-mail voor nieuwsbrief');
  }
  $(simplenews_form).click(function() {
    if ($(this).val() == 'e-mail voor nieuwsbrief') {
      $(this).val('');
    }
  });
  $(simplenews_form).blur(function() {
    if ($(this).val() == '') {
      $(this).val('e-mail voor nieuwsbrief');
    }
  });
  
  var active_menu = $("#navigation ul li a.active");
  active_menu.parents("li li").children("a").addClass("active");
  
});