<!--
/**
 * generateMenu
 * arr ~ array that pass to the function
 * toMenu ~ the destination that the array will shown, typically a "select" object
 * ignoreIndex ~ this is used when a item is selected from the list, the selected item
 *               would not show in the orginal list
 */
function generateMenu(arrValue, arrText, toMenu, ignoreIndex){
	var i = 0;
	var newFromArr	= new Array();
	
	if (ignoreIndex == null){									// ignoreIndex = null
		for (i = 0; i < arrValue.length; i++){						// the first time menu generation
			var opt = new Option();
			opt.value	= arrValue[i];
			opt.text	= arrText[i];

			toMenu[toMenu.length] = opt;
		}
	} else {													// there have a item selected
		for (i = 0; i < toMenu.length; i++){					// get the original list except the selected item
			if (ignoreIndex == i){
				newFromArr[i] = "";
			} else{
				newFromArr[i] = toMenu.options[i].text;
			}
		}
			
		toMenu.length = 0;
		
		for (i = 0; i < newFromArr.length; i++){				// re-generate the new from menu list
			if (newFromArr[i] != ""){
				var opt = new Option();
				opt.value	= i + 1;
				opt.text	= newFromArr[i];
				
				toMenu[toMenu.length] = opt;
			}
		}
	}
}

function move(fromList, toList, max, arrValue, arrText){
	var iSelectedIndex	= fromList.selectedIndex;
	var toListLength		= toList.options.length;
	var toListValue			= new Array();
	var toListText			= new Array();
	var opt							= new Option();

	if (iSelectedIndex != -1){

		/* @ this rule will only apply to the SelectedMenu */
		if (toList.name.indexOf("Selected") != -1){
			/* @ case: user have selected "ALL" keyword already */
			for (i = 0; i < toList.length; i++){
				if (toList[i].value.toUpperCase() == "ALL")
					return false;
			}

			/* @ case: user selected other keywords, but need to select "ALL" finally */
			if (fromList[iSelectedIndex].value.toUpperCase() == "ALL"){
				toList.length = 0;
				var opt = new Option();
				opt.value = fromList[iSelectedIndex].value;
				opt.text = fromList[iSelectedIndex].value;
				toList[toList.length] = opt;
				fromList.length = 0;
				generateMenu(arrValue, arrText, fromList, null);

				return false;
			}
		}

		if (max == 0){
			opt.value	= fromList[iSelectedIndex].value;
			opt.text	= fromList[iSelectedIndex].text;
			toList[toListLength] = opt;
			fromList[iSelectedIndex] = null;
		} else{
			if (toListLength < max){
				opt.value = fromList[iSelectedIndex].value;
				opt.text = fromList[iSelectedIndex].text;
				toList[toList.length] = opt;
				fromList[iSelectedIndex] = null;
			}
		}
	}
}

function selectItem(menu_list){
	// @ select the "selected" item
	for (var i = 0; i < menu_list.options.length; i++){
		menu_list.options[i].selected = true;
	}
}


//-->