(function () {

  // Help tooltip
  $("a.fieldhelp").each (function () {
    $ (this).focus (function () {
      $ (this).addClass ('show');
    });
    $ (this).click (function () {
      $ (this).addClass ('show');
    });
    $ (this).blur (function () {
      $ (this).removeClass ('show');
    })
  });

  // input titles
  $("input[type='text'][title]").each (function () {
    $ (this).focus (function () {
      if ($ (this).val () === $ (this).attr ('title')) {
        $ (this).val ("");
      }});
    $ (this).blur (function () {
      if ($ (this).val () === "") {
        $ (this).val ($ (this).attr ('title'));
      }})
  });

  // form submit button/link
  var form_ids = ["agendaForm", "authorisation-required", "formt2", "formc29", "formc33", "formc66", "login2",
                  "loginAction", "orderForm", "profileForm", "stelVraagForm", "stuurDoorForm", "woningcorporatiesForm"];

  $.each(form_ids, function(i, form_id) {
    $('#' + form_id + " a." + (form_id === 'searchForm' ? 'submit' : 'more'))
      .click (function(e) {
        $ ('#' + form_id).submit ();
        e.preventDefault ();
        return false;
      });
  });

// re-added to temp fix search form
(function() {
      $('#searchForm a.submit').click(function(e) {
        $('#searchForm').submit();
        e.preventDefault();
        return false;
    });
}) ();

  // form submit on [Enter]
    // list of: maps with fields that will activate appropriate form submission (both should be CSS selectors).
    var enterSubmitConfigs = [{
        fields: ["#loginusr", "#loginpwd"],
        form:   "#loginAction"
    }, {
        fields: ["#c53name", "#c53zipcode", "#c53city"],
        form:   "#woningcorporatiesForm"
    }, {
        fields: ["#c66name", "#c66zipcode", "#c66city"],
        form:   "#formc66"
    }, {
        fields: ["#searchcolleague"],
        form:   "#formt2"
    }, {
        fields: ["#searchkeyword", "#search"],
        form:   "#searchForm"
    }, {
        fields: ["#keywords"],
        form:   "#Form1"
    }];

    $.each (enterSubmitConfigs, function (i, enterSubmitCfg) {
      $.each (enterSubmitCfg.fields, function () {
        $ (this).keypress (function (e) {
          if (e.which === 13) {
            $ ('#' +  enterSubmitCfg.form).submit ();
            e.preventDefault ();
          }
        });
      });
    });
}) ();

