﻿var emailFilter = /^.+@.+\..{2,3}$/;

$(document).ready(function () {
    $('#sendEmail').click(function () {
        if ($("#email").val().length == 0 || $("#name").val().length == 0 || $("#message").val().length == 0) {
            alert("Please fill your email, name and message and send them to us.");
            return;
        }

        var email = $("#email").val();
        if (!emailFilter.test(email)) {
            alert("Your email is not valid.");
            return;
        }

        $.ajax({
            url: "../c/ajax_controller.py?",
            type: "get",
            data: 'method=send_message&email=' + $("#email").val() + '&from=' + $("#name").val() + '&msg=' + $("#message").val(),
            success: function (data) {
                //alert(data);
                $("#emailBox").html("Thank you for contacting us.<br/><br/>We will give you a feedback shortly.");
            },
            error: function (x, e, s) {
                alert(s);
            }
        });
    });
});
