function body_load(ddlCompanyEmployeeAmountId, pnlFunctionId, 
                   functionDomainValidatorId,
                   functionLevelValidatorId)
{
    var ddlCompanyEmployeeAmount = $get(ddlCompanyEmployeeAmountId);
    var pnlFunction = $get(pnlFunctionId);

    if (pnlFunction != null)
    {
        if(ddlCompanyEmployeeAmount.options[ddlCompanyEmployeeAmount.selectedIndex].value > 2)
        {
            pnlFunction.style.display = 'block';
            pnlFunction.style.visibility = '';
        }
    }
}

$(
    function()
    {
        bindPasswordRequiredPanelEvents();
    }
)

function bindPasswordRequiredPanelEvents()
{
    $('img#close-password-requirements-image').bind('click', onClosePasswordRequirementsClick);
    $('a#show-password-requirements-link').bind('click', onShowPasswordRequirementsClick);
}

function onClosePasswordRequirementsClick()
{
    $('div#password-requirements-text').hide();
}

function onShowPasswordRequirementsClick()
{
    $('div#password-requirements-text').show();
}

function RestoreSelectedItemsAfterPostBack(listBoxWithAllItemsId, listBoxWithSelectedItemsId, hiddenFieldId)
{
    var hiddenField = $get(hiddenFieldId);
        
    if(hiddenField.value != '')
    {
        var selectedItemsCollection = hiddenField.value.split(';');
        var listBoxWithAllItems = $get(listBoxWithAllItemsId);
        var listBoxWithSelectedItems = $get(listBoxWithSelectedItemsId);
                        
        for(var i = 0; i < selectedItemsCollection.length; i++)
        {
            for(var optionIndex = 0; optionIndex < listBoxWithAllItems.options.length; optionIndex++)
            {
                if(listBoxWithAllItems.options[optionIndex].value == selectedItemsCollection[i])
                {
                    listBoxWithAllItems.options[optionIndex].selected = true;
                    break;
                }
            }
        }
        
        SelectListBoxElements(listBoxWithAllItems, listBoxWithSelectedItems, hiddenField)
    }
}

function ddlCompanyEmployeeAmount_SelectedIndexChanged(ddlCompanyEmployeeAmountId, pnlFunctionId, fadeInAnimationId, fadeOutAnimationId)
{
    var pnlFunction = $get(pnlFunctionId);
    var ddlCompanyEmployeeAmount = $get(ddlCompanyEmployeeAmountId);

    if(ddlCompanyEmployeeAmount.options[ddlCompanyEmployeeAmount.selectedIndex].value > 2)
    {   
        if(pnlFunction.style.display == 'none')
        {
            pnlFunction.style.opacity = '';
            pnlFunction.style.filter = '';
            pnlFunction.style.visibility = '';
            pnlFunction.style.display = 'block';
        
            var fadeIn = $find(fadeInAnimationId).get_OnClickBehavior().get_animation();     
            fadeIn.set_target(pnlFunction);
            fadeIn.play();
        }
    }
    else
    {
        if(pnlFunction.style.display == 'block')
        {
            var fadeOut = $find(fadeOutAnimationId).get_OnClickBehavior().get_animation();
    
            fadeOut.set_target(pnlFunction);
            fadeOut.play();
            
            fadeOut.style.opacity = 0;
        }
    }
}

function SelectListBoxElements(allListBox, selectedListBox, hiddenField)
{
    MoveSelectedOptions(allListBox, selectedListBox);
    
    hiddenField.value = ConcatenateSelectedListBoxElements(selectedListBox);
}

function DeselectListBoxElements(allListBox, selectedListBox, hiddenField)
{
    MoveSelectedOptions(selectedListBox, allListBox);
    
    hiddenField.value = ConcatenateSelectedListBoxElements(selectedListBox);
}

function ConcatenateSelectedListBoxElements(selectedListBox)
{
    var result = '';
    
    for(var optionIndex = 0; optionIndex < selectedListBox.options.length; optionIndex++)
    {
        result = result + selectedListBox.options[optionIndex].value + ';';
    }
    
    result = result.substring(0, result.length - 1);
    
    return result;
}

function MoveSelectedOptions(fromListBox, toListBox, hiddenField)
{
    var selectedOptions = new Array();
    var selectedItemsCommaSeparated = '';
    
    for(var optionIndex = 0; optionIndex < fromListBox.options.length; optionIndex++)
    {
        if(fromListBox.options[optionIndex].selected == true)
        {
            Array.add(selectedOptions, fromListBox.options[optionIndex]);
        }
    }
    
    for(var selectedOptionIndex = 0; selectedOptionIndex < selectedOptions.length; selectedOptionIndex++)
    {
        fromListBox.removeChild(selectedOptions[selectedOptionIndex]);
        
        var inserted = false;
        
        for(var i = 0; i < toListBox.options.length; i++)
        {   
            if(toListBox.options[i].value > selectedOptions[selectedOptionIndex].value)
            {
                toListBox.insertBefore(selectedOptions[selectedOptionIndex], toListBox.options[i]);
                inserted = true;
                break; 
            }
        }
        
        if(!inserted)
        {
            toListBox.appendChild(selectedOptions[selectedOptionIndex]);
        }
    }
    
    fromListBox.selectedIndex = -1;
    toListBox.selectedIndex = -1;
}