// prepare the form when the DOM is ready
$(document).ready(function() {
    // bind form using ajaxForm
    $('#formContact').ajaxForm( {
		beforeSubmit:  validateContact,  		// pre-submit callback
		success:       showResponseContact,  	// post-submit callback
		clearForm: true        			// clear all form fields after successful submit
	});
});

function validateContact(formData, jqForm, options) {
    var nomeValue = $('input[id=contato_nome]').fieldValue();
    var emailValue = $('input[id=contato_email]').fieldValue();        
    var mensagemValue = $('textarea[id=contato_mensagem]').fieldValue();
    

    if (!nomeValue[0]) {
		alert('Por Favor Insira um Nome!');
		return false;
	}
    if (!emailValue[0]) {
		alert('Por Favor Insira um E-mail!');
		return false;
	}    
    if (!mensagemValue[0]) {
		alert('Por Favor Insira uma Mensagem!');
		return false;
	}    

	return true;


}





// post-submit callback
function showResponseContact(responseText, statusText, xhr, $form)  {
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server

    if (responseText == 1){
		alert("Seus dados foram cadastrados com sucesso. Obrigado!");
	} else {
		alert("Um erro ocorreu, tente novamente mais tarde por favor.");
	}
}
