$(function() {
    $('.erro').hide();

    $(".button").click(function() {
		// validate and process form
		// first hide any error messages
        $('.erro').hide();

	    var name = $("input#nome").val();
	    if (name == "") {
            $("span#erro_geral").show();
            $("input#nome").focus();
            return false;
        }

		var email = $("input#email").val();
		if (email == "") {
            $("span#erro_geral").show();
            $("input#email").focus();
            return false;
        }else if(!validaEmail(email)) {// Valida Através de E.R. a formatacao do E-mail
            $("span#erro_email").show();
            return false;
        }

        var mensagem = $("textarea#mensagem").val();
		if (mensagem == "") {
            $("span#erro_geral").show();
            $("textarea#mensagem").focus();
            return false;
        }

        $('#form').hide();
        $('#loading').show();


        $.ajax({
            type: "POST",
            url: "php/mail.php",
            async:true,
            data: { nome : $('#form form #nome').val(),
                    assunto : $('#form form #assunto').val(),
                    email : $('#form form #email').val(),
                    mensagem : $('#form form #mensagem').val()
            },
            success: function() { //Estou usando o complete pois estou sem a pagina php
            //complete: function(r) {
                $('#loading').hide();
                $('#success-msg').show();

            return true

                $('#contact_form').html("<div id='message'></div>");
                $('#message').html("<h2>Contact Form Submitted!</h2>")
               .append("<p>We will be in touch soon.</p>")
              .hide()
                .fadeIn(1500, function() {
                    $('#message').append("<img id='checkmark' src='images/check.png' />");
                 });
            },
            ajaxError: function(){
                $('#loading').hide();
                $('#error-msg').show();
            }

        });

        return false;
	});
});

//runOnLoad(function(){
//  $("input#name").select().focus();
//});


