$(document).ready(function(){
	$("#frmCalculaFrete").submit(function(){
		var cep1 = $("#inpCep1").val();
		var cep2 = $("#inpCep2").val();
		var produto = $("#inpProduto").val();
		
		if (cep1 == ""){
			alert("Informe seu cep");
			$("#inpCep1").focus();
			return false;
		}
		if (cep2 == ""){
			alert("Informe seu cep");
			$("#inpCep2").focus();
			return false;
		}
		
		var pCep = cep1 + "" + cep2;
		
		$("#boxContentFrete").fadeOut(function(){
			$("#boxContentValorFreteLoading").fadeIn();
		});
		
		$.post('../ajax-calcula-frete.php', {cep:pCep, produto:produto},function(data){
			if (data) {
				$("#boxContentValorFreteLoading").fadeOut(function(){
					$("#boxContentValorFrete").html(data);
					$("#boxContentValorFrete").fadeIn();
					
					$("#linkCalcularFrete").click(function(){
						$("#boxContentValorFrete").fadeOut(function(){
							$("#boxContentFrete").fadeIn();
							$("#inpCep1").val("");
							$("#inpCep2").val("");
							$("#inpCep1").focus();
						});	
						return false;				
					});
				});		
			}else{
				alert("Não foi possível calcular o frete.");
				$("#boxContentFrete").fadeIn();
			}	
		});
		
		return false;
	});
});

