function updateCart() {
   $('formAction').value = 'updateCart';
   $('mainForm').submit();
}

function copyShippingToBilling() {
  $('bill_name_first').value = $F('ship_name_first');
  $('bill_name_last').value = $F('ship_name_last');
  $('bill_company').value = $F('ship_company');
  $('bill_address1').value = $F('ship_address1');
  $('bill_address2').value = $F('ship_address2');
  $('bill_city').value = $F('ship_city');
  $('bill_state').value = $F('ship_state');
  $('bill_postal_code').value = $F('ship_postal_code');
  $('bill_country').value = $F('ship_country');
  $('bill_phone').value = $F('ship_phone');
  $('bill_email').value = $F('ship_email');
}

function setupCategories() {
	var categories = $('categories_list');
	if(!categories) return;
	
	var node = categories.firstDescendant();
	
	setupCategories_Node(node);
}

function setupCategories_Node(node) {
	var children = node.immediateDescendants();
	var collapses = false;
	children.each(function(child) {
		if(child.tagName == 'UL') {
			var toggle = new Element('span').update('+');
			if(child.parentNode.hasClassName('active') || child.descendants().detect(function(e){return e.hasClassName('active');})) {
				toggle.update('-');
			}else{
				child.addClassName('closed');
			}
			child.parentNode.insertBefore(toggle,child.parentNode.firstDescendant());
			
			collapses = true;
			setupCategories_Node(child);
			Event.observe(toggle,'click',categoryToggleClick);
		}else if(child.tagName == 'LI') {
			setupCategories_Node(child);
		}
	});
	if(node.tagName == 'LI' && !collapses) {
		var toggle = new Element('span').update('&nbsp;');
		node.insertBefore(toggle,node.firstDescendant());
	}
}

function categoryToggleClick(evt) {
	var toggle = evt.target;
	if(toggle.innerHTML == '+') {
		toggle.update('-');
		toggle.parentNode.select('ul').first().removeClassName('closed');
	}else{
		toggle.update('+');
		toggle.parentNode.select('ul').first().addClassName('closed');
	}
}


Event.observe(window,'load',setupCategories);