// EKLIST functions

function EKListAdd(theList,theItem)
{
	var i = 0;
	if(theItem != '') 
	{
		var newItem = new Option();
		newItem.value = theItem;
		newItem.text = theItem;
		theList.options[theList.options.length] = newItem;
		theItem = "";
   	}
}	

function EKListItemToAdd(theSourceField,theTargetField)
{
	if (theSourceField.value == "")
	{
		alert("Please enter a new item to add to the list.");
		return false
	}
	else
	{
		theTargetField.value = theSourceField.value;
		return true
	}
}

function EKListItemToDelete(theList,theField)
{
	var daValue = '';
	for (var i=0; i<theList.options.length; i++) 
	{
		if(theList.options[i].selected && theList.options[i] != "") 
			daValue = theList.options[theList.selectedIndex].text;
	}
	if (daValue == '')
	{
		alert("Please select an item to delete.");
		return false
	}
	else
	{
		theField.value = daValue;
		return true
	}
}

function EKListDelete(theList)
{
	for (var i=0; i<theList.options.length; i++) 
	{
		if(theList.options[i].selected && theList.options[i] != "") 
		{
			theList.options[i].value = "";
			theList.options[i].text = "";
		}	
	}
	EKListMoveUp(theList);
}

function EKListMoveUp(aList) 
{
	for(var i = 0; i < aList.options.length; i++) 
	{
		if(aList.options[i].text == "")  
		{
			for(var j = i; j < aList.options.length - 1; j++)  
			{
				aList.options[j].value = aList.options[j + 1].value;
				aList.options[j].text = aList.options[j + 1].text;
			}
			var ln = i;
			break;
   		}
	}

	if(ln < aList.options.length)  
	{
		aList.options.length -= 1;
		EKListMoveUp(aList);
   	}
}

function EKListItems(theList)
{
	var theItems = '<EKLIST>';
	for (var i=0; i<theList.options.length; i++) 
	{
		if((theList.options[i] != "") && (theList.options[i].text != "")) 
		{
			theItems += "<OPTION>" + theList.options[i].text + "</OPTION>";
		}	
	}
	theItems += '</EKLIST>';	
	// alert (theItems);
	return theItems;
}
 
