(function ($) {
    "use strict";

    var base_url = 'https://cespakistan.com/';
    // var base_url = 'http://127.0.0.1:8000/';

    $(document).on('click', '.contact_btn', function(event) {

        event.preventDefault();

        if($('.contact_name').val() == "")return alert_msg('Please enter your name.');
        var email = $('.contact_email').val();
        if(email == "")return alert_msg('Please enter your email.');
        var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        if(!regex.test(email)) return alert_msg('You have entered an invalid email address!');
        if($('.contact_subject').val() == "")return alert_msg('Please enter subject.');
        if($('.contact_message').val() == "")return alert_msg('Please enter your message.');

        $.ajax({
            url: base_url + "saveContact",
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            type: "post",
            data: $(".contact-form").serialize(),
            dataType: "json",
            success: function(result) {
                if(result.status == true) {
                    alert_msg('Your message has been saved.','success');
                    $('.contact_name').val('')
                    $('.contact_email').val('')
                    $('.contact_subject').val('')
                    $('.contact_message').val('')
                    return true;
                }
                alert_msg(result.message);
                return false;
            }
        });

    });

    function alert_msg(message,type_of_message){
        if (typeof(type_of_message)==='undefined') type_of_message = 'error';
        var n = noty({
            timeout: 5000,
            text: message,
            type:type_of_message,//alert, success, error, warning, information, confirm
            layout: 'topRight',
            maxVisible: 5, // you can set max visible notification for dismissQueue true option,

        });
    }

})(jQuery);
