// Global variables
// ------------------------------------------------------------------------
COOKIE_PATH =
    "/";
COOKIE_PREFIX         = "multiLingualSkin_";
RADIO_LANGUAGE_COOKIE = COOKIE_PREFIX + "radioLanguage";

function setLanguage(i)
{
    rl = window.document.forms.settings.radioLanguage;
    // Handle both multi- and mono-lingual causes.  In the
    // monolingual case, rl.length isn't defined.
    if (rl.length)
        rl[i].checked = true;
    else
        rl.checked = true;
    setCookie(RADIO_LANGUAGE_COOKIE, LANGUAGE_INDEX[i], cookieTime(), COOKIE_PATH);
    if (isParentForm())
    {
        // Handle both multi- and mono-lingual causes.  In the
        // monolingual case, rl.length isn't defined.
        if (parentForm().radioLanguage.length)
            parentForm().radioLanguage[i].checked = true;
        else
            parentForm().radioLanguage = checked;
        // Refresh the parent to show the new language there, too
        window.opener.location.reload();
    }
    // Show the new language using a refresh
    window.location.reload();
}

function getLanguage()
{
    // If we can find a cookie, use its' value
    if (getCookie(RADIO_LANGUAGE_COOKIE))
    {
        lang = getCookie(RADIO_LANGUAGE_COOKIE);
        // See if this language is available in this web page
        if (getLanguageIndex(lang) != -1)
            // Yes, so return it
            return(lang);
    }
    // No, so try getting data from (preferably) the parent page
    // or, if not, the current page
    form = isParentForm() ? parentForm() :
        window.document.forms.settings;
    if (!form || !form.radioLanguage)
        // The language buttons might not be in the web page
        // yet.  Pick the first language.
        return(LANGUAGE_INDEX[0]);
    // If there's just one button (a monolingual page), then
    // radioLanguage's length property is undefined.
    if (!form.radioLanguage.length)
        return(LANGUAGE_INDEX[0]);
    for (i = 0; i < form.radioLanguage.length; i++)
        if (form.radioLanguage[i].checked)
            return(LANGUAGE_INDEX[i]);
    alert("Error");
}

function getLanguageIndex(name)
{
    for (i = 0; i < LANGUAGE_INDEX.length; i++)
        if (name == LANGUAGE_INDEX[i])
            return(i);
    // No match
    return(-1);
}

function getLabel(givenLabel)
{
    if ((typeof(givenLabel) == "object"))
    {
        l = givenLabel[getLanguage()];
        if (l == undefined)
        {
            l = givenLabel[""];
            if (l == undefined)
                l = "";
        }
        return(l);
    } else
        return(givenLabel);
}

