<!-- Begin
/********************************************************************************
 In the various routines, one or both of the following are passed:
 	N = The Newadd text element
	L = The list
 This is to generalize the processing so it can be used for multiple lists, on a
 single screen.
********************************************************************************/
var listname = "";
var newopt = new Option();

var i = 0;
var j = 0;
var start = 0;
var end   = 0;
var item  = 0;

		
/********************************************************************************
 Retrieve the List name. It's in a cookie called "ListName" that is created by
 lists.htm. if thislist == -1, this is lists.htm so skip this section.
********************************************************************************/
if (thislist != -1)
	{
	start = document.cookie.indexOf("ListName=");
	if (start == -1)
		listname = "List #" + thislist;
	else
		{
		start += 9;
		for (i= 0; i < thislist; i++)
			{
			item = document.cookie.indexOf(":", start);
			start = item + 1;
			}
		item = document.cookie.indexOf(":", start);
		listname = unescape(document.cookie.substring(start, item));
		}
	}

/********************************************************************************
 This routine creates a little "pop-up" window and puts the ListHelp page in it.
********************************************************************************/
function ListInfo()
   {
    win = window.open(helpscrn, "Help");
 
   if (parseInt(navigator.appVersion) >= 4)
	  win.window.focus();
   }

/********************************************************************************
 The List uses one cookie in the form:
          List1=item1:item2:item3; expires=date
 ...where the items are the individual List entries and the date is one year
 in the future. This routine retrieves the cookie and creates OPTION entries in
 the SELECT list from it.
********************************************************************************/
function getit(L)
	{
	start = document.cookie.indexOf(cook);
	if (start == -1)
		{
		newopt = new Option();
		newopt.value = 0;
		newopt.text = "";
		L.options[0] = newopt;
		return;
		}

	start += cook.length;

	end   = document.cookie.indexOf(";", start);
	if (end == -1)
		end = document.cookie.length;

	for (i= 0; start < end; i++)
		{
		newopt = new Option();

		item = document.cookie.indexOf(":", start);
		if ( (item == -1) || (item > end) )
			break;

		if (start == item)
			{
			newopt.value = "";
			newopt.text = "";
			}
		else
			{
			newopt.value = i;
			newopt.text = unescape(document.cookie.substring(start, item));
			}
			
		L.options[i] = newopt;
		start = item + 1;
		}

	while (i < L.options.length)
		L.options[i] = null;

	/******************************************************
	  Save the list again to update the expiration date.
	******************************************************/
	saveit(L);
	}

/********************************************************************************
 This routine creates the cookie from OPTION entries.
********************************************************************************/
function saveit(L)
	{
	var expDays = 3 * 365;
	var exp = new Date();
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	var values = cook;
		
	for (i = 0; i < L.options.length; i++)
		values = values + escape(L.options[i].text) + ":";

	values = values +  "; expires=" + exp.toGMTString();
	document.cookie = values;
	}

/**********************************************************************************
 This routine adds a new item to the List. The item is added after the highlighted
 list item. If there's no highlighted list item, it's added at the end.
**********************************************************************************/
function addit(N, L)
	{
	var text1 = "";
	var text2 = "";

	newopt = new Option();

	if (N.value == "")
		alert('Enter data in the "New Item" box.');
	else
		{
		text1 = N.value;

		for (i = 0; i < L.options.length; i++)
			if ( L.options[i].selected )
				{
				L.options[i].selected = false;
				break;
				}
		if ( i == L.options.length )
			j = i
		else j = i + 1;
		
		for (; j < L.options.length; j++)
			{
			text2 = L.options[j].text;
			L.options[j].text = text1;
			L.options[j].value = j;
			text1 = text2;
			}
		L.options[j] = newopt;
		L.options[j].text = text1;
		L.options[j].value = j;

		if ( i < j )
			L.options[i+1].selected = true;

		N.value = "";
		N.focus();
		
		saveit(L);          /* Save the list */
		}
	}

/********************************************************************************
 This routine retrieves a list item to the "New Item" area.
********************************************************************************/
function retrieve(N, L)
	{
	newopt = new Option();

	for (i = 0; i < L.options.length; i++)
		if ( L.options[i].selected )
			{
			N.value = L.options[i].text;
			break;
			}

	N.focus();
	}

/********************************************************************************
 This routine deletes items from the List by moving all lower entries up
 one notch. There's a special check for deleting the last item.
********************************************************************************/
function delit(L)
	{
	for (i = 0; i < L.options.length; i++)
		{
		while (L.options[i].selected)
			{
			L.options[i] = null;
			if ( i == L.options.length )
				break;
			}
		}

	saveit(L);                     /* Save the list */
	}

/********************************************************************************
 This routine replaces a name on the list.
********************************************************************************/
function replaceit(N, L)
	{
	newopt = new Option();

	if (N.value == "")
		alert('Enter data in the "New Item" box.');
	else
		{
		for (i = 0; i < L.options.length; i++)
			if (L.options[i].selected)
				break;

		if ( i	== L.options.length )
			alert("Highlight the List entry to be replaced.");
		else
			{
			newopt.value = i;
			newopt.text = N.value;
			L.options[i] = newopt;
			N.value = "";
			
			saveit(L);			/* save the list */
			}
		}

	N.focus();
	}

/********************************************************************************
 This routine moves an item up one position by reversing an item with the one
 immediately above it. You can't move items up higher than the top of the list.
********************************************************************************/
function upit(L)
	{
	for(i = 1; i < L.options.length; i++)
		{
		newopt = new Option();

		if ( L.options[i].selected && !L.options[i-1].selected )
			{
			newopt.value    = L.options[i].value;
			newopt.text     = L.options[i].text;

			L.options[i].value    = L.options[i-1].value;
			L.options[i].text     = L.options[i-1].text;
			L.options[i].selected = L.options[i-1].selected;
			
			L.options[i-1] = newopt;
			L.options[i-1].selected = true;
			}
		}

	saveit(L);                     /* Save the list */
	}

/********************************************************************************
 This routine moves an item down one position by reversing an item with the one
 immediately below it. You can move items below the bottom of the list. It's
 equivilent to adding a blank line above them.
********************************************************************************/
function downit(L)
	{
	for(i = L.options.length - 1; i > -1; i--)
		{
		newopt = new Option();

		if (L.options[i].selected)
			{
			newopt.value     = L.options[i].value;
			newopt.text      = L.options[i].text;

			if (i < L.options.length - 1)
				{
				L.options[i].value    = L.options[i+1].value;
				L.options[i].text     = L.options[i+1].text;
				L.options[i].selected = L.options[i+1].selected;
				}
			else
				{
				L.options[i].value    = "";
				L.options[i].text     = "";
				L.options[i].selected = 0;	
				}

			L.options[i+1] = newopt;
			L.options[i+1].selected = true;
			}
		}

	saveit(L);                     /* Save the list */
	}

/********************************************************************************
 Return to the List-of-Lists.
********************************************************************************/
function LofL()
	{
	document.location = "lists.htm";
	}

/********************************************************************************
 Invoke a list item.
********************************************************************************/
function gotoit(L)
	{
	for (i = 0; i < L.options.length; i++)
		if (L.options[i].selected)
			break;

	if ( i	== L.options.length )
		alert("Highlight the List we are to invoke.");
	else
		document.location = "list" + i + ".htm";
	}
//  End -->
