












$(document).ready(function()
{
    
    $("#SignInForm").validate
    ({
        rules: 
        {
            email: 
            {
                required: true,
                email: true
            },
            password: 
            {
                required: true,
                minlength: 6
            }
        },
        messages: 
        {
            email: 
            {
                required: "Please enter an email address",
                email: "Please enter a valid email address"
            },
            password: 
            {
                required: "Please provide a password",
                minlength: "Your password must be at least 6 characters    long"
            },
        },
    });




    $("#SignInForm").on("submit", function(e)
    {
        e.preventDefault();
        var FS      =   $(this).valid();
        var FORM    =   $(this)[0];
        if((FS))
        {
            var data = new FormData(FORM);
            data.append("request", "signin");
            $("#SignInFormSB").prop("disabled", true);
            $.ajax
            ({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "../controllers/signin.php",
                data: data,
                processData: false,
                contentType: false,
                cache: false,
                timeout: 600000,
                async: true,
                success: function (response) 
                {
                    response    =   JSON.parse(response);
                    if((response["error"] == false))
                    {
                        if((response["R_URL"]))
                        {
                            window.location.href    =   response["R_URL"];
                        }
                    }
                    else
                    {
                        alert(response["error_msg"]);
                    }
                    $("#SignInFormSB").prop("disabled", false);

                },
                error: function (e) 
                {
                    $("#result").text(e.responseText);
                    console.log("ERROR : ", e);
                    $("#btnSubmit").prop("disabled", false);
                }
            });
        }
    });





});