












$(document).ready(function()
{
    
    $("#SignUpForm").validate
    ({
        rules: 
        {
            firstname: 
            {
                required: true,
            },
            lastname: 
            {
                required: true,
            },
            email: 
            {
                required: true,
            },
            password: 
            {
                required: true,
            }
        },
        messages: 
        {
            firstname: 
            {
                required: "First Name is required",
            },
            lastname: 
            {
                required: "Last Name is required",
            },
            email: 
            {
                required: "Email is required",
            },
            password: 
            {
                required: "Password is required",
            }
        },
    });




    $("#SignUpForm").on("submit", function(e)
    {
        e.preventDefault();
        var FS      =   $(this).valid();
        var FORM    =   $(this)[0];
        if((FS))
        {
            var data = new FormData(FORM);
            data.append("request", "signup");
            $("#SignInFormSB").prop("disabled", true);
            $.ajax
            ({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "../controllers/signup.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["message"]))
                        {
                            alert(response["message"]);
                        }
                        if((response["R_URL"]))
                        {
                            window.location.href    =   response["R_URL"];
                        }
                    }
                    else
                    {
                        alert(response["error_msg"]);
                    }
                    $("#SignUpFormSB").prop("disabled", false);

                },
                error: function (e) 
                {
                    $("#SignUpFormSB").prop("disabled", false);
                }
            });
        }
    });





});