var AddRemove;
var ricolaAddRemoveCustomLeftItems = new Array();
var ricolaAddRemoveCustomRightItems = new Array();
var ricolaAddRemoveNumber = 0;
var AddRemove_useCustomJavaScript = false;
var AddRemove_useOnBeforeReturn = false;
var AddRemove_onBeforeReturn_functionName = new String("");

function AddRemoveItems() {
	var useSmallSelectFont = false;
	var useSmallHeadingFont = false;
	var useSmallColumnHeadingsFont = false;
	var returnTypeText=true;
	var outOneStr=new String("");
	var outTwoStr=new String("");
	var i=0;

	var defaultSelectBoxWidth = "180px";	// This is the smallest width the <SELECT> boxes will be
	var windowLeftPosition = "200";		// How many pixels from the left will the popup window be
	var windowTopPosition = "100";		// How many pixels from the top  will the popup window be

	if (arguments.length == 0) {
		alert("Add/Remove Component Error #9599: There were no parameters passed with the AddRemoveItems() function.  Please refer to the documentation at http://home.www.uprr.com/emp/it/hf/ricola/addremove/ for a list of valid parameters.");
		return false;
	} else if (arguments.length == 1) {
		alert("Add/Remove Component Error #9600: There was only 1 parameter passed with the AddRemoveItems() function.\nPlease also pass in a type (example: AddRemoveItems(document.MainForm.selectBoxName,\"addressbook\");\nRefer to the documentation at http://home.www.uprr.com/emp/it/hf/ricola/addremove/ for a list of valid parameters.");
		return false;
	}
	var returningItem=arguments[0];
	var returnDelimiter=new String(", ");
	var ARotherReturnItem=new String("-1856");
//	var URLEncodeCharAry=new Array("\%"," ","\&","\?");
//	var URLEncodeCodeAry=new Array("%25","%20","%26","%3F");
	if (arguments[1].toLowerCase() == "addressbook") {
		var returnTypeStyle=new String("flname");
		for (i=2; i<arguments.length; i++) {
			if (arguments[i].search(/^return:/i) != -1) {
				if (arguments[i].search(/^return:\s*email/i) != -1) { 
					returnTypeStyle="email"; 
				} else if (arguments[i].search(/^return:\s*shortname/i) != -1) { 
					returnTypeStyle="shortname";
				} else if (arguments[i].search(/^return:\s*(fl)?name/i) != -1) { 
					returnTypeStyle="flname";
				} else if (arguments[i].search(/^return:\s*employeeid/i) != -1) { 
					returnTypeStyle="empid";
				}
			} else if (arguments[i].search(/^delim[ie]ter:/i) != -1) {
				returnDelimiter=arguments[i].substring(10);
				returnDelimiter=returnDelimiter.replace(/\%/g, "%25").replace(/ /g, "%20").replace(/\&/g, "%26").replace(/\?/g, "%3F").replace(/\=/g, "%3D");				
			} else if (arguments[i].search(/^returnotheritem:/i) != -1) {
				ARotherReturnItem="window.opener." + arguments[i].replace(/^returnotheritem:\s*(.*)$/i,"$1");
			}
		}
		if ((ARotherReturnItem != "-1856") && (returnTypeStyle == "flname")) {
			alert("Add/Remove Component Error #9601: If you use a second return item (\"ReturnOtherItem\") in the \"AddressBook\" type, you must specify a \"return\" that is different than \"name\".\n\nExample:\n\t AddRemoveItems(document.MainForm.selectBoxName,\"addressbook\",\"return: email\",\"ReturnOtherItem: document.MainForm.HiddenEmail\");\n\nRefer to the documentation at http://home.www.uprr.com/emp/it/hf/ricola/addremove/ for a list of valid parameters.");
			return false;
		}
		outOneStr="/ssi/apps/addremove/addressbook.cfm?OpenerElemName=window.opener." + arguments[0] + "&ReturnType=" + returnTypeStyle + "&DelimiterType=" + returnDelimiter;
		if (ARotherReturnItem != "-1856") { outOneStr+="&CFOtherReturnItem=" + ARotherReturnItem; }
		var addRemove_WidthCont = 570;
		var addRemove_HeightCont = 600;
		AddRemovePopup = window.open(outOneStr, "AddRemoveWindow", "menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + addRemove_WidthCont + ",height=" + addRemove_HeightCont + ",directories=no,screenX=" + windowLeftPosition + ",screenY=" + windowTopPosition + ",left=" + windowLeftPosition + ",top=" + windowTopPosition);
		AddRemovePopup.focus();
//		AddRemovePopup.opener=self;
	} else if (arguments[1].toLowerCase() == "custom") {
		var usePreFillToField=false;
		var ShowSelectedCount = false;
		var DisableSortButtons = false; 
		var DisableAddAllButtons = false;
		var UseMaxSelect = false;
		var NumMaxSelect = -1;
		var addRemove_WidthCont = 612;
		var addRemove_HeightCont = 530;
		

		var titlecounter=0;
		var titleclasshold=new String("");
		var fromNameLabel=new String("From List");
		var toNameLabel=new String("To List");
		var initialTitle=new String("Add/Remove Utility");
		var secondaryTitle=new String("");
		var currAddRemoveNum = 0;
		var OptionSelectedMultipleTimes = false;
		for (i=2; i < arguments.length; i++) {
			if (arguments[i].substring(0,6).toLowerCase() == "title:") {
				titleclasshold=(titlecounter++ == 0)? "ARHeading" : "ARHeading2";
				if (titlecounter == 1) {
					initialTitle=arguments[i].replace(/title:\s?(.+)/i,"$1");
				} else {
					secondaryTitle=arguments[i].replace(/title:\s?(.+)/i,"$1");
				}
//				AddRemovePopup.document.writeln("<DIV ALIGN=\"CENTER\"><SPAN CLASS=\"" + titleclasshold + "\">" + arguments[i].replace(/title:\s?(.+)/i,"$1") + "</SPAN></DIV>");
			} else if (arguments[i].substring(0,10).toLowerCase() == "fromlabel:") {
				fromNameLabel=arguments[i].replace(/fromlabel:\s?(.+)/i,"$1");
			} else if (arguments[i].substring(0,8).toLowerCase() == "tolabel:") {
				toNameLabel=arguments[i].replace(/tolabel:\s?(.+)/i,"$1");
//			} else if (arguments[i].substring(0,2).toLowerCase() == "o:") {
//				usePreFillToField=true;
			} else if ((arguments[i].substring(0,10).toLowerCase() == "delimiter:") || (arguments[i].substring(0,10).toLowerCase() == "delimeter:")) {
				returnDelimiter=arguments[i].substring(10);
			} else if (arguments[i].search(/^\s*AddRemoveNum:\s*\d+\s*$/i) != -1) {
				currAddRemoveNum=parseInt(arguments[i].replace(/^\s*AddRemoveNum:\s*(\d+)\s*$/i, "$1"), 10);
			} else if (arguments[i].search(/^UseSmallSelectFont\s*:\s*1\s*$/i) != -1) {
				useSmallSelectFont = true;
			} else if (arguments[i].search(/^useSmallHeadingFont\s*:\s*1\s*$/i) != -1) {
				useSmallHeadingFont = true;
			} else if (arguments[i].search(/^UseSmallColumnHeadingsFont\s*:\s*1\s*$/i) != -1) {
				useSmallColumnHeadingsFont = true;
			} else if (arguments[i].search(/^return:/i) != -1) {
				(arguments[i].toLowerCase().indexOf("value") != -1)? returnTypeText=false : returnTypeText=true; 
			} else if (arguments[i].search(/^returnotheritem:/i) != -1) {
				ARotherReturnItem="window.opener." + arguments[i].replace(/^returnotheritem:\s*(.*)$/i,"$1");
			} else if (arguments[i].search(/^Show\s*Selected\s*Count:\s*\d\s*$/i) != -1) {
				if (arguments[i].replace(/^Show\s*Selected\s*Count:\s*(\d)\s*$/i, "$1") == "1") { 
					ShowSelectedCount = true; 
				}
			} else if (arguments[i].search(/^Max\s*Select:\s*\d+\s*$/i) != -1) {
				UseMaxSelect = true;
				NumMaxSelect = parseInt(arguments[i].replace(/^Max\s*Select:\s*(\d+)\s*$/i, "$1"), 10);
			} else if (arguments[i].search(/^Disable\s*Sort\s*Buttons:\s*\d\s*$/i) != -1) {
				if (arguments[i].replace(/^Disable\s*Sort\s*Buttons:\s*(\d)\s*$/i, "$1") == "1") { 
					DisableSortButtons = true; 
				}
			} else if (arguments[i].search(/^Disable\s*Add\s*All\s*Buttons?:\s*\d\s*$/i) != -1) {
				if (arguments[i].replace(/^Disable\s*Add\s*All\s*Buttons?:\s*(\d)\s*$/i, "$1") == "1") { 
					DisableAddAllButtons = true; 
				}
			} else if (arguments[i].toString().search(/^Allow\s*Multiple$/gi) != -1) {
				OptionSelectedMultipleTimes = true;
			}
		}
		
		
		
		
		
		
		AddRemovePopup = window.open("", "AddRemoveWindow", "menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + addRemove_WidthCont + ",height=" + addRemove_HeightCont + ",directories=no,screenX=" + windowLeftPosition + ",screenY=" + windowTopPosition + ",left=" + windowLeftPosition + ",top=" + windowTopPosition);
		AddRemovePopup.focus();
//		AddRemovePopup.opener=self;
		AddRemovePopup.document.open();
		AddRemovePopup.document.writeln("<HTML>\n<HEAD>\n\t<TITLE>UP: Add/Remove</TITLE>");
//		AddRemovePopup.document.writeln("\t<LINK HREF=\"/ssi/apps/addremove/addremove.css\" REL=\"stylesheet\" TYPE=\"text/css\">");

// Trying to explode the CSS File

AddRemovePopup.document.writeln("\t<STYLE TYPE=\"text/css\">");
AddRemovePopup.document.writeln("\t\t.BODY { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : small; }");
AddRemovePopup.document.writeln("\t\t.BODY { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : small; }");
// AddRemovePopup.document.writeln("\t\t.ARHeading { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : large; color: #669999; }");
// AddRemovePopup.document.writeln("\t\t.ARHeading2 { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : small; color: #669999; font-weight : bold; }");
if (useSmallHeadingFont) {
	AddRemovePopup.document.writeln("\t\t.ARHeading { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 14px; color: #FFFFFF; background-color: #000000; font-weight : 900; }");
	AddRemovePopup.document.writeln("\t\t.ARHeading2 { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 11px; color: #000000; background-color: #CEE1F2; font-weight : 900; padding: 7px 7px 7px 7px; }");
} else {
	AddRemovePopup.document.writeln("\t\t.ARHeading { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 16px; color: #FFFFFF; background-color: #000000; font-weight : 900; }");
	AddRemovePopup.document.writeln("\t\t.ARHeading2 { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 13px; color: #000000; background-color: #CEE1F2; font-weight : 900; padding: 7px 7px 7px 7px; }");
}
AddRemovePopup.document.writeln("\t\tINPUT { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : x-small; width: 140 px;}");
if (useSmallSelectFont) {
	defaultSelectBoxWidth = "190px";	// This is the smallest width the <SELECT> boxes will be
	AddRemovePopup.document.writeln("\t\tSELECT { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 10px;  }");
} else {
	AddRemovePopup.document.writeln("\t\tSELECT { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : x-small; }");
}
if (useSmallColumnHeadingsFont) {
	AddRemovePopup.document.writeln("\t\t.ListHeader { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 10px; font-weight : bold; }");
} else {
	AddRemovePopup.document.writeln("\t\t.ListHeader { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : x-small; font-weight : bold; }");
}
AddRemovePopup.document.writeln("\t\t.NoneFound { color : #993333; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : medium; font-weight : bold; }");
AddRemovePopup.document.writeln("\t\t.CountStyle { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : xx-small; font-weight : bold; color: #000000; }");
AddRemovePopup.document.writeln("\t\t.TooManySelectedBig { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : x-small; font-weight : bold; color: #CC6633; }");
AddRemovePopup.document.writeln("\t\t.TooManySelected { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : xx-small; font-weight : bold; color: #CC6633; }");
AddRemovePopup.document.writeln("\t</STYLE>");



/*		AddRemovePopup.document.writeln("\t<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"/ssi/apps/addremove/windowjs.js\">");
		AddRemovePopup.document.write("\<\/");
		AddRemovePopup.document.write("SCRIPT\>\n");
*/

/* ************************ EXPLODING window.js ********************************************************* */
		AddRemovePopup.document.writeln("<SCRIPT LANGUAGE=\"JavaScript\">\n");
		AddRemovePopup.document.writeln("var defaultSelectBoxWidth = \"" + defaultSelectBoxWidth + "\"");
		AddRemovePopup.document.writeln("var windowLeftPosition = \"" + windowLeftPosition + "\"");
		AddRemovePopup.document.writeln("var windowTopPosition = \"" + windowTopPosition + "\"");

		AddRemovePopup.document.writeln("function resizeMyWindow() {");
		AddRemovePopup.document.writeln("	var fSelect = document.AddRemoveForm.FromArea;");
		AddRemovePopup.document.writeln("	var tSelect = document.AddRemoveForm.ToArea;");
		AddRemovePopup.document.writeln("	if (fSelect.clientWidth < defaultSelectBoxWidth) {");
		AddRemovePopup.document.writeln("		fSelect.clientWidth = defaultSelectBoxWidth;");
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("	if (tSelect.clientWidth < defaultSelectBoxWidth) {");
		AddRemovePopup.document.writeln("		tSelect.clientWidth = defaultSelectBoxWidth;");
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("	if (fSelect.clientWidth > tSelect.clientWidth) {");
		AddRemovePopup.document.writeln("		tSelect.style.width = fSelect.clientWidth;");
		AddRemovePopup.document.writeln("	} else {");
		AddRemovePopup.document.writeln("		fSelect.style.width = tSelect.clientWidth;");
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("	var cWidth = document.body.scrollWidth + 30;");
		AddRemovePopup.document.writeln("	var cHeight = document.body.scrollHeight + 60;");
		AddRemovePopup.document.writeln("	if (cWidth < screen.width) {");
		AddRemovePopup.document.writeln("	window.resizeTo(cWidth, cHeight);");
		AddRemovePopup.document.writeln("		if ((windowTopPosition + cWidth) > screen.width) {");
		AddRemovePopup.document.writeln("			var WindowDifference = screen.width - cWidth;");
		AddRemovePopup.document.writeln("			window.moveTo(parseInt(WindowDifference/2, 10), windowTopPosition);");
		AddRemovePopup.document.writeln("		}");
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("	return true;");
		AddRemovePopup.document.writeln("}");

		AddRemovePopup.document.writeln("function addItems() {");
		AddRemovePopup.document.writeln("	var i=0;");
		AddRemovePopup.document.writeln("	var c=0;");
		AddRemovePopup.document.writeln("	var isAlreadyThere=false;");
		AddRemovePopup.document.writeln("	for (i=0; i< TAObj.length; i++) {");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].value == \"ThisIsASpacerDeleteMe\") {");
		AddRemovePopup.document.writeln("			TAObj.options[i] = null;");
		AddRemovePopup.document.writeln("		}");
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("	for (i=0; i< FAObj.length; i++) {");
		AddRemovePopup.document.writeln("		if (FAObj.options[i].selected) {");
		AddRemovePopup.document.writeln("			isAlreadyThere=false;");
		AddRemovePopup.document.writeln("			if (!AddRemove_OptionSelectedMultipleTimes) {");
		AddRemovePopup.document.writeln("				for (c=0; c < TAObj.length; c++) {");
		AddRemovePopup.document.writeln("					if ((TAObj.options[c].text == FAObj.options[i].text) && (TAObj.options[c].value == FAObj.options[i].value)) {");
		AddRemovePopup.document.writeln("						isAlreadyThere=true;");
		AddRemovePopup.document.writeln("					}");
		AddRemovePopup.document.writeln("				}");
		AddRemovePopup.document.writeln("			}");
		AddRemovePopup.document.writeln("			if (!isAlreadyThere) {");
		AddRemovePopup.document.writeln("				TAObj.options[TAObj.length] = new Option(FAObj.options[i].text,FAObj.options[i].value,false,false);");
		AddRemovePopup.document.writeln("			}");
		AddRemovePopup.document.writeln("		}");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		doCheckCount(TAObj, 'ShowToSelectCountLay'); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("}\n");

		AddRemovePopup.document.writeln("function removeItems() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	for (i=0; i<TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].selected) { ");
		AddRemovePopup.document.writeln("			TAObj.options[i] = null; ");
		AddRemovePopup.document.writeln("			i=-1; ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		doCheckCount(TAObj, 'ShowToSelectCountLay'); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("} ");


		AddRemovePopup.document.writeln("function removeAll() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	for (i=0; i<TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		TAObj.options[i] = null; ");
		AddRemovePopup.document.writeln("		i=-1; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		doCheckCount(TAObj, 'ShowToSelectCountLay'); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function addAll() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	var c=0; ");
		AddRemovePopup.document.writeln("	var isAlreadyThere=false; ");
		AddRemovePopup.document.writeln("	for (i=0; i< TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].value == \"ThisIsASpacerDeleteMe\") { ");
		AddRemovePopup.document.writeln("			TAObj.options[i] = null; ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	}	 ");
		AddRemovePopup.document.writeln("	for (i=0; i<FAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		isAlreadyThere=false; ");
		AddRemovePopup.document.writeln("		for (c=0; c < TAObj.length; c++) { ");
		AddRemovePopup.document.writeln("			if ((TAObj.options[c].text == FAObj.options[i].text) && (TAObj.options[c].value == FAObj.options[i].value)) { ");
		AddRemovePopup.document.writeln("				isAlreadyThere=true; ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("		if (!isAlreadyThere) { ");
		AddRemovePopup.document.writeln("			TAObj.options[TAObj.length] = new Option(FAObj.options[i].text,FAObj.options[i].value,false,false); ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	}	 ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		doCheckCount(TAObj, 'ShowToSelectCountLay'); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function moveUp() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	var itemsSelected=0; ");
		AddRemovePopup.document.writeln("	var selectedBL=false; ");
		AddRemovePopup.document.writeln("	var TATary=new Array(); ");
		AddRemovePopup.document.writeln("	var TAVary=new Array(); ");
		AddRemovePopup.document.writeln("	var TATOary=new Array(); ");
		AddRemovePopup.document.writeln("	var TAVOary=new Array(); ");
		AddRemovePopup.document.writeln("	for (i=0; i<TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].selected) { itemsSelected++; } ");
		AddRemovePopup.document.writeln("		TATary[TATary.length]=TAObj.options[i].text; ");
		AddRemovePopup.document.writeln("		TAVary[TAVary.length]=TAObj.options[i].value; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (itemsSelected > 1) { ");
		AddRemovePopup.document.writeln("		alert(\"There were more than one item selected to move up in the list order.\\nPlease select only one item in the list box on the right hand side.\"); ");
		AddRemovePopup.document.writeln("		return false; ");
		AddRemovePopup.document.writeln("	} else if (itemsSelected == 0) { ");
		AddRemovePopup.document.writeln("		alert(\"There wasn't an item selected to move up in the list order.\\nPlease select an item in the list box on the right hand side.\"); ");
		AddRemovePopup.document.writeln("		return false; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (TAObj.selectedIndex != 0) { ");
		AddRemovePopup.document.writeln("		itemsSelected=TAObj.selectedIndex; ");
		AddRemovePopup.document.writeln("		removeAll(); ");
		AddRemovePopup.document.writeln("		for (i=0; i<TATary.length; i++) { ");
		AddRemovePopup.document.writeln("			if (i == (itemsSelected - 1)) { ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[(i + 1)]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[(i + 1)]; ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[i]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[i]; ");
		AddRemovePopup.document.writeln("				i++; ");
		AddRemovePopup.document.writeln("			} else { ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[i]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[i]; ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("		for (i=0; i<TATOary.length; i++) { ");
		AddRemovePopup.document.writeln("			(i == (itemsSelected - 1)) ? selectedBL=true : selectedBL=false; ");
		AddRemovePopup.document.writeln("			TAObj.options[TAObj.length]=new Option(TATOary[i],TAVOary[i],false,selectedBL); ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	}  ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function moveDown() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	var itemsSelected=0; ");
		AddRemovePopup.document.writeln("	var selectedBL=false; ");
		AddRemovePopup.document.writeln("	var TATary=new Array(); ");
		AddRemovePopup.document.writeln("	var TAVary=new Array(); ");
		AddRemovePopup.document.writeln("	var TATOary=new Array(); ");
		AddRemovePopup.document.writeln("	var TAVOary=new Array(); ");
		AddRemovePopup.document.writeln("	for (i=0; i<TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].selected) { itemsSelected++; } ");
		AddRemovePopup.document.writeln("		TATary[TATary.length]=TAObj.options[i].text; ");
		AddRemovePopup.document.writeln("		TAVary[TAVary.length]=TAObj.options[i].value; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (itemsSelected > 1) { ");
		AddRemovePopup.document.writeln("		alert(\"There were more than one item selected to move up in the list order.\\nPlease select only one item in the list box on the right hand side.\"); ");
		AddRemovePopup.document.writeln("		return false; ");
		AddRemovePopup.document.writeln("	} else if (itemsSelected == 0) { ");
		AddRemovePopup.document.writeln("		alert(\"There wasn't an item selected to move up in the list order.\\nPlease select an item in the list box on the right hand side.\"); ");
		AddRemovePopup.document.writeln("		return false; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (TAObj.selectedIndex != (TAObj.length - 1)) { ");
		AddRemovePopup.document.writeln("		itemsSelected=TAObj.selectedIndex; ");
		AddRemovePopup.document.writeln("		removeAll(); ");
		AddRemovePopup.document.writeln("		for (i=0; i<TATary.length; i++) { ");
		AddRemovePopup.document.writeln("			if (i == itemsSelected) { ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[(i + 1)]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[(i + 1)]; ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[i]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[i]; ");
		AddRemovePopup.document.writeln("				i++; ");
		AddRemovePopup.document.writeln("			} else { ");
		AddRemovePopup.document.writeln("				TATOary[TATOary.length]=TATary[i]; ");
		AddRemovePopup.document.writeln("				TAVOary[TAVOary.length]=TAVary[i];			 ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("		for (i=0; i<TATOary.length; i++) { ");
		AddRemovePopup.document.writeln("			(i == (itemsSelected + 1)) ? selectedBL=true : selectedBL=false; ");
		AddRemovePopup.document.writeln("			TAObj.options[TAObj.length]=new Option(TATOary[i],TAVOary[i],false,selectedBL); ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	}  ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function sortList() { ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	var TATary=new Array(); ");
		AddRemovePopup.document.writeln("	var TAVary=new Array();	 ");
		AddRemovePopup.document.writeln("	var TASary=new Array(); ");
		AddRemovePopup.document.writeln("	if (TAObj.options[0].value == \"ThisIsASpacerDeleteMe\") { ");
		AddRemovePopup.document.writeln("		alert(\"There are no items in the List box on the right hand side to sort.\"); ");
		AddRemovePopup.document.writeln("		return false; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	for (i=0; i< TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		TATary[TATary.length] = TAObj.options[i].text + \"-1856-\" + TAObj.options[i].value; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	TATary.sort(); ");
		AddRemovePopup.document.writeln("	removeAll();   ");
		AddRemovePopup.document.writeln("	for (i=0; i<TATary.length; i++) { ");
		AddRemovePopup.document.writeln("		TAObj.options[TAObj.length]=new Option(TATary[i].replace(/(.+)-1856-(.+)/,\"$1\"),TATary[i].replace(/(.+)-1856-(.+)/,\"$2\"),false,false); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		doCheckCount(TAObj, 'ShowToSelectCountLay'); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("}\n ");


		AddRemovePopup.document.writeln("function returnMySelections() { ");
		AddRemovePopup.document.writeln("	window.opener.focus(); ");
		AddRemovePopup.document.writeln("	window.opener.RICOLAAddRemove_CheckOnBeforeReturnJS(); ");
		AddRemovePopup.document.writeln("	var i=0; "); 
		AddRemovePopup.document.writeln("	for (i=0; i< TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].value == \"ThisIsASpacerDeleteMe\") { ");
		AddRemovePopup.document.writeln("			TAObj.options[i] = null; ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	}	 ");

		AddRemovePopup.document.writeln("	if (AddRemove_UseMaxSelect) { ");
		AddRemovePopup.document.writeln("		if (TAObj.length > AddRemove_NumMaxSelect) { ");
		AddRemovePopup.document.writeln("			alert('There can be only ' + AddRemove_NumMaxSelect + ' items selected/returned (You have ' + TAObj.length + ' items selected).\\n\\nPlease remove some items from the \\\"' + AddRemove_toNameLabel + '\\\" column.'); ");
		AddRemovePopup.document.writeln("			return false; ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("	} ");
		
		AddRemovePopup.document.writeln("	if (returnDelimiter) {  ");
		AddRemovePopup.document.writeln("		returnDelimiter=returnDelimiter.replace(/1856_CR/g,\"\\n\"); ");
		AddRemovePopup.document.writeln("		var delimiter=returnDelimiter; ");
		AddRemovePopup.document.writeln("	} else { ");
		AddRemovePopup.document.writeln("		var delimiter=new String(\",\"); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	var rtypeString=new String(returningItem.type); ");
		AddRemovePopup.document.writeln("	if (arguments.length != 0) { delimiter=arguments[0]; } ");
		AddRemovePopup.document.writeln("	if ((rtypeString.toLowerCase() == \"text\") || (rtypeString.toLowerCase() == \"textarea\")) {  	 ");
		AddRemovePopup.document.writeln("		returningItem.value=\"\"; ");
		AddRemovePopup.document.writeln("		if (UseOtherRetItem) { otherReturnItem.value=\"\";  } ");
		AddRemovePopup.document.writeln("		for (i=0; i < TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("			returningItem.value+=(returnTypeText)? TAObj.options[i].text : TAObj.options[i].value; ");
		AddRemovePopup.document.writeln("			if (UseOtherRetItem) {  ");
		AddRemovePopup.document.writeln("				otherReturnItem.value+=(returnTypeText)? TAObj.options[i].value : TAObj.options[i].text;  ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("			if ((i+1) < TAObj.length) { ");
		AddRemovePopup.document.writeln("				returningItem.value+=delimiter; ");
		AddRemovePopup.document.writeln("				if (UseOtherRetItem) {  ");
		AddRemovePopup.document.writeln("					otherReturnItem.value+=delimiter; ");
		AddRemovePopup.document.writeln("				} ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		}	 ");
		AddRemovePopup.document.writeln("	}  ");
		AddRemovePopup.document.writeln("	window.opener.RICOLAAddRemove_CheckCustomJS(); ");
		AddRemovePopup.document.writeln("	self.close(); ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function disableCheck() { ");
		AddRemovePopup.document.writeln("	var numofTAselect=0; "); 
		AddRemovePopup.document.writeln("	var numofFAselect=0;	 ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	for (i=0; i < TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].selected) { numofTAselect++; } ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	for (i=0; i < FAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (FAObj.options[i].selected) { numofFAselect++; } ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.RemoveButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.RemoveAllButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.AddButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.AddAllButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.MoveUpButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.MoveDownButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.SortButton.disabled=false; ");
		AddRemovePopup.document.writeln("	document.AddRemoveForm.OKButton.disabled=false; ");
		AddRemovePopup.document.writeln("	if (numofFAselect == 0) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.AddButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (TAObj.length == 0) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.RemoveButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.RemoveAllButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.SortButton.disabled=true; ");
//		AddRemovePopup.document.writeln("		document.AddRemoveForm.OKButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} else if ((numofTAselect > 1) || ((TAObj.options[0].selected) && (TAObj.options[(TAObj.length - 1)].selected) ) ) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} else if (TAObj.options[0].selected) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} else if (TAObj.options[(TAObj.length - 1)].selected) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=true; ");
		AddRemovePopup.document.writeln("	}  ");
		AddRemovePopup.document.writeln("}\n ");


		AddRemovePopup.document.writeln("function toFieldChecking() {  ");
		AddRemovePopup.document.writeln("	var numofTAselect=0; ");
		AddRemovePopup.document.writeln("	var numofFAselect=0;	 ");
		AddRemovePopup.document.writeln("	var i=0; ");
		AddRemovePopup.document.writeln("	for (i=0; i < TAObj.length; i++) { ");
		AddRemovePopup.document.writeln("		if (TAObj.options[i].selected) { numofTAselect++; } ");
		AddRemovePopup.document.writeln("	}	 ");
		AddRemovePopup.document.writeln("	if (i > 0) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.RemoveButton.disabled=false; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.RemoveAllButton.disabled=false; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.SortButton.disabled=false; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.OKButton.disabled=false; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=false; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=false; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if ((numofTAselect > 1) || ((TAObj.options[0].selected) && (TAObj.options[(TAObj.length - 1)].selected) ) ) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} else if (TAObj.options[0].selected) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveUpButton.disabled=true; ");
		AddRemovePopup.document.writeln("	} else if (TAObj.options[(TAObj.length - 1)].selected) { ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.MoveDownButton.disabled=true; ");
		AddRemovePopup.document.writeln("	}  ");
		AddRemovePopup.document.writeln("}\n ");

		AddRemovePopup.document.writeln("function writeToLayer(lay,txt) { ");
		AddRemovePopup.document.writeln("	var ie4 = (document.all) ? true : false; ");
		AddRemovePopup.document.writeln("	var ns4 = (document.layers) ? true : false; ");
		AddRemovePopup.document.writeln("	var ns6 = (document.getElementById && !document.all) ? true : false; ");
		AddRemovePopup.document.writeln("	if (ie4) { ");
		AddRemovePopup.document.writeln("		document.all[lay].innerHTML = txt; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (ns4) { ");
		AddRemovePopup.document.writeln("		document[lay].document.write(txt); ");
		AddRemovePopup.document.writeln("		document[lay].document.close(); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (ns6) { ");
		AddRemovePopup.document.writeln("		over = document.getElementById([lay]); ");
		AddRemovePopup.document.writeln("		range = document.createRange(); ");
		AddRemovePopup.document.writeln("		range.setStartBefore(over); ");
		AddRemovePopup.document.writeln("		domfrag = range.createContextualFragment(txt); ");
		AddRemovePopup.document.writeln("		while (over.hasChildNodes()) { ");
		AddRemovePopup.document.writeln("			over.removeChild(over.lastChild); ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("		over.appendChild(domfrag); ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("} \n ");

		AddRemovePopup.document.writeln("function doCheckCount(inItem, inLay) { ");
		AddRemovePopup.document.writeln("	var FromSide = false;");
		AddRemovePopup.document.writeln("	if (inLay == 'ShowSelectedCountLay') { ");
		AddRemovePopup.document.writeln("		FromSide = true; ");
		AddRemovePopup.document.writeln("		document.AddRemoveForm.AddButton.disabled=false;");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (AddRemove_ShowSelectedCount) { ");
		AddRemovePopup.document.writeln("		var numSelected = 0; ");
		AddRemovePopup.document.writeln("		if (FromSide) { ");
		AddRemovePopup.document.writeln("			for (var i=0; i < inItem.length; i++) { ");
		AddRemovePopup.document.writeln("				if (inItem.options[i].selected) { numSelected++; } ");
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		} else { ");
		AddRemovePopup.document.writeln("			numSelected = inItem.length; ");
		AddRemovePopup.document.writeln("			if (AddRemove_UseMaxSelect) { ");
		AddRemovePopup.document.writeln("				var classToUse = (TAObj.length > AddRemove_NumMaxSelect) ? 'TooManySelected' : 'CountStyle'; ");
		AddRemovePopup.document.writeln("				setLayClassChange('MaxSelectLay', classToUse); ");
		AddRemovePopup.document.writeln("				setLayClassChange('ShowToSelectLayAll', classToUse); ");		
		AddRemovePopup.document.writeln("			} ");
		AddRemovePopup.document.writeln("		} ");
		AddRemovePopup.document.writeln("		writeToLayer(inLay, numSelected);");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("} \n ");		

		AddRemovePopup.document.writeln("function setLayClassChange(lay, inClass) { ");
		AddRemovePopup.document.writeln("	var ie4 = (document.all) ? true : false; ");
		AddRemovePopup.document.writeln("	var ns6 = (document.getElementById && !document.all) ? true : false; ");
		AddRemovePopup.document.writeln("	if (ie4) { ");
		AddRemovePopup.document.writeln("		document.all[lay].className = inClass; ");
		AddRemovePopup.document.writeln("	} ");
		AddRemovePopup.document.writeln("	if (ns6) { ");
		AddRemovePopup.document.writeln("		document.getElementById([lay]).className = inClass; "); 
		AddRemovePopup.document.writeln("	}");
		AddRemovePopup.document.writeln("} \n ");		
		
		AddRemovePopup.document.write("\<\/");
		AddRemovePopup.document.writeln("SCRIPT>");
/* *************************************************************************************************************** */

		AddRemovePopup.document.writeln("</HEAD>\n\n<body onLoad=\"resizeMyWindow();\">"); 

		
/* START Groupbox format (A) */		
		AddRemovePopup.document.writeln("<TABLE BORDER='1' CELLSPACING='0' CELLPADDING='3' ALIGN='CENTER' BORDERCOLOR='BLACK' width='570px'>");
		AddRemovePopup.document.writeln("<TR>\n\t<TD CLASS=\"ARHeading\" ALIGN=\"center\">" + initialTitle + "</TD>\n</TR>\n<TR>\n\t<TD>\n");
		if (titlecounter > 1) {
			AddRemovePopup.document.writeln("<DIV CLASS=\"ARHeading2\" ALIGN=\"center\" STYLE=\"width: 100%\">" + secondaryTitle + "</DIV><BR>");
		}


/* END Groupbox format (A) */		

	
//		AddRemovePopup.document.writeln("<HR COLOR='#669999' NOSHADE>");
		
		AddRemovePopup.document.writeln("<FORM NAME=\"AddRemoveForm\">\n<TABLE BORDER=\"0\" CELLPADDING=\"4\" CELLSPACING=\"0\" ALIGN=\"CENTER\">");
		AddRemovePopup.document.writeln("<TR><TD ALIGN=\"CENTER\"><SPAN CLASS=\"ListHeader\">" + fromNameLabel + "</SPAN></TD><TD>&nbsp;</TD><TD ALIGN=\"CENTER\"><SPAN CLASS=\"ListHeader\">" + toNameLabel + "</SPAN></TD></TR>");
		AddRemovePopup.document.writeln("<TR>\n\t<TD>");
		AddRemovePopup.document.writeln("\t\t<SELECT NAME='FromArea' SIZE='17' MULTIPLE onClick=\"doCheckCount(this, 'ShowSelectedCountLay');\" onChange=\"doCheckCount(this, 'ShowSelectedCountLay');\">");
		
		var currLeftOptionsAry  = ricolaAddRemoveCustomLeftItems[currAddRemoveNum].split("-=-");
		var currRightOptionsAry = new Array();
		if (ricolaAddRemoveCustomRightItems[currAddRemoveNum] != "") { 
			usePreFillToField = true;
			currRightOptionsAry = ricolaAddRemoveCustomRightItems[currAddRemoveNum].split("-=-");
		}
		var optionValueStr = new String("");
		var optionTextStr = new String("");
		var currOpt = new String("");
		for (i=0; i < currLeftOptionsAry.length; i++) {
			currOpt = currLeftOptionsAry[i];
			currOpt = currOpt.replace(/\\:/g,"-=1856=-");
			if (currOpt.search(/:/g) != -1) {
				optionTextStr  = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$1");
				optionValueStr = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$2");
			} else {
				optionTextStr  = currOpt;
				optionValueStr = currOpt;
			}
			optionTextStr  = optionTextStr.replace(/\-\=1856\=\-/g, ":");
			optionValueStr  = optionValueStr.replace(/\-\=1856\=\-/g, ":");
			AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
		}
		for (i=0; i < currRightOptionsAry.length; i++) {
			currOpt = currRightOptionsAry[i];
			currOpt = currOpt.replace(/\\:/g,"-=1856=-");
			if (currOpt.search(/:/g) != -1) {
				optionTextStr  = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$1");
				optionValueStr = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$2");
			} else {
				optionTextStr  = currOpt;
				optionValueStr = currOpt;
			}
			optionTextStr  = optionTextStr.replace(/\-\=1856\=\-/g, ":");
			optionValueStr  = optionValueStr.replace(/\-\=1856\=\-/g, ":");
			AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
		}
/*
		var ChangingStr=new String("");
		for (i=2; i < arguments.length; i++) {
			if ((arguments[i].substring(0,2).toLowerCase() == "i:") || (arguments[i].substring(0,2).toLowerCase() == "o:")) {
				if (arguments[i].substring(2,3) == " ") {
					ChangingStr=arguments[i].substring(3);
				} else {
					ChangingStr=arguments[i].substring(2);
				}
				ChangingStr=ChangingStr.replace(/\\:/,"-=-1856-=-");
				if (ChangingStr.indexOf(":") != -1) {
					outOneStr=ChangingStr.replace(/(.+):(.+)/,"$2");
					outTwoStr=ChangingStr.replace(/(.+):(.+)/,"$1");
					outOneStr=outOneStr.replace(/-=-1856-=-/,":");
					outTwoStr=outTwoStr.replace(/-=-1856-=-/,":");
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + outOneStr + "\">" + outTwoStr + "</OPTION>");
				} else {
					outOneStr=ChangingStr.replace(/-=-1856-=-/,":");
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + outOneStr + "\">" + outOneStr + "</OPTION>");
				}
			} else if (arguments[i].search(/^return:/i) != -1) {
				(arguments[i].toLowerCase().indexOf("value") != -1)? returnTypeText=false : returnTypeText=true; 
			} else if (arguments[i].search(/^returnotheritem:/i) != -1) {
				ARotherReturnItem="window.opener." + arguments[i].replace(/^returnotheritem:\s*(.*)$/i,"$1");
			}
		}
*/	
		AddRemovePopup.document.writeln("\t\t</SELECT>");
		
// Show Count
		if (ShowSelectedCount) {
			AddRemovePopup.document.writeln("<SPAN CLASS=\"CountStyle\"><SPAN ID=\"ShowSelectedCountLay\">0</SPAN>&nbsp;Item(s)&nbsp;Highlighted</SPAN>");
		}

		AddRemovePopup.document.writeln("\t</TD>\n\t<TD>");
		AddRemovePopup.document.writeln("\t\t<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\" ALIGN=\"CENTER\">");	
		AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Add > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\" onClick=\"addItems(); disableCheck();\" NAME=\"AddButton\" ID=\"AddButton\" DISABLED></TD></TR>");
		AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp; < Remove &nbsp;&nbsp;&nbsp;\" onClick=\"removeItems(); disableCheck();\" NAME=\"RemoveButton\" ID=\"RemoveButton\" DISABLED></TD></TR>");
		if (!DisableAddAllButtons) {
			AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp; Add All >> &nbsp;&nbsp;\" onClick=\"addAll(); disableCheck();\" NAME=\"AddAllButton\" ID=\"AddAllButton\"></TD></TR>");
		} else {
			AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp; Add All >> &nbsp;&nbsp;\" onClick=\"addAll(); disableCheck();\" DISABLED><INPUT TYPE=\"button\" style=\"display: none;\" NAME=\"AddAllButton\" ID=\"AddAllButton\"></TD></TR>");
		}
		AddRemovePopup.document.write("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;<< Remove All\" onClick=\"removeAll(); disableCheck();\" NAME=\"RemoveAllButton\" ID=\"RemoveAllButton\"");
		if (!usePreFillToField) { AddRemovePopup.document.write(" DISABLED"); }
		AddRemovePopup.document.write("></TD></TR>");
		
		if (!DisableSortButtons) {
			AddRemovePopup.document.writeln("\t\t<TR><TD>&nbsp;</TD></TR>\n\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp; Move Up &nbsp;&nbsp;&nbsp;&nbsp;\" onClick=\"moveUp(); disableCheck();\" NAME=\"MoveUpButton\" ID=\"MoveUpButton\" DISABLED></TD></TR>");
			AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;Move Down &nbsp;&nbsp;\" onClick=\"moveDown(); disableCheck();\" NAME=\"MoveDownButton\" ID=\"MoveDownButton\" DISABLED></TD>");
			AddRemovePopup.document.writeln("\t\t<TR><TD>&nbsp;</TD></TR>\n\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp;&nbsp; Sort List &nbsp;&nbsp;&nbsp;\" onClick=\"sortList();\" NAME=\"SortButton\" ID=\"SortButton\"");
			if (!usePreFillToField) { AddRemovePopup.document.write(" DISABLED"); }
			AddRemovePopup.document.write("></TD></TR>");
		} else {
			AddRemovePopup.document.writeln("\t\t<TR><TD>&nbsp;</TD></TR>\n\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" STYLE=\"visibility: hidden;\" VALUE=\"&nbsp;&nbsp;&nbsp; Move Up &nbsp;&nbsp;&nbsp;&nbsp;\" onClick=\"moveUp(); disableCheck();\" NAME=\"MoveUpButton\" ID=\"MoveUpButton\" DISABLED></TD></TR>");
			AddRemovePopup.document.writeln("\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" STYLE=\"visibility: hidden;\" VALUE=\"&nbsp;&nbsp;Move Down &nbsp;&nbsp;\" onClick=\"moveDown(); disableCheck();\" NAME=\"MoveDownButton\" ID=\"MoveDownButton\" DISABLED></TD>");
			AddRemovePopup.document.writeln("\t\t<TR><TD>&nbsp;</TD></TR>\n\t\t<TR>\n\t\t\t<TD><INPUT TYPE=\"button\" STYLE=\"visibility: hidden;\" VALUE=\"&nbsp;&nbsp;&nbsp;&nbsp; Sort List &nbsp;&nbsp;&nbsp;\" onClick=\"sortList();\" NAME=\"SortButton\" ID=\"SortButton\"");
			AddRemovePopup.document.write("></TD></TR>");
		}
		AddRemovePopup.document.writeln("\n\t\t</TR>");
		AddRemovePopup.document.writeln("\t\t</TABLE>");	
		AddRemovePopup.document.writeln("\t</TD>\n\t<TD>");
		AddRemovePopup.document.writeln("\t\t<SELECT NAME='ToArea' SIZE='17' MULTIPLE onChange=\"toFieldChecking();\">");
		var usedToTextAry = new Array();
		var usedToValuAry = new Array();
		var currRetItemAry = new Array();
		var currRetItemVal = eval(returningItem + ".value");
		currRetItemVal = currRetItemVal.replace(/^\s*/, "").replace(/\s*$/, "");
		currRetItemAry = currRetItemVal.split(returnDelimiter);
		// returnTypeText
		// returnDelimiter
		// returningItem
		
		
		if (usePreFillToField && (currRetItemVal == "")) {
			for (i=0; i < currRightOptionsAry.length; i++) {
				currOpt = currRightOptionsAry[i];
				currOpt = currOpt.replace(/\\:/g,"-=1856=-");
				if (currOpt.search(/:/g) != -1) {
					optionTextStr  = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$1");
					optionValueStr = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$2");
				} else {
					optionTextStr  = currOpt;
					optionValueStr = currOpt;
				}
				optionTextStr  = optionTextStr.replace(/\-\=1856\=\-/g, ":");
				optionValueStr  = optionValueStr.replace(/\-\=1856\=\-/g, ":");
				usedToTextAry[i] = optionTextStr;
				usedToValuAry[i] = optionValueStr;
				AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
			}	
/*
			for (i=2; i < arguments.length; i++) {
				if ((arguments[i].substring(0,2).toLowerCase() == "o:") && (arguments[1].toLowerCase() == "custom")) {
					if (arguments[i].substring(2,3) == " ") {
						arguments[i]=arguments[i].substring(3);
					} else {
						arguments[i]=arguments[i].substring(2);
					}
					arguments[i]=arguments[i].replace(/\\:/,"-=-1856-=-");
					if (arguments[i].indexOf(":") != -1) {
						outOneStr=arguments[i].replace(/(.+):(.+)/,"$2");
						outTwoStr=arguments[i].replace(/(.+):(.+)/,"$1");
						outOneStr=outOneStr.replace(/-=-1856-=-/,":");
						outTwoStr=outTwoStr.replace(/-=-1856-=-/,":");
						AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + outOneStr + "\">" + outTwoStr + "</OPTION>");
					} else {
						outOneStr=arguments[i].replace(/-=-1856-=-/,":");
						AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + outOneStr + "\">" + outOneStr + "</OPTION>");
					}
				} 
			}
*/
		} else {
			if (currRetItemVal == "") {
				AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"ThisIsASpacerDeleteMe\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</OPTION>");
			}
		}
		var shouldBeSkipped = false;
		var testingToBoxStr = new String("");
		for (i = 0; i < currRetItemAry.length; i++) {
			shouldBeSkipped = false;
			testingToBoxStr = currRetItemAry[i].replace(/^\s*/, "").replace(/\s*$/, "");

			if (testingToBoxStr == "") { shouldBeSkipped = true; }
			for (var cou=0; cou < usedToTextAry.length; cou++) {
				if (returnTypeText && (usedToTextAry[cou] == testingToBoxStr)) {
					shouldBeSkipped = true;
				} else if (!returnTypeText && (usedToValuAry[cou] == testingToBoxStr)) {
					shouldBeSkipped = true;
				}
			}
			if (shouldBeSkipped) {
				continue;
			}
			
			for (var cou=0; cou < currLeftOptionsAry.length; cou++) {
				currOpt = currLeftOptionsAry[cou];
				currOpt = currOpt.replace(/\\:/g,"-=1856=-");
				if (currOpt.search(/:/g) != -1) {
					optionTextStr  = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$1");
					optionValueStr = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$2");
				} else {
					optionTextStr  = currOpt;
					optionValueStr = currOpt;
				}
				optionTextStr  = optionTextStr.replace(/\-\=1856\=\-/g, ":");
				optionValueStr  = optionValueStr.replace(/\-\=1856\=\-/g, ":");
//				alert(cou + "\noptionTextStr: \t " + optionTextStr + "\noptionValueStr: \t " + optionValueStr + "\nreturnTypeText: \t " + returnTypeText + "\ntestingToBoxStr: \t " + testingToBoxStr);
				if (returnTypeText && (optionTextStr == testingToBoxStr)) {
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
				} else if (!returnTypeText && (optionValueStr == testingToBoxStr)) {
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
				}
			}			
			for (var cou=0; cou < currRightOptionsAry.length; cou++) {
				currOpt = currRightOptionsAry[cou];
				currOpt = currOpt.replace(/\\:/g,"-=1856=-");
				if (currOpt.search(/:/g) != -1) {
					optionTextStr  = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$1");
					optionValueStr = currOpt.replace(/^\s*(.+)\s*:\s*(.+)\s*$/, "$2");
				} else {
					optionTextStr  = currOpt;
					optionValueStr = currOpt;
				}
				optionTextStr  = optionTextStr.replace(/\-\=1856\=\-/g, ":");
				optionValueStr  = optionValueStr.replace(/\-\=1856\=\-/g, ":");
//				alert(cou + "\noptionTextStr: \t " + optionTextStr + "\noptionValueStr: \t " + optionValueStr + "\nreturnTypeText: \t " + returnTypeText + "\ntestingToBoxStr: \t " + testingToBoxStr);
				if (returnTypeText && (optionTextStr == testingToBoxStr)) {
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
				} else if (!returnTypeText && (optionValueStr == testingToBoxStr)) {
					AddRemovePopup.document.writeln("\t\t\t<OPTION VALUE=\"" + optionValueStr + "\">" + optionTextStr + "</OPTION>");
				}
			}			
		}
		AddRemovePopup.document.writeln("\t\t</SELECT>");
// Show Count
		if (ShowSelectedCount) {
			AddRemovePopup.document.writeln("<SPAN CLASS=\"CountStyle\" ID=\"ShowToSelectLayAll\"><SPAN ID=\"ShowToSelectCountLay\">" + currRightOptionsAry.length + "</SPAN>&nbsp;Item(s)&nbsp;Selected</SPAN>");
		}

		AddRemovePopup.document.writeln("\t</TD>\n</TR>\n</TABLE>");
		if (UseMaxSelect) {
			AddRemovePopup.document.writeln("<DIV ALIGN=\"center\" CLASS=\"CountStyle\" ID=\"MaxSelectLay\">*Note:&nbsp;&nbsp;Only&nbsp;" + NumMaxSelect + "&nbsp;Item(s)&nbsp;Are&nbsp;Allowed</div>");
		}
		AddRemovePopup.document.writeln("<BR>\n<NOBR><DIV ALIGN=\"CENTER\">\n\t<INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\" onClick=\"returnMySelections();\" NAME=\"OKButton\" ID=\"OKButton\"> &nbsp;&nbsp;&nbsp; <INPUT TYPE=\"button\" VALUE=\"&nbsp;&nbsp;&nbsp; Cancel &nbsp;&nbsp;&nbsp;\" onClick=\"self.close();\"></NOBR>");
	
		AddRemovePopup.document.writeln("</DIV>\n</FORM>");

/* START Groupbox format (B) */		
		AddRemovePopup.document.writeln("</TD>\n</TR>\n</TABLE>");

/* END Groupbox format (B) */		

		AddRemovePopup.document.writeln("\n<SCRIPT LANGUAGE=\"JavaScript\">");
		AddRemovePopup.document.writeln("\t var TAObj=document.AddRemoveForm.ToArea; ");
		AddRemovePopup.document.writeln("\t var FAObj=document.AddRemoveForm.FromArea; ");
		AddRemovePopup.document.writeln("\t var returningItem=window.opener." + returningItem + "; ");
		AddRemovePopup.document.writeln("\t var UseOtherRetItem=" + ((ARotherReturnItem != -1856)? "true" : "false") + ";");
		AddRemovePopup.document.writeln("\t var otherReturnItem=" + ARotherReturnItem + "; ");
		AddRemovePopup.document.writeln("\t var returnTypeText=" + returnTypeText + "; ");
		returnDelimiter=returnDelimiter.replace(/\n/g,"1856_CR");
		AddRemovePopup.document.writeln("\t var returnDelimiter=\"" + returnDelimiter + "\"; ");

		AddRemovePopup.document.writeln("\t var AddRemove_toNameLabel = new String(\"" + toNameLabel + "\"); ");
		AddRemovePopup.document.writeln("\t var AddRemove_DisableSortButtons = " + DisableSortButtons + "; ");
		AddRemovePopup.document.writeln("\t var AddRemove_UseMaxSelect = " + UseMaxSelect + "; ");
		AddRemovePopup.document.writeln("\t var AddRemove_NumMaxSelect = " + NumMaxSelect + "; ");
		AddRemovePopup.document.writeln("\t var AddRemove_OptionSelectedMultipleTimes = " + OptionSelectedMultipleTimes + "; ");
		AddRemovePopup.document.writeln("\t var AddRemove_ShowSelectedCount = " + ShowSelectedCount + "; \n");

		AddRemovePopup.document.write("\<\/");
		AddRemovePopup.document.write("SCRIPT\>");	
		AddRemovePopup.document.writeln("\n\n</BODY>\n</HTML>");
		AddRemovePopup.document.close();
	}
}

function AddRemoveComponent() {
	document.write("<A HREF=\"javascript: void AddRemoveItems(");
	
	ricolaAddRemoveCustomLeftItems[ricolaAddRemoveNumber]  = "";
	ricolaAddRemoveCustomRightItems[ricolaAddRemoveNumber] = "";
	var i=0;
	for (i=0; i < arguments.length; i++) {
		if (arguments[i].search(/^\s*i:/i) != -1) {
			ricolaAddRemoveCustomLeftItems[ricolaAddRemoveNumber] += arguments[i].replace(/^\s*i:\s*/i, "").replace(/\s*$/, "") + "-=-";
		} else if (arguments[i].search(/^\s*o:/i) != -1) {
			ricolaAddRemoveCustomRightItems[ricolaAddRemoveNumber] += arguments[i].replace(/^\s*o:\s*/i, "").replace(/\s*$/, "") + "-=-";		
		} else if (arguments[i].search(/^\s*use\s*custom\s*javascript\s*$/i) != -1) {
			AddRemove_useCustomJavaScript = true;
		} else if (arguments[i].search(/^\s*on\s*Before\s*Return\s*:/i) != -1) {
			AddRemove_useOnBeforeReturn = true;
			AddRemove_onBeforeReturn_functionName = arguments[i].replace(/^\s*on\s*Before\s*Return\s*:\s*/i, "");
			if (AddRemove_onBeforeReturn_functionName.indexOf("(") != -1) {
				AddRemove_onBeforeReturn_functionName = AddRemove_onBeforeReturn_functionName.substring(0, AddRemove_onBeforeReturn_functionName.indexOf("("));
			}
		} else if (arguments[i].search(/^\s*i_array:/i) != -1) {
			// Left-side elements are in an array

			// Get var name of left-side array
			var leftSideVar = arguments[i].replace(/^\s*i_array:\s*/i, "");

			// Iterate through left-side array and create delimited (-=-) list of left-side elements
			for (var c = 0; c < eval(leftSideVar).length; c++) {
				ricolaAddRemoveCustomLeftItems[ricolaAddRemoveNumber] += eval(leftSideVar)[c].replace(/\s*$/, "") + "-=-";
			}
			
		} else if (arguments[i].search(/^\s*o_array:/i) != -1) {
			// Right-side elements are in an array

			// Get var name of right-side array
			var rightSideVar = arguments[i].replace(/^\s*o_array:\s*/i, "");

			// Iterate through right-side array and create delimited (-=-) list of right-side elements
			for (var c = 0; c < eval(rightSideVar).length; c++) {
				ricolaAddRemoveCustomRightItems[ricolaAddRemoveNumber] += eval(rightSideVar)[c].replace(/\s*$/, "") + "-=-";
			}

		} else {
			document.write("'" + arguments[i] + "'");
			document.write(",");
		}
	}
	ricolaAddRemoveCustomLeftItems[ricolaAddRemoveNumber] = ricolaAddRemoveCustomLeftItems[ricolaAddRemoveNumber].replace(/-=-$/, "");
	ricolaAddRemoveCustomRightItems[ricolaAddRemoveNumber] = ricolaAddRemoveCustomRightItems[ricolaAddRemoveNumber].replace(/-=-$/, "");

	document.write("'AddRemoveNum: " + ricolaAddRemoveNumber + "'");
	document.write(");\"><IMG SRC=\"/graphics/apps/lookup.gif\" BORDER=\"0\" ALT=\"Look Up (Add/Remove Values)\" WIDTH=\"25\" HEIGHT=\"24\" TITLE=\"Look Up (Add/Remove Values)\" ALIGN=\"bottom\" VALIGN=\"bottom\"></A>");
	
	ricolaAddRemoveNumber++;
}

function RICOLAAddRemove_CheckCustomJS() {
	if (AddRemove_useCustomJavaScript) {
		RICOLA_AddRemoveHasReturned();
	}
}

function RICOLAAddRemove_CheckOnBeforeReturnJS() {
	if (AddRemove_useOnBeforeReturn) {
		eval(AddRemove_onBeforeReturn_functionName + "();");
	}
}
