
var selectorBox = new Array();
var selectorSpan = new Array();
window.onload = function() {
	selectorBox[1] = document.getElementById('selector1');
	selectorBox[2] = document.getElementById('selector2');
	selectorBox[3] = document.getElementById('selector3');

	selectorSpan[1] = document.getElementById('selector1span');
	selectorSpan[2] = document.getElementById('selector2span');
	selectorSpan[3] = document.getElementById('selector3span');
}

function updateProductSelector(numBox) {
	var selectedValue = new Array();
	selectedValue[1] = selectorBox[1].options[selectorBox[1].selectedIndex].value;
	selectedValue[2] = selectorBox[2].options[selectorBox[2].selectedIndex].value;
	selectedValue[3] = selectorBox[3].options[selectorBox[3].selectedIndex].value;

	var inputData = "";

	if (numBox == 1) inputData = inputData + "&box1=" + selectedValue[1];
	if (numBox == 2) inputData = inputData + "&box2=" + selectedValue[2];
	if (numBox == 3) inputData = inputData + "&box3=" + selectedValue[3];

	ajaxSendRequest("POST", "/wms_custom/shop/ajax_productselector.php", inputData, updateProductSelector_ajaxResponse);
}

function updateProductSelector_ajaxResponse(responseText) {
	if (responseText != "-ERR") {
		var boxData = eval("(" + responseText + ")");

		if (boxData['url']) {
			location.href = boxData['url'];
			return;
		} else {
			if (boxData['sourcebox'] == "3" || boxData['sourcebox'] == "2") {
				selectorSpan[1].style.display = '';
				selectorSpan[2].style.display = '';
				selectorSpan[3].style.display = '';
			} else if (boxData['sourcebox'] == "1") {
				selectorSpan[1].style.display = '';
				selectorSpan[2].style.display = '';
				selectorSpan[3].style.display = 'none';
			}

			var destinationBox = selectorBox[boxData['destinationbox']];
			destinationBox.options.length = 0;

			if (boxData['values'].length) {
				destinationBox.options[destinationBox.options.length] = new Option("- Select -", "");
				for(var c = 0; c < boxData['values'].length; c++) {
					var boxItem = boxData['values'][c];
					destinationBox.options[destinationBox.options.length] = new Option(boxItem['name'], boxItem['id']);
				}
			}
		}
	}
}
