function update() {
	form = getById('mainForm');
	form.submit();
}

function addToCart() {
	var found = false;
	for (var i = 1; i < 16; i++) {
		var select = getById('sizeSelect' + i);
		var quantity = getById('quantity' + i);

		if (select == null) {
			continue;
		}

		found = true;

		if (select.value < 1) {
			alert(msgNoSize);
			select.focus();
			return;
		}

		if (quantity.value < 1) {
			alert(msgNoQuantity);
			quantity.focus();
			return;
		}
	}

	if (!found) {
		alert(msgNotFound);
		return;
	}

	form = getById('mainForm');
	action = getById('action');
	action.value = 'QuickOrder.addToCart';
	form.submit();
}

function resetForm() {
	if (confirm(msgResetForm)) {
		window.location.href = '?action=QuickOrder';
	}
}

function onCupSelect(select) {
	var idx = select.id.substr(4);
	populateNrSelect(idx);
}

function populateNrSelect(idx) {
	var cupSelect = getById('cups' + idx);
	if (cupSelect == null) return;
	var sizes = eval('sizeList' + idx);
	if (sizes == null) return;

	var select = getById('sizeSelect' + idx);

	var selSize = getById('selSize' + idx).value;

	select.options.length = 1;
	select.options[0] = new Option(msgChooseSize, 0);

	groupName = cupSelect.options[cupSelect.selectedIndex].value;
	for (var curGroup in sizes) {
		if (curGroup == groupName) {
			var group = sizes[curGroup];
			for (var size in group) {
				select.options[select.options.length] = new Option(size, size);
			}
		}
	}

	select.options.selectedIndex = 0;
	for (var i = 0; i < select.options.length; i++) {
		if (select.options[i].value == selSize) {
			select.options.selectedIndex = i;
			break;
		}
	}

	return;
}

function init() {
	for (var i = 1; i < 16; i++) {
		populateNrSelect(i);
	}
}

window.onload = init;
