<!-- Begin
// batch move from fmovename select to tmovename select, the data is taken from the array as 
// specified by the selected option from dropdownname dropdown.
function move_batch_from_dropdown ( form, fmovename, tmovename, dropdownname ){
	var fmovefield = form.elements[fmovename];
	var tmovefield = form.elements[tmovename];

	var dropdownfield = form.elements[dropdownname];
	var seldata = new Array();
	seldata = regions2cty[ dropdownfield.options[dropdownfield.selectedIndex].value ];

	for (var i=0;i<fmovefield.options.length;i++){
		var val = fmovefield.options[i];
		if (seldata[val.value])
		{
			val.selected = true;
		}
	}
	move(fmovefield, tmovefield);

}

// selects all the options for all the selects as specified by array fSels
function doSelectAllMulti(form, fSels){
for (var i=0;i<fSels.length;i++){ doSelectAll( form.elements[fSels[i]] ); }
}

// selects all the options for the select selObj
function doSelectAll(selObj){
 for(var x = 0; x < selObj.options.length; x++){
   selObj.options[x].selected = true;
 }
}

// checks if at least one option has been selected returns 0 otherwise
function checkOptions_Selected(form, fSels){
	for (var i=0;i<fSels.length;i++){ 
		var selected = document.forms[form].elements[fSels[i]].length;
		if (selected){
			return 1;
		}
	}
	return 0;
}

// moves selected options from fbox select to tbox select.  Optionally, you can disable resorting of the 
// options of either selects.
function move(fbox, tbox, dis_fsort, dis_tsort , maxno) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;

for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length;

for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if (fbox.options[i].selected && fbox.options[i].value != "") {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
if (!dis_fsort)
{
	arrFbox.sort();
}
if (!dis_tsort)
{
	arrTbox.sort();
}
fbox.length = 0;
tbox.length = 0;

// check for max group number of items to move
if (maxno){
	if ( arrTbox.length  > maxno ){
		alert("You can only select up to " + maxno + " items at a time" );
		// put the first n values into the to box
		for (c = 0; c < maxno; c++){
			var no = new Option();
			no.value = arrLookup[arrTbox[c]];
			no.text = arrTbox[c];
			tbox[c] = no;
		}
		// store the rejected items
		var count = 0;
		var backTofbox = new Array ();
		for (c = maxno; c < ( arrTbox.length); c++){
			backTofbox[count] = arrTbox[c];
			count++;
		}
		// add them to the from list
		for (var i = 0; i <  backTofbox.length; i++){
			arrFbox.push(backTofbox[i]);
		}

		// sort the list
		arrFbox = arrFbox.sort();

		// build from select
		for (d = 0 ; d < arrFbox.length ; d++){
			var no = new Option();
			no.value = arrLookup[arrFbox[d]];
			no.text = arrFbox[d];
			fbox[d] = no;
		}	
	}else{
		var c;
		for(c = 0; c < arrFbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrFbox[c]];
			no.text = arrFbox[c];
			fbox[c] = no;
		}
		for(c = 0; c < arrTbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrTbox[c]];
			no.text = arrTbox[c];
			tbox[c] = no;
		}
	}
} else {
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}

} // else

}

// move the selected option up
function moveUpList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == 0 ) {
               alert("The first entry in the list cannot be moved up.");
            } else {
               // Get the text/value of the one directly above the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected-1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected-1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected-1].text = moveText2;
               listField[selected-1].value = moveValue2;
               listField.selectedIndex = selected-1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

// move the selected option up
function moveDownList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == listField.length-1 ) {
               alert("The last entry in the list cannot be moved down.");
            } else {
               // Get the text/value of the one directly below the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected+1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected+1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected+1].text = moveText2;
               listField[selected+1].value = moveValue2;
               listField.selectedIndex = selected+1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

// End -->
