function setUpRoles()
{
    var frm = document.forms[0];
    var boxActual = frm.ActiveRoles;
    var boxAvailable = frm.AvailableRoles;
    var actual = frm.Roles_.value;
    var available = frm.roles.value;
    var arrActual = actual.split(";");
    var arrAvailable = available.split(";");
    var hash = new Array();
    for ( i = 0; i < arrActual.length; i++ )
    {
        var item = arrActual[i];
        if ( item.length > 0 )
        {
            addOption( boxActual, item, item );
            hash[item] = item;
        }
    }
    for ( i = 0; i < arrAvailable.length; i++ )
    {
        var item = arrAvailable[i];
        if ( item.length > 0 && !hash[item] )
            addOption( boxAvailable, item, item );          
    }   
}

// append new value to the values in the list box
function addOption( ctrl, text, value )
{
    if ( document.all )
    {
        var oOption = document.createElement("OPTION");
        oOption.text = text;
        oOption.value = value;
        ctrl.options[ctrl.options.length] = oOption;
    }
    else
    {
        var oOption = new Option( text, value );
        ctrl.options[ctrl.options.length] = oOption;
    }
}

function addToActive()
{
    var frm = document.forms[0];
    var boxActual = frm.ActiveRoles;
    var boxAvailable = frm.AvailableRoles;
    if ( -1 == boxAvailable.selectedIndex )
        return;
    var role = boxAvailable.options[boxAvailable.selectedIndex].value;
    addOption( boxActual, role, role );
    boxAvailable.options[boxAvailable.selectedIndex] = null;
}

function removeFromActive()
{
    var frm = document.forms[0];
    var boxActual = frm.ActiveRoles;
    var boxAvailable = frm.AvailableRoles;
    if ( -1 == boxActual.selectedIndex )
        return;
    var role = boxActual.options[boxActual.selectedIndex].value;
    addOption( boxAvailable, role, role );
    boxActual.options[boxActual.selectedIndex] = null;  
}

function enableDisable( list, button )
{
    if ( -1 == list.selectedIndex )
        button.disabled = true;
    else
        button.disabled = false;
}

function makeDefault()
{
    var boxActual = document.forms[0].ActiveRoles;
    var selIndex = boxActual.selectedIndex;
    if ( selIndex < 1 )
        return;
    var role = boxActual.options[selIndex];
    var firstRole = boxActual.options[0];
    boxActual.options[selIndex] = null;
    boxActual.options[0] = role;
    boxActual.options[boxActual.options.length] = firstRole;
    boxActual.selectedIndex = 0;
}

function pickRoles()
{
    var boxActual = document.forms[0].ActiveRoles;
    var roles = document.forms[0].Roles_;   
    var str = "";
    for ( i = 0; i < boxActual.options.length; i++ )
    {
        str = str + ";" + boxActual.options[i].value;
    }
    // remove first ";"
    if ( str.length > 0 )
        str = str.substring(1);
    roles.value = str;
}

/* function stuffRoles()
{
    var combo = document.forms[0].Roles;
    var arr = opener.document.forms[0].Roles.value.split(";");
    for ( i = 0; i < arr.length; i++ )
    {
        if ( arr[i].length > 0 )
            addOption( combo, arr[i], arr[i] );     
    }
}	*/

function stuffRoles2() 
	{
    var combo = document.PW.Role;
    var arr = document.PW.RolesList.value.split(";");

    for ( i = 0; i < arr.length; i++ )
    	{
      	if ( arr[i].length > 0 )
      		{
          	addOption( combo, arr[i], arr[i] );
      		}
		}
	}
