$(document).ready(function(){
    $(".nav-contact-form input[type=text], .nav-contact-form textarea").focus(function(){
        if(this.value == $(this).attr('title')) this.value = '';
        $(this).removeClass('error');
    });
    $(".nav-contact-form input[type=text], .nav-contact-form textarea").blur(function(){
        if(this.value == '') this.value = $(this).attr('title');
        $(this).removeClass('error');
    });
    
    $('.nav-contact-form').submit(function(){
        $('.ajax-loader').show();
        var has_error = false;
        $(".nav-contact-form input[type=text], .nav-contact-form textarea").each(function(i,elem){
            if(elem.value == '' || elem.value == $(elem).attr('title')) {
                $(elem).addClass('error');
                has_error = true;
            }
        });
        
        if(!has_error) {
            $.post("/lead.php",
                $(".nav-contact-form").serialize(),
                function(data) {
                    console.log(data);
                }
            );
            $('.nav-contact-form').fadeOut();
            $('.contactbox p').fadeOut();
            $('.wpcf7-response-output').html('Thank you for your submission!');
        }
        $('.ajax-loader').hide();
        return false;
    });
});
