var gv_LockedItems = new Array();


/*=================================================

developed by: Ulf Gustafsson, Sublime Consulting AB

date: 2000-04-20


Script comments:

Theese scripts has been tested on the
following platforms.
---------------------------------------------------
2000-04-26: Win 2K - IE5 - all ok
2000-04-26: Win 98 - IE5 - all ok
2000-04-26: NT4 - IE4 - all ok
2000-04-26: iMac - IE4 - all ok
2000-04-26: iMac - NS4 - all ok ( no doubleclick )
2000-04-26: iMac - NS3 gold - all ok ( no doubleclick )
2000-04-26: Win 98 - NS4< - all ok ( no doubleclick )

=================================================*/


/*=================================================

method:

	xferOptItem()

description:

	transfers one or more selected
	options from one select element
	to	another.

arguments:

	String, name of the source element.

	String, name of the target element.

	integer,an integer representing the maximum
			of items that can be transfered to target
			element, 0 = unlimited

returns:

	boolean ( always true )

=================================================*/
function xferOptItem( strForm, strSource, strTarget, intMaxAllowed )
{
	var sourceElement = eval( "document.forms[strForm]." + strSource );
	var targetElement = eval( "document.forms[strForm]." + strTarget );
	var selectedItem = sourceElement.selectedIndex;
	var isLocked = false;
	while( selectedItem >= 0 )
	{
		isLocked = false;
		for(var iCount=0; iCount<gv_LockedItems.length; iCount++) {
			if(gv_LockedItems[iCount] == sourceElement[selectedItem].value) {
				isLocked = true;
			}
		}
		if( intMaxAllowed > 0 && targetElement.length >= intMaxAllowed ) return false;
		if(selectedItem < 0) return true;
		if(isLocked) return false;
		selectedOption = sourceElement.options[selectedItem];
		sourceElement[selectedItem].selected = false;
		var strVal = selectedOption.value;
		var strText = selectedOption.text;
		newItem = new Option(strText, strVal, false, false);
		targetElement[targetElement.length] = newItem;
		sourceElement[selectedItem].selected = true;
		sourceElement.options[selectedItem] =null;
		selectedItem = sourceElement.selectedIndex;
	}
	return true;
}

function delOptItem( strForm, strSource )
{
	var sourceElement = eval( "document.forms[strForm]." + strSource );
	var selectedItem = sourceElement.selectedIndex;
	while( selectedItem >= 0 )
	{
		if ( selectedItem < 0 ) return true;
		selectedOption = sourceElement.options[selectedItem];
		sourceElement.options[selectedItem] = null;
		selectedItem = sourceElement.selectedIndex;
	}
	return true;
}


/*=================================================

method:

	prepSubmit()

description:

	method which needs to be called before the form
	gets posted, loops through all items in the target
	element and selects them. This will enable the
	values to be read by the recieving script.

arguments:

	String, name of the target element.

returns:

	boolean ( allways true )

=================================================*/
function xferPrepSubmit( strForm, strTargetElement )
{
	var targetElement = eval( "document.forms[strForm]." + strTargetElement );
	var itemCount = targetElement.length;

	for(var i=0; i<itemCount; i++)
	{
		var optionItem = targetElement.options[i];
		optionItem.selected = true;
	}
	return true;
}

function xferSyncOptions(strForm, sIfIn, sRemoveFrom)
{
	var vObj = document.forms[strForm];
	if(!vObj) return;
	for(var i=0; i<vObj[sIfIn].options.length; i++)
	{
		var iID = vObj[sIfIn].options[i].value;
		for(var o=0; o<vObj[sRemoveFrom].options.length; o++)
		{
			if(iID==vObj[sRemoveFrom].options[o].value)
			{
				vObj[sRemoveFrom].options[o] = null;
			}
		}
	}
}
