﻿$(document).ready(function () {
  // Load dialog on page load
  //$('#basic-modal-content').modal();

  // Load login dialog on click
  $('.login_showmodal').click(function (e) {
    $('#basic-modal-content').modal({
      appendTo: 'Form',
      opacity: 80,
      overlayCss: { backgroundColor: "#000" },
      position: [200, 0]
    });
  });

  $(".login_submit").click(function () {
    $.ajax({
      type: "POST",
      url: "/login.aspx/Login",
      data: "{username: '" + $("#ctl00_TextBox_Username").val() + "', password: '" + $("#ctl00_TextBox_Password").val() + "'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
        // Do something interesting here.
        if (msg.d == "login") {
          window.location.replace("/members/my-account/");
        } else {
          $("#login_error").html(msg.d);
          $("#login_error").addClass('login_error');
        }
      }
    });
  });



  // Close login dialog and load forgot password dialog on click
  $('.forgotpassword_showmodal').click(function (e) {
    $.modal.close();
    setTimeout(function () {
      $('#basic-modal-content2').modal(
      {
        appendTo: 'Form',
        opacity: 80,
        overlayCss: { backgroundColor: "#000" },
        position: [200, 0]
      }
      );
    }, 20);
  });

  $(".forgotpassword_submit").click(function () {
    $.ajax({
      type: "POST",
      url: "/forgotpassword.aspx/ResetPassword",
      data: "{emailAddress: '" + $("#ctl00_TextBox_EmailAddress").val() + "'}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
        // Do something interesting here.
        if (msg.d == "success") {
          $("#forgotpassword_error").html("We've emailed you a new password!");
          $("#forgotpassword_error").addClass('login_success');
          $(".forgotpassword_submit").attr('style', 'display: none;');
        } else {
          $("#forgotpassword_error").html(msg.d);
          $("#forgotpassword_error").addClass('login_error');
        }
      }
    });
  });

});
