$(document).ready(function(){
// 
	$("#enviaOrcamento").bind('click', function() {
		var erro = false;																	  
		
		var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	 	if (!regmail.test($("input[name='email']").val())) {
	 		alert("E-mail inválido");
		   	erro = true;			
     	}
	 	
	 	if(!erro){
			$.ajax({
				type: "POST",
				async:false,
				url: "php/enviaOrcamento.php",
				cache: false,
				data: {
					nome: $("input[name='nome']").val(), 
					email: $("input[name='email']").val(),				
					empresa: $("input[name='empresa']").val(),
					estado: $("input[name='estado']").val(),
					cidade: $("input[name='cidade']").val()},				
				context: document.body, 
				success: function(retorno){	
					retorno = retorno.trim();					
					if (retorno == "OK") {					
						alert('Sua mensagem foi enviada. \nAguarde o contato da nossa equipe.');
						$("input[name='nome']").val('');
						$("input[name='email']").val('');					
						$("input[name='empresa']").val('');
						$("input[name='estado']").val('');
						$("input[name='cidade']").val('');
						var url = "../index.php";    
						$(location).attr('href',url);
					}else{
						alert('Não foi possível enviar sua mensagem.');
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					alert('Não foi possível enviar sua mensagem.');
				}
			});
	 	}
	});
	
	
	
	
	
	$("#orcamento input").each(function(){
		$(this).blur(function(){
			dados();
		})
	});
	
	function dados(){
		$.ajax({
			type: "POST",
	        url: "formOrcamento.php",
	        data: {
				nome: $("#nome").val(),
				email: $("#email").val(),
				empresa: $("#empresa").val(),
				estado: $("#estado").val(),
				cidade: $("#cidade").val(),
			}
	    });
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
});
			
