$(document).ready(
	function() {
		
		year_make_model_assign_events();
		
	}
);

function year_make_model_assign_events() {
	
	$("#id_year").blur(vehicle_year_changed);
	$("#id_make").blur(vehicle_make_changed);
	$("#id_model").blur(vehicle_model_changed);

}

function vehicle_year_changed() {
	
	update_make_dropdown();
	update_model_dropdown();
	
}

function update_year_dropdown() {
	$.post(
		"/info/ajax-narrow-years/",
		{
			'id_year' : $("#id_year").val(),
			'id_make' : $("#id_make").val(),
			'id_model' : $("#id_model").val()
		},
		function(data) {
			$("#id_year").html(data);
		}
	);
}

function vehicle_make_changed() {
	
	update_year_dropdown();
	update_model_dropdown();
	
}

function update_make_dropdown() {
	$.post(
		"/info/ajax-narrow-makes/",
		{
			'id_year' : $("#id_year").val(),
			'id_make' : $("#id_make").val(),
			'id_model' : $("#id_model").val()
		},
		function(data) {
			$("#id_make").html(data);
		}
	);
}

function vehicle_model_changed() {
	
	update_year_dropdown();
	update_make_dropdown();
	
}

function update_model_dropdown() {
	$.post(
		"/info/ajax-narrow-models/",
		{
			'id_year' : $("#id_year").val(),
			'id_make' : $("#id_make").val(),
			'id_model' : $("#id_model").val()
		},
		function(data) {
			$("#id_model").html(data);
		}
	);
}
