$$.extend({
  tmp : {
    Ready : function()
    {
      $('span.tmpEdit').hover(
        function() {
          $(this).addClass('tmpEditOn');
        },
        function() {
          $(this).removeClass('tmpEditOn');
        }
      );

      if ($('form#tmpResetPasswordDialogue').length) {
        $('form#tmpResetPasswordDialogue').OpenDialogue(true);

        $('input#tmpResetPasswordDialogueResetPassword').click(
          function($e) {
            $e.preventDefault();

            if ($('input#tmpResetPassword').val().length && $('input#tmpResetPasswordConfirm').val().length) {
              if ($('input#tmpResetPassword').val() === $('input#tmpResetPasswordConfirm').val()) {
                $.getJSON(
                  $$.Path(
                    '/private/tmpEmployees/resetOwnPassword', {
                      tmpResetPassword: $('input#tmpResetPassword').val() 
                    }
                  ),
                  function(json) {
                    if ($$.tmp.CheckResponseCode(json)) {
                      alert('Your password has been changed!');
                      $('form#tmpResetPasswordDialogue').CloseDialogue(true);
                    }
                  }
                );
              } else {
                alert('Password and Confirm Password do not match, please try entering your password again.');
                $('input#tmpResetPasswordConfirm').val('')
                $('input#tmpResetPassword').val('').focus();
              }
            } else {
              alert('No new password has been entered.');
            }
          }
        );
      }
    },

    CheckResponseCode : function($response)
    {
      var $error = '';
      switch (parseInt($response)) {
        case -6: {
          $error = "Your session has expired, please login again to continue.";
          break;
        };
        case -5: {
          $error = "Required information is missing from the request.";
          break;
        };
        case -1: {
          $error = "You are not authorized to perform this action.";
          break;
        };
        case -23: {
          $error = "Faux email address is not valid.";
          break;
        };
        case -13:
        case -14: {
          $error = "User already exists.";
          break;
        };
        case -500: {
          $error = "No trainer with that employee ID exists.";
          break;
        };
        case -501: {
          $error = "Employee cannot be assigned to that training module.";
          break;
        };
        case -502: {
          $error = "Training module does not exist.";
          break;
        };
        case -503: {
          $error =
            "Assigned trainer is not qualified to be a trainer for this training module\n" +
            "He/She has not previously completed the training.";
          break;
        };
        case -504: {
          $error =
            "You have failed to acheive at least a 70% score on the TIA Test, please try again.\n";
          break;
        }
      }

      if ($error) {
        alert((arguments[1]? arguments[1] : '') + $error);
        return false;
      }

      return true;
    }
  }
});

$(document).ready(
  function() {
    $$.tmp.Ready();
  }
);