$(document).ready(function(){
	
	// On choisit la marque
	// --------------------
	$('#ReferenceMarqueId').change(function(){
	
		// Màj Types
		$.post(
			$('#ReferenceUpdateTypesFromMarqueUrl').val(),
			{
				marque_id: $(this).val(),
				type_id:   $('#ReferenceTypeId').val()
			},
			function(data){ $('#ReferenceTypeId').html(data); },
			'html'
		);
		
		// Màj Gammes
		$.post(
			$('#ReferenceUpdateGammesFromMarqueUrl').val(),
			{
				marque_id: $(this).val(),
				gamme_id:  $('#ReferenceGammeId').val()
			},
			function(data){ $('#ReferenceGammeId').html(data); },
			'html'
		);
	});
	
	// On choisit le type
	// ------------------
	$('#ReferenceTypeId').change(function(){
	
		// Màj Marques
		$.post(
			$('#ReferenceUpdateMarquesFromTypeUrl').val(),
			{
				type_id:   $(this).val(),
				marque_id: $('#ReferenceMarqueId').val()
			},
			function(data){ $('#ReferenceMarqueId').html(data); },
			'html'
		);
		
		// Màj Gammes
		$.post(
			$('#ReferenceUpdateGammesFromTypeUrl').val(),
			{
				type_id:  $(this).val(),
				gamme_id: $('#ReferenceGammeId').val()
			},
			function(data){ $('#ReferenceGammeId').html(data); },
			'html'
		);
	});
	
	// On choisit la gamme
	// -------------------
	$('#ReferenceGammeId').change(function(){
	
		// Màj Marques
		$.post(
			$('#ReferenceUpdateMarquesFromGammeUrl').val(),
			{
				gamme_id:  $(this).val(),
				marque_id: $('#ReferenceMarqueId').val()
			},
			function(data){ $('#ReferenceMarqueId').html(data); },
			'html'
		);
		
		// Màj Types
		$.post(
			$('#ReferenceUpdateTypesFromGammeUrl').val(),
			{
				gamme_id: $(this).val(),
				type_id:  $('#ReferenceTypeId').val()
			},
			function(data){ $('#ReferenceTypeId').html(data); },
			'html'
		);
	});
});