$(document).ready(function(){
	$("#error-message").css({'opacity':0, 'height':0});
	$("#feedback").fadeOut();
	$('#estimate-form').validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? "There is a problem with one field. It has been highlighted for you."
					: "There is a problem with " + errors + " fields. They have been highlighted for you.";
				$("#error-message div").html(message);
				
				var scrollDest = $("#error-message").offset().top;
				
				$('html, body').animate({
					scrollTop: scrollDest - 50
				}, 500, function() {
					$("#error-message").animate({
						opacity: 1,
						height: 30
					})
				});
			} else {
				$("#error-message").fadeTo(0);
			}
		},
		submitHandler: function(form){
			var options = {
				target: "#feedback",
				success: function(){
					$(form).clearForm();
					setTimeout(function(){ $("#feedback").fadeOut() }, 5000);
				}
			}
			$(form).ajaxSubmit(options);
			$("#feedback").html("Sending...");
			$("#feedback").fadeIn();
			
			return false;
		}
	});
	$('input.phone').mask('(999) 999.9999', { placeholder:" " });
	$('input.zip').mask('99999', { placeholder:"" });
	$('input.state').mask('aa', { placeholder:"" });
});

function toUpper(id) {
	$('#'+id).val($('#'+id).val().toUpperCase());
}

function getCityState(code) {
	/*
	$.get('http://geocoder.us/service/csv/geocode', { zip : code }, function(data) {
		alert(data);
	})
	
	$.ajax({
	  url: 'http://geocoder.us/service/csv/geocode?zip=92008',
	  dataType: "text",
	  success: function(data) {
	    //$("#response").html(data);
	    //alert("response:" + data);
	  }
	});
	*/
}
