$(function() 
{
    $('.form_error').hide();

    $(".submit_btn").click(function() 
    {
        $('.form_error').hide();
        var name = $("input#contact_name").val();
        if (name == "") 
        {
            $("label#name_error").show();
            $("input#contact_name").focus();
            return false;
        }
        var email = $("input#contact_email").val();
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z]{2,4})+$/;
        if ( (email == "") || (!filter.test(email))) 
        {
            $("label#email_error").show();
            $("input#contact_email").focus();
            return false;
        }
        var comments = $("textarea#contact_comments").val();
        if (comments == "") 
        {
            $("label#comments_error").show();
            $("textarea#contact_comments").focus();
            return false;
        }
        var captcha = $("input#captcha_code").val();        
        var dataString = 'name='+ name + '&email=' + email + '&captcha_code=' + captcha +'&comments=' + comments;
        $.ajax(
        {
            type: "POST",
            url: "contact.php",
            data: dataString,
            success: function(result) 
            {
                if(result == 1)
                {
                    $('#contact_form').html("<div id='message'></div>");
                    $('#message').html("<h4 class='auriga_red'>Thank you for your comments.</h4>")
                        .append("<p>We will be in touch with you soon.</p>")
                        .hide()
                        .fadeIn(1500, function(){})
                } else alert("The code you entered does not match the image. Please try again");
            }
        });
        return false;
    });
});

