<script type="text/javascript">
	$(document).ready(function() {
		$(".VariationSelect:gt(0)").attr('disabled', 'disabled');
	});

	$(".VariationSelect").change(function() {
		var index = $('.VariationSelect').index($(this));
		if (this.selectedIndex == 0) {
			$('.VariationSelect:gt(' + index + ')').each(function() {
				$(this).attr('disabled', 'disabled');
			});

			updateSelectedVariation($('body'));
			return;
		} else {
			$('.VariationSelect:gt(' + (index + 1) + ')').attr('disabled', 'disabled');
		}

		var optionIds = '';
		$('.VariationSelect:lt(' + (index + 1) + ')').each(function() {
			if (optionIds != '') {
				optionIds += ',';
			}

			optionIds += $(this).val();
		});

		$.getJSON(
			'{{ ShopPath|safe }}/remote.php?w=GetVariationOptions&productId={{ ProductId|safe }}&options=' + optionIds,
			function(data) {
				if (data.hasOptions) {
					$('.VariationSelect:eq(' + (index + 1) + ') option:gt(0)').remove();
					$('.VariationSelect:eq(' + (index + 1) + ')').append(data.options).attr('disabled', '').focus();
				} else if (data.comboFound) {
					updateSelectedVariation($('body'), data, data.combinationid);
				}
			}
		);
	});
</script>