$(document).ready(function() {
	$('.formOrcamento').bind( 'submit', function() { return validaOrcamento(); } );
	$('#orc_telefone').maskRvaz('(99) 9999-9999');
});

function validaOrcamento() {
	if( $.trim($('#orc_nome').val()) == '' ){
		$('#orc_nome').focus();
		mostraMsg('Digite seu nome');
		return false;
	}
	if( $('#orc_email').val() == '' ){
		$('#orc_email').focus();
		mostraMsg('Digite seu e-mail');
		return false;
	}
	else {
		if( !validaEmail($('#orc_email').val()) ){
			$('#orc_email').focus();
			mostraMsg('E-mail inválido');
			return false;
		}
	}
	if( $('#orc_telefone').val() == '' || $('#orc_telefone').val().length < 14 ){
		$('#orc_telefone').focus();
		mostraMsg('Digite seu telefone');
		return false;
	}
	if( $.trim($('#orc_mensagem').val()) == '' ){
		$('#orc_mensagem').focus();
		mostraMsg('Digite sua mensagem');
		return false;
	}
	$.ajax({
		type: 'POST',
		url:$('#form_orcamento').attr('action'),
		data:$('#form_orcamento').serializeArray(),
		beforeSend: function() {
			//$('.formOrcamento').fadeTo(100, 0.30);
		},
		success: function(data) {
			//$('.formOrcamento').fadeTo(100, 1);
			//$('.formOrcamento').hide('slow');
			if(data == 'erro') {
				$('.msgForm').addClass('erro').html('<p>O orçamento não foi enviado.</p>').css('margin', '0').show();
			} else {
				$('.msgForm').addClass('certo').html('<p>O orçamento foi enviado com sucesso.</p>').css('margin', '0').show();
				$('.formOrcamento input, .formOrcamento textarea').val('');
			}
		}
	});
	return false;
}
function mostraMsg(mensagem) {
	$('.formOrcamento .msgForm').html('<p>' + mensagem + '</p>').show('slow');
}
