
<SCRIPT language=JAVASCRIPT>

function setCheckboxState(f,state)
{
	for (i=0; i< f.elements.length; i++) {
		if ("checkbox" == f.elements[i].type) {
			f.elements[i].checked = state;
		}
	}
}

function allSelectedIsAllCleared(f)
{
	return;		// don't do this any more
	for (i=0; i< f.elements.length; i++) {
		if ("checkbox" == f.elements[i].type) {
			if (f.elements[i].checked == false) {
				return;
			}
		}
	}
	for (i=0; i< f.elements.length; i++) {
		if ("checkbox" == f.elements[i].type) {
			f.elements[i].checked = false;
		}
	}
}

function addSelectToTextArea(ta,sel)
{
  var newline = "\n";
  if (sel.selectedIndex > 0) {
     ta.value = sel.options[sel.selectedIndex].text + newline + ta.value;
  }
}          
                                 
function doSelectChange(el,dest)
{
	dest.value = el.options[el.selectedIndex].text
}


function NS3PopulateCPListBox()
{
	var txtel = document.forms[0].textInput;
	popcount++;
	self.status="popcount = " + popcount + " letter = " + txtel.value;

	txtel.blur();
	populateCPListBox(txtel, document.forms[0].selectInput);

	if (!isDHTML)
		txtel._v = setTimeout("NS3PopulateCPListBox()",500);
	txtel.focus();
}

// populate dest (a list box) with choices matching substring
// in el (a text box).
// populate from the cp_? arrays, based on first letters of el.value
oldletter = ' ';
popcount = 0;
function populateCPListBox(el,dest)
{
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	var curValue = el.value.toLowerCase();
	if (curValue.length > 1) 
	{
		lookupItem(el,dest);
	}
	else	// populate list box with all partners beginning with
	{		// a certain letter
		if (curValue.length == 0) return;
		var letter = curValue.substring(0,1);	// NS 3.x can't use substr!!
		var index = alpha.indexOf(letter);
		if (index == -1) letter = "a";
		if (letter != oldletter)
		{
			var aname = eval("cp_" + letter);
			dest.length = 0;
			for (var i=0; i<aname.length; i++)
			{
				dest.options[dest.length] = new Option(aname[i],aname[i]);
			}
			if (dest.length) dest.options[0].selected = true;
			oldletter = letter;
		}
	}

} 

function lookupItem(el,dest)
{
	var curValue = el.value.toLowerCase()
	var found = false
	var index = dest.selectedIndex
	var numOptions = dest.options.length

	// clear all existing highlights
	for (var i=0; i<numOptions; i++)
	{
		dest.options[i].selected = false;
	}
	var pos = 0
	while ((!found) && (pos < numOptions)) 
	{
		found = (dest.options[pos].value.toLowerCase().indexOf(curValue)==0)
		if (found)
			index = pos
		pos++
	}
	if (found)
	{
		dest.options[index].selected = true;
	}
} 
 
function goValue(el)
{
  var where
  if (el.selectedIndex>-1) {
     where = el.options[el.selectedIndex].value
     window.open(where,"")
  }
}

var ie4 = false;
	if (document.all) ie4 = true;
var ns4 = false;
	if (document.layers) ns4 = true;
var isDHTML = ie4 || ns4;

sortitems = 1;	// Automatically sort items within lists? (1 or 0)

// Move a selection from the from box to the tobox, stripping
// off the parenthesized count at the end first
function move(fbox,tbox)
{
	// first, remove blank placeholder entry from tbox, if any
	// (it'll be the first choice)
	if(tbox.length && tbox.options[0].value == " ")
		tbox.length = 0;

	for(var i=0; i<fbox.length; i++)
	{
		if(fbox.options[i].selected && fbox.options[i].value != "")
		{
			var no 		= new Option();
			no.value 	= fbox.options[i].value;
			no.text 	= fbox.options[i].text;
			var x 		= no.value.lastIndexOf(" (");
			no.value 	= no.value.substring(0,x);
			tbox.options[tbox.length] = no;
		}
	}
	if (sortitems) SortDown(tbox);
}

// debugging function
function elToString(el) 
{
	var ret = "Select " + el.name + " is ["
	for (var prop in el)
		ret += "  " + prop + " is " + el[prop] + ";"
	return ret + "]"
}

function remove(listbox)
{
	// set selected lines to blank
	for(var i=0; i<listbox.length; i++)
	{
		if(listbox.options[i].selected)
		{
			listbox.options[i].value = "";
			listbox.options[i].text = "";
		}
	}
	
	// SortDown also removes the blank entries
	SortDown(listbox);
	
	// After a remove, nothing should be selected
	for(var i=0; i<listbox.length; i++)
	{
		listbox.options[i].selected = false;
	}
}                                

function compare_options(a,b)
{
	if (a.value < b.value) 
		return -1;
	else if (a.value > b.value)
		return 1;
	else return 0;
}

function SortDown(listbox)
{
	var temp_opts = new Array();  // of options
	for(var i=0; i<listbox.length; i++)
	{
		var opt = listbox.options[i];
		if (opt.value != "")
			temp_opts[temp_opts.length] = new Option(opt.text, opt.value);
	}
	temp_opts.sort(compare_options);
	
	listbox.length = 0;
	for(var j=0; j<temp_opts.length; j++)
	{
		listbox.options[listbox.length] = temp_opts[j];
	}
}

</SCRIPT>

