﻿$(document).ready(function () {
    $('.btnlogin').click(function (e) {
        var hdnReturnURL = $('#hdnReturnURL').val();
        var EMAIL = $('#inputEmail').val();
        var PASS = $('#inputPassword').val();
        e.preventDefault();
        if (EMAIL == "") {
            $('#inputEmail').focus(); return false;
        }
        if (PASS == "") {
            $('#inputPassword').focus(); return false;
        }
        if (EMAIL != "" && PASS != "") {
            $('.btnlogin').hide();
            $('.loader').show();
            //------------------
            $.ajax(
                      {
                          type: "POST",
                          url: "../home/login",
                          data: "{'EMAIL':'" + EMAIL + "','PASS':'" + PASS + "'}",
                          contentType: "application/json; charset=utf-8",
                          async: "true",
                          cache: "false",
                          success: function (msg) {
                              if (msg == "true" && hdnReturnURL=="") {
                                  location.replace('../home/index');
                              }
                              else if (msg == "true" && hdnReturnURL != "") {
                                  location.replace(hdnReturnURL);
                              }
                              else {
                                  swal("Incorrect Email ID / Password !", "", "error")
                                  $('.btnlogin').show();
                                  $('.loader').hide();

                              }
                          }
                      });
            //--------------
        }
    });
    //----------------------REGISTRATION------------------
    $('.btnsignup').click(function (e) {
        e.preventDefault();
        var inputName = $('#inputName').val();
        var inputMobile = $('#inputMobile').val();
        var EMAIL = $('#inputEmailnew').val();
        var PASS = $('#inputPasswordnew').val();
        var CPASS = $('#inputPasswordconfirm').val();
        if (inputName == "") {
            $('#inputName').focus(); return false;
        }
        if (inputMobile == "") {
            $('#inputMobile').focus(); return false;
        }
        if (EMAIL == "") {
            $('#inputEmailnew').focus(); return false;
        }
        if (PASS == "") {
            $('#inputPasswordnew').focus(); return false;
        }
        if (CPASS == "") {
            $('#inputPasswordconfirm').focus(); return false;
        }
        if (PASS != CPASS) {
            $('#inputPasswordconfirm').val('');
            $('#inputPasswordconfirm').focus(); return false;
        }
        if (EMAIL != "" && PASS != "") {
            $('.btnsignup').hide();
            $('.loader2').show();
            $.ajax(
                      {
                          type: "POST",
                          url: "../home/register",
                          data: "{'EMAIL':'" + EMAIL + "','PASS':'" + PASS + "','inputName':'" + inputName + "','inputMobile':'" + inputMobile + "'}",
                          contentType: "application/json; charset=utf-8",
                          async: "true",
                          cache: "false",
                          success: function (msg) {
                              if (msg == "true") {
                                  swal("Successfully Registered, Please login your account !", "", "success")
                                  setTimeout(function () {
                                      location.replace('../home/login');
                                  }, 2000);
                                  $('.btnsignup').show();
                                  $('.loader2').hide();
                              }
                              else {
                                  swal(msg, "", "error")
                                  $('.btnsignup').show();
                                  $('.loader2').hide();
                              }
                          }
                      });
        }
    });

    //--------------------------------
});
