<!--

	var frmHdnFld, frmAvail, frmSlctd, srcList, destList;
	
	function getFldNames(fldName)
	{
		// Initialise pieces - set the available / selected form items as appropriate...
		if((document.frmName.frmActn.value == "UPD") || (document.frmName.frmActn.value == "SET"))
		{
			frmAvail = eval("document.frmName.frmAvailableList" + fldName);
			frmSlctd = eval("document.frmName.frmSelectedList" + fldName);
		}
		else
		{
			if(document.frmName.frmActn.value == "ADD")
			{
				frmAvail = eval("document.frmName.frmAvailableList" + fldName);
				frmSlctd = eval("document.frmName.frmSelectedList" + fldName);				
			}
		}
	}
	
	// Compare two options within a list by VALUES
	function compareOptionValues(a, b) 
	{ 
		// Radix 10: for numeric values
		// Radix 36: for alphanumeric values
		var sA = parseInt(a.value, 36);  
		var sB = parseInt(b.value, 36);  
		return sA - sB;
	}
	
	// Compare two options within a list by TEXT
	function compareOptionText(a, b) 
	{ 
		// Radix 10: for numeric values
		// Radix 36: for alphanumeric values
		var sA = parseInt(a.text, 36);  
		var sB = parseInt(b.text, 36);  
		return sA - sB;
	}

	function sortList(boxName)
	{
		var temp_opts = new Array();
		var temp = new Object();
		for(var i=0; i<boxName.options.length; i++)
		{
			temp_opts[i] = boxName.options[i];
		}
		for(var x=0; x<temp_opts.length-1; x++)
		{
			for(var y=(x+1); y<temp_opts.length; y++)
			{
				if(temp_opts[x].text > temp_opts[y].text)
				{
					temp = temp_opts[x].text;
					temp_opts[x].text = temp_opts[y].text;
					temp_opts[y].text = temp;
					temp = temp_opts[x].value;
					temp_opts[x].value = temp_opts[y].value;
					temp_opts[y].value = temp;
				}
			}
		}
		for(var i=0; i<boxName.options.length; i++)
		{
			boxName.options[i].value = temp_opts[i].value;
			boxName.options[i].text = temp_opts[i].text;
		}
	}
	
	// Dual list move function
	function moveDualList(srcList,destList,moveAll,fldName) 
	{
		//alert(srcList);
		//alert(destList);
		getFldNames(fldName);
		// Do nothing if nothing is selected
		if((srcList.selectedIndex == -1) && (moveAll == false))
		{
			return;
		}
		newDestList = new Array(destList.options.length);
		var len = 0;
		for(len = 0; len < destList.options.length; len++) 
		{
			if(destList.options[len] != null)
			{
				newDestList[len] = new Option(destList.options[len].text, destList.options[len].value, destList.options[len].defaultSelected, destList.options[len].selected);
			}
		}
		for(var i = 0; i < srcList.options.length; i++) 
		{ 
			if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll))
			{
				// Statements to perform if option is selected, incorporate into new list
				newDestList[len] = new Option(srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected);
				len++;
			}
		}
		// Sort out the new destination list
		//newDestList.sort(compareOptionValues);		// BY VALUES
		//newDestList.sort(compareOptionText);			// BY TEXT
		
		// Populate the destination with the items from the new array
		for (var j = 0; j < newDestList.length; j++) 
		{
			if (newDestList[j] != null)
			{
				destList.options[j] = newDestList[j];
			}
		}
		// Erase source list selected elements
		for(var i = srcList.options.length - 1; i >= 0; i--) 
		{ 
			if (srcList.options[i] != null && (srcList.options[i].selected == true || moveAll))
			{
				// Erase Source
				//srcList.options[i].value = "";
				//srcList.options[i].text  = "";
				srcList.options[i] = null;
			}
		}
		sortList(srcList);
		sortList(destList);
		hdnFldUpdate(fldName);
	}
	// End of moveDualList()

	// Rewrite the form hidden field holding the new order
	function hdnFldUpdate(fldName)
	{
		getFldNames(fldName);
		var theFrm = eval("document.frmName.frmSelectedIDs" + fldName);
		//alert("document.frmName.frmSelectedIDs" + fldName);
		theFrm.value="";
		for (j = 0; j < frmSlctd.length; j++) {
			if (theFrm.value==""){
				theFrm.value+="|";
				theFrm.value+=frmSlctd[j].value;
				theFrm.value+="|";
			}
			else
			{
				theFrm.value+=frmSlctd[j].value;
				theFrm.value+="|";
			}
		}
		//alert(theFrm.value);
	}

//  End -->
