var sBasketPage = 'update_basket.html';

function addToBasket(id) {
	document.location.href = sBasketPage+'?action=add&id='+id;
}

function deleteFromBasket(id) {
	document.location.href = sBasketPage+'?action=delete&id='+id;
}

function updateShipping(sDestination, sCategory) {
	var oDestination = document.forms[0].elements[sDestination]
	var iDestination = oDestination.options[oDestination.options.selectedIndex].value;
	
	var oCategory = document.forms[0].elements[sCategory];
	var iCategory = aOptions[iDestination][oCategory.options.selectedIndex].id;

	document.location.href = sBasketPage+'?action=shipping&destination='+iDestination+'&category='+iCategory;
}

SelectUtil = new Object();
SelectUtil.add = function(oList, sName, sValue) {
	if (!this.exists(oList, sValue)) {
		oOption = document.createElement('option');
		oOption.appendChild(document.createTextNode(sName));
		oOption.setAttribute("value", sValue);
	
		oList.appendChild(oOption);
	}
}
SelectUtil.empty = function(oList) {
	iLength = oList.options.length;
	for (var i = 0; i < iLength; i++) {
		oList.remove(0);
	}
}
SelectUtil.exists = function(oList, sValue) {
	for (var i = 0; i < oList.options.length; i++) {
		if (oList.options[i].value == sValue) return true;
	}
}
SelectUtil.getList = function(sName) {
	if (document.getElementById(sName)) {
		return document.getElementById(sName);
	} else if (document.forms[0].elements[sName]) {
		return document.forms[0].elements[sName];
	} else {
		alert('No object '+sName+' exists!');
		return;
	}
}
SelectUtil.getSelected = function(oList) {
	var aSelected = new Array();
	
	var i = 0;
	while (oList.options.selectedIndex != -1) {
		var oTmp = new Object();
		oTmp.text = oList.options[oList.options.selectedIndex].text;
		oTmp.value = oList.options[oList.options.selectedIndex].value;
		aSelected.push(oTmp);
		oList.options[oList.options.selectedIndex].selected = 0;
		i++;
	}
	
	if (aSelected.length == 0) alert('You currently have no options selected!');

	return aSelected;
}
SelectUtil.move = function(sFrom, sTo) {
	var oFrom = this.getList(sFrom);
	var oTo = this.getList(sTo);
	
	var aSelected = this.getSelected(oFrom);

	for (var i = 0; i < aSelected.length; i++) {
		this.add(oTo, aSelected[i].text, aSelected[i].value);
	}
}
SelectUtil.remove = function(sList) {
	var oList = this.getList(sList);
	while (oList.options.selectedIndex != -1) oList.remove(oList.options.selectedIndex);
}
SelectUtil.selectAll = function(sList) {
	var oList = this.getList(sList);
	for (var i = 0; i < oList.options.length; i++) {
		oList.options[i].selected = 1;
	}
}
