// GetPickList returns the value from a single selection SELECT list
function GetPickList(thelist){
  var PickList='';
  for (var i=0; i < thelist.length; i++) {
  	//if (thelist.options[i]) {
	    if (thelist.options[i].selected) {
	      PickList = thelist.options[i].value;
	      return PickList;
	    }
	//}
  }
  return PickList;
}

// GetPickList returns the value from a single selection SELECT list
function GetPickListText(thelist){
  var PickList='';
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].selected) {
      PickList = thelist.options[i].text;
      return PickList;
    }
  }
  return PickList;
}

// Check to see if the default item is selected
function ItemSelected(thelist){
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].selected)
      return i;
  }
  return -1;
}
// Sets specific value in list
function setPickList(thelist, thevalue) {
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].value == thevalue) {
      thelist.options[i].selected = true;
      break;
    }
  }
}
// Sets specific value in list
function setPickListMulti(thelist, thevalue) {
  // first clear all previously selected options
  for (var i=0; i < thelist.length; i++) {
	thelist.options[i].selected = false;
  }
  for (var i=0; i < thelist.length; i++) {
    if (thelist.options[i].value == thevalue) {
      thelist.options[i].selected = true;
    }
  }
}
// kent Sets similar value in list used in places like quick fill 
function setPickListLike(thelist, thevalue) {
	for (var i=0; i < thelist.length; i++) {
		var thelistvalue = thelist.options[i].value.toLowerCase();
    	if (thelistvalue.substring(0,thevalue.length) == thevalue) {
	 		thelist.options[i].selected = true;
		break;
		}
	}
}
// kent Sets similar value in list
function setPickListLikeMulti(thelist, thevalue) {
	// first clear all previously selected options
	for (var i=0; i < thelist.length; i++) {
		thelist.options[i].selected = false;
	}
	// if the value is not null then loop thru
	if(thevalue.length>0){
		for (var i=0; i < thelist.length; i++) {
			var thelistvalue = thelist.options[i].value.toLowerCase();
	    	if (thelistvalue.substring(0,thevalue.length) == thevalue) {
		 		thelist.options[i].selected = true;
			}
		}
	}
}

// KPB Returns number of values selected from a MULTI-Select box KPB 12/16/2009
function GetPickListMultiSelected(thelist){
	var picklistselected = 0;
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			picklistselected += 1;
		}
	}
	return picklistselected;
}

// kent Returns comma delimited list of values from a MULTI-Select box kent 1/26/2001
function GetPickListMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += String(thelist.options[i].value);
		}
	}
	return picklist;
}
// kent Returns QUOTED comma delimited list of values from a MULTI-Select box kent 1/26/2001
function GetPickListMultiQuoted(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += "'" + String(thelist.options[i].value) + "'";
		}
	}
	return picklist;
}
// kent Returns comma delimited list of text from a MULTI-Select box kent 1/26/2001
function GetPickListTextMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			// determine if we need to start separating with commas 
			if(picklist > ""){
				picklist += ",";
			}
			picklist += String(thelist.options[i].text);
		}
	}
	return picklist;
}

// kent Removes all selected options from a MULTI-Select box kent 1/26/2001
function RemovePickListMulti(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if (thelist.options[i].selected) {
			thelist.options[i] = null;
			// recursively call itself until all are found and removed
			RemovePickListMulti(thelist);
		}
	}
}
// kent Moves options FROM a multi Select box to another kent 1/26/2001
function MovePickListMulti(fromlist,tolist){
	// create comma delim lists
	tempindex = GetPickListMulti(fromlist);
	temptext = GetPickListTextMulti(fromlist);

	// now remove the options from the fromlist
	temp = RemovePickListMulti(fromlist);

	// create arrays, loop thru and add to the tolist 
	var arrayindex = tempindex.split(",");
	var arraytext = temptext.split(",");
	var startat = tolist.length;
	for (var i=0; i < arrayindex.length; i++) {
		var newoption = startat + i;
		tolist.options[newoption] = new Option (arraytext[i], arrayindex[i]);
	}
}

// kent Returns comma delimited list of ALL values from a MULTI-Select box kent 1/26/2001
function GetPickListMultiAll(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if(picklist > ""){
			picklist += ",";
		}
		picklist += String(thelist.options[i].value);
	}
	return picklist;
}

// kent Returns comma delimited list of ALL text from a MULTI-Select box kent 1/26/2001
function GetPickListTextMultiAll(thelist){
	var picklist = "";
	for (var i=0; i < thelist.length; i++) {
		if(picklist > ""){
			picklist += ",";
		}
		picklist += String(thelist.options[i].text);
	}
	return picklist;
}


