$(function() {
	$(".retornoCont a").click(function() {
		$(".retornoCont").hide();
		$("form.frmCont").fadeIn();
	});
	$('form.frmCont .btnEnviar').click(function () {
		temerro = "";
		var frmCont = document.frmCont;
		
		if (frmCont.nome.value == "Nome") {
			temerro = 1;
			$("form.frmCont #nome").addClass("inputErro");
		}else{
			$("form.frmCont #nome").removeClass("inputErro");
		}

		/*if (frmCont.telefone.value == "Telefone") {
			temerro = 1;
			$("form.frmCont #telefone").addClass("inputErro");
		}else{
			$("form.frmCont #telefone").removeClass("inputErro");
		}
*/
		if (frmCont.mensagem.value == "Mensagem") {
			temerro = 1;
			$("form.frmCont .textarea").addClass("inputErro");
		}else{
			$("form.frmCont .textarea").removeClass("inputErro");
		}

		if (frmCont.emailCont.value.indexOf("@") == -1 ||
			frmCont.emailCont.value.indexOf(".") == -1 ||
			frmCont.emailCont.value.indexOf(" ") != -1 || 
			frmCont.emailCont.value.length < 6) 
		{
			temerro = 1;
			$("form.frmCont #emailCont").addClass("inputErro");
		}else{
			$("form.frmCont #emailCont").removeClass("inputErro");
		};
		
		if(temerro != ""){
			$(".frmCont .alertErro").fadeIn();
		}
		else {
			var params = $("#frmCont").serialize();
			jQuery.ajax({
			data: params,
			type: 'POST',
			url: 'grava_contato.php',
			timeout: 5000,
			error: function() {
				alert("Houve algum erro");
			},
			success: function() {
//				alert("Dados enviados com sucesso!");
				$("form.frmCont").hide();
				$(".retornoCont").fadeIn();
				$(".frmCont .alertErro").hide();
				document.frmCont.reset();
				}
			})
			//document.frmCont.submit();
		}
	});
});

