$(document).ready(function()
{
    $(".submit").click(function()
    {
        if(greatliving.validForm())
        {
            var url = base_url + "contact/sendMail";
            var data = $("#mainContact").serialize();

            $.post(url, data, function(result)
            {

                if(result.error)
                {
					$("#result").html("<h3 class='result'>"+result.message+"</h3> ");
                }
                else
                {
     				window.location = result.message;
                }


            }, "json");//text is the response from the server
        }
        //if it was not a valid form
        else
        {
            $("#result").html("<h3 class='result'>Please enter all required fields</h3>");
        }

        return false;
    });
});

