//Everything you see here was written by Guy Malachi guy@guymal.com
function MoveUp(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;
if (i>0)
{
swap(combo,i,i-1);
combo.options[i-1].selected=true;
combo.options[i].selected=false;
}
}
function MoveDown(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;
if (i<combo.length-1 && i>-1)
{
swap(combo,i+1,i);
combo.options[i+1].selected=true;
combo.options[i].selected=false;
}
}
//this function is used to swap between elements
function swap(combo,index1, index2)
{
var savedValue=combo.options[index1].value;
var savedText=combo.options[index1].text;
function MoveToTop(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;
for (;i>0;i--)
{
swap(combo,i,i-1);
combo.options[i-1].selected=true;
combo.options[i].selected=false;
}
}
function MoveToBottom(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;
if (i>-1)
{
for (;i<combo.length-1;i++)
{
swap(combo,i+1,i);
combo.options[i+1].selected=true;
combo.options[i].selected=false;
}
}
}
//moves options from one selection box (combo box) to another
//removes the all selected options from one combo box and adds them to the second combo box
function MoveElements(FromComboName,ToComboName)
{
var FromCombo=document.getElementById(FromComboName);
var ToCombo=document.getElementById(ToComboName);
var to_remove_counter=0; //number of options that were removed (num selected options)
//move selected options to right select box (to)
for (var i=0;i<FromCombo.options.length;i++)
{
if (FromCombo.options[i].selected==true)
{
var addtext=FromCombo.options[i].text;
var addvalue=FromCombo.options[i].value;
ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);
FromCombo.options[i].selected=false;
++to_remove_counter;
}
else
{
FromCombo.options[i-to_remove_counter].selected=false;
FromCombo.options[i-to_remove_counter].text=FromCombo.options[i].text;
FromCombo.options[i-to_remove_counter].value=FromCombo.options[i].value;
}
}
//now cleanup the last remaining options
var numToLeave=FromCombo.options.length-to_remove_counter;
for (i=FromCombo.options.length-1;i>=numToLeave;i--)
{
FromCombo.options[i]=null;
}
}
function toggleSelectAll(combo_name)
{
var select_all_link=document.getElementById('select_all_link');
var combo=document.getElementById(combo_name);//get the select
var to_select=true;
var select_link_new_caption;//the new "Select All" link caption will be here
if (select_all_link.unselectAll==true)//this is a new attribute that is dynamically added
{
//we now want to select all options
to_select=false;
select_all_link.unselectAll=false;
select_link_new_caption="Select All";//set the new caption
}
else
{
//we now want to unselect all options
select_all_link.unselectAll=true;
select_link_new_caption="Unselect All";//set the new caption
}
select_all_link.innerText=select_link_new_caption;//change the caption of the select all link
SelectAll(combo,to_select);
}
//select is true for selecting all, false for unselecting all
function SelectAll(combo,select)
{
for (var i=0;i<combo.options.length;i++)
{
combo.options[i].selected=select;
}
}
//-->
</script>