// This function is called when a region in the market box has been selected.
// It uses the value of the selection in the market select box to fetch
// the language values from the market object to put into the language select box.
// The market object is generated and rendered dynamically in the LanguageSelector control.
function CmsaSelectLanguages(select, languageBoxClientId)
{
    var selectedText = select.options[select.options.selectedIndex].text;
    var selectedValue = select.options[select.options.selectedIndex].value;

    var languageBox = document.getElementById(languageBoxClientId);
    languageBox.options.length = 0;

    var langArray = marketObject[selectedValue];

    var first = true;

    for (var key = 0; key < langArray.size(); key++) {
        var newElement = document.createElement('option');
        newElement.text = langArray[key].Text;
        newElement.value = langArray[key].Value;

        /* First valid language shall be selected by default */
        newElement.selected = first;
        first = false;

        try {
            /* standards compliant; doesn't work in IE */
            languageBox.add(newElement, null);
        }
        catch (ex) {
            /* IE only */
            languageBox.add(newElement);
        }
    }
}
