$(document).ready(function() {
    // Stuff to do as soon as the DOM is ready;
    $('#phone').mask("(999) 999-9999");
    
    $('#contactform').submit(function(){
        var datacon = $(this).serialize();
                var URL = $(this).attr('action');
                var notice = $('#note');
                clearNotice(notice);

                //$('#message').empty();
                $.ajax({
                    type: 'POST',
                      url: URL,
                      data: datacon,
                    success: function(data) {
                        if(data.match(/OK/)) {
                            $('#contactform').hide();
                            $('#thank-you').show('slow');}
                        else {
                            clearNotice(notice);
                            notice.addClass('error');
                            notice.html(data);
                            notice.show();}
                        }
                });
                  return false;
    });
    
    function clearNotice() {
        $('#note').empty();
        if($('#note').hasClass('error')) {
            $('#note').removeClass('error');
        }
    }
});

