<!--
/* add to the selected items */
function addAttribute(fromList,toList) {
	var selectedList;
	var availableList;
	availableList = document.getElementById(fromList);
	selectedList = document.getElementById(toList);
	
   var addIndex = availableList.selectedIndex;
   if (addIndex < 0)
	return;
	
   var intTargetLen;

   for (i=0; i < availableList.options.length; i++) {
		if (availableList.options[i].selected == true) {
		   intTargetLen = selectedList.length++;
		   selectedList.options[intTargetLen].text = availableList.options[i].text;
		   selectedList.options[intTargetLen].value = availableList.options[i].value;
		}
   }
}

/* add to the available options */
function delAttribute(toList) {
	var selectedList;
	selectedList = document.getElementById(toList);
	var selIndex = selectedList.selectedIndex;
	if (selIndex < 0)
		return;
	
	var onesToDelete = new Array();
	
	for (i=0; i < selectedList.options.length; i++) {
		if (selectedList.options[i].selected == true) {
			onesToDelete[onesToDelete.length] = selectedList.options[i].value;
			//selectedList.options[i] = null;
		}
	}
	
	for (i=0; i < onesToDelete.length; i++) {
		// loop through options
		//alert(onesToDelete[i]);
		for (j=0; j < selectedList.options.length; j++) {
			if ((selectedList.options[j].selected == true) && (selectedList.options[j].value == onesToDelete[i])) {
				selectedList.options[j] = null;
			}
		}
	}
}

function addProteinCarb(fromList,toList) {
	var selectedList;
	var availableList;
	availableList = document.getElementById(fromList);
	selectedList = document.getElementById(toList);
	
   var addIndex = availableList.selectedIndex;
   if (addIndex < 0)
	return;
   var intTargetLen;

   for (i=0; i < availableList.options.length; i ++) {
		if (availableList.options[i].selected == true) {
		   intTargetLen = selectedList.length++;
		   selectedList.options[intTargetLen].text = availableList.options[i].text;
		   selectedList.options[intTargetLen].value = availableList.options[i].value;
		}
   }
}

function removeProteinCarb(toList) {
	var selectedList;
	selectedList = document.getElementById(toList);
	var selIndex = selectedList.selectedIndex;
	if (selIndex < 0)
		return;
	selectedList.options[selIndex] = null;

	var onesToDelete = new Array();
	
	for (i=0; i < selectedList.options.length; i++) {
		if (selectedList.options[i].selected == true) {
			onesToDelete[onesToDelete.length] = selectedList.options[i].value;
			//selectedList.options[i] = null;
		}
	}
	
	for (i=0; i < onesToDelete.length; i++) {
		// loop through options
		//alert(onesToDelete[i]);
		for (j=0; j < selectedList.options.length; j++) {
			if ((selectedList.options[j].selected == true) && (selectedList.options[j].value == onesToDelete[i])) {
				selectedList.options[j] = null;
			}
		}
	}
}

/* make sure nothing is selected */
function selectNone(availableList,selectedList) {
	availableList.selectedIndex = -1;
	selectedList.selectedIndex = -1;
}

/* set the category list */
function setCategory(selectedOptions,holderText) {
	var catValue = "";
	for (i=0; i < selectedOptions.length; i++) 	{
		catValue += selectedOptions[i].value;
	
		if (i != selectedOptions.length) {
			catValue += ',';
		}
	}
	
	holderText.value = catValue;
	if (selectedOptions.length == 7) {
		if (selectedOptions.name == 'protein_breakfast_s') {
			document.form1.carb_breakfast_a.selectedIndex = 0;
			document.form1.carb_breakfast_a.focus();
		}
		else if (selectedOptions.name == 'carb_breakfast_s') {
			document.form1.snack_am_a.selectedIndex = 0;
			document.form1.snack_am_a.focus();
		}
		else if (selectedOptions.name == 'snack_am_s') {
			document.form1.protein_lunch_a.selectedIndex = 0;
			document.form1.protein_lunch_a.focus();
		}
		else if (selectedOptions.name == 'protein_lunch_s') {
			document.form1.carb_lunch_a.selectedIndex = 0;
			document.form1.carb_lunch_a.focus();
		}
		else if (selectedOptions.name == 'carb_lunch_s') {
			document.form1.protein_dinner_a.selectedIndex = 0;
			document.form1.protein_dinner_a.focus();
		}
		else if (selectedOptions.name == 'protein_dinner_s') {
			document.form1.carb_dinner_a.selectedIndex = 0;
			document.form1.carb_dinner_a.focus();
		}
	}
}

/* change the order of the options */
function changeOrder(opList,dir) {
	var cOption; // the cmoponent
	var sIndex; // selected option
	var oText; // original text of the option
	var oValue; // original value of the option
	
	cOption = document.getElementById(opList);
	sIndex = cOption.selectedIndex;
	
	if (sIndex != -1 && cOption.options[sIndex].value > "") {
		oText = cOption.options[sIndex].text;
		oValue = cOption.options[sIndex].value;
		
		if (cOption.options[sIndex].value > "" && sIndex > 0 && dir == 0) {
			cOption.options[sIndex].text = cOption.options[sIndex-1].text;
			cOption.options[sIndex].value = cOption.options[sIndex-1].value;
			cOption.options[sIndex-1].text = oText;
			cOption.options[sIndex-1].value = oValue;
			cOption.options.selectedIndex--;
		}
		else if (sIndex < cOption.length-1 && cOption.options[sIndex+1].value > "" && dir == 1) {
			cOption.options[sIndex].text = cOption.options[sIndex+1].text;
			cOption.options[sIndex].value = cOption.options[sIndex+1].value;
			cOption.options[sIndex+1].text = oText;
			cOption.options[sIndex+1].value = oValue;
			cOption.options.selectedIndex++;
		}
	} else {
			alert("Please make a selection");
	}
}

/* tabbed interface */
var activePane = 1;
function showPane(catNum) {
	var oldPane = "cat" + activePane;
	var newPane = "cat" + catNum;
	
	document.getElementById(oldPane).style.display = 'none';
	document.getElementById(newPane).style.display = 'block';
	
	activePane = catNum;
}

/* phone number changer */
function goNext(theForm,currentBox,toBox) {
	if (currentBox.value.length == '3') {
		toBox.focus();
	}
}
//-->