﻿function respostaSucesso() {
	$("#resposta_frete").hide();
	$("#resposta_frete").fadeIn('slow'); 
}

function valoresDimensoes(linkatual, comprimento, largura, altura) {
	//Função automatisa processo de preencher valores das dimensões
	document.getElementById("comprimento").value = comprimento;
	document.getElementById("largura").value = largura;
	document.getElementById("altura").value = altura;
}
//<!--[if ie6]
//(document.getElementById("img_prd").width > 210)? "210px" : "auto";
//(document.getElementById("img_prd").height > 210)? "210px" : "auto";

jQuery(function() {
		// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="imgs/loading.gif" alt="Carregando..." /></div>')
			.css({position: "relative", top: "1em", left: "25em"})
			.appendTo("#resposta_frete")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		var v = jQuery("#form-calcula-frete").validate({
			rules:{
				cepdestinatario: {
					required: true,
					minlength: 8
				},
				quantidade: {
					required: true,
					minlength: 1
				}
			},
			messages: {
				cepdestinatario: {
					required: "Por favor, digite seu CEP sem hífen e com 8 dígitos.",
					minlength: "Digite um CEP válido de 8 dígitos"
				},
				quantidade: {
					required: "Informe a quantidade de produtos.",
					minlength: "Quantidade deve ser de pelo menos 1 produto."
				}
			},
			errorLabelContainer: $("div#erros"),

			submitHandler: function(form) {
				jQuery(form).ajaxSubmit({
					target: "#resposta_frete",
					success: respostaSucesso
				});
			}
		});
		
		jQuery("#reset").click(function() {
			v.resetForm();
		});
	});

