﻿$(document).ready(function() {
    $("#send").click(function() {
        sendContact();
    });

    var sendContact = function() {
        var contact = new Object();

        contact.FullName = $("#fullname").val();
        contact.Email = $("#email").val();
        contact.Subject = $("#subject").val();
        contact.Message = $("#message").val();

        var data = new Object();
        data.contact = contact;

        $.ajax({
            type: "POST",
            url: "/Proxy.asmx/SendContact",
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function() {
                $("#send").unbind().click(function() { return false; });
            },
            success: function(msg) {
                if (msg.status == "1") {
                    $("#step1").hide();
                    $("#step2").show();
                }
                else if (msg.status == "2") {
                    alert("Please fill in all required fields");
                    $("#send").unbind().click(function() { sendContact(); });
                }
                else {
                    alert("An unexpected error occured. Please try again later");
                    $("#send").unbind().click(function() { sendContact(); });
                }
            },
            error: function() {
                alert("An unexpected error occured. Please try again later");
                $("#send").unbind().click(function() { sendContact(); });
            }
        });
    }   
});