jQuery(document).ready(function() {
	jQuery('input[title*=postcode], input#zipcode').mask('99999-999', {placeholder:"_"});
	
	jQuery("#change_country").attr("onclick", "return false");
	jQuery("input[name=wpsc_submit_zipcode]").click(function() {
		valida_cep();
	});
	
	jQuery("input#zipcode").keydown(function(e) {
		//if (e.keyCode==13) valida_cep();
	}); 
	jQuery("form.wpsc_checkout_forms").attr("onSubmit", "return validaFrete()");

	

	
});

function valida_cep() {
	zip = jQuery.trim(jQuery('input#zipcode').val());
	if ((zip=="") || (zip=="_____-___") || (zip=="     -   ")) {
		alert("Preencha o CEP");
		return;
	}
	document.forms['change_country'].submit();	
}


function validaFrete() {
	
	valorFrete = document.getElementById("checkout_shipping").textContent;
	if(valorFrete == "R$0.00"){
		alert("Para finalizar a compra, é necessario calcular o frete");
		return false;
	}	
}

