/**
 * For the OLU we want to use Webcube's SwitchLanguageController. 
 * This script is to be injected, which will set the url2FR or url2EN variables appropriately...
 */

// The global url2 variables...
var url2FR = '/fr';
var url2EN = '/en';

/**
 * Sets the HREF attribute of the anchor with the ID "nl_switch" or "fr_switch".
 * Since IE6 doesn't work nicely with the onclick event switch, 
 * we're forced to use the default HREF attribute...
 * 
 * @param context           The application context
 * @param requestUri        The requestUri
 * @param activeChannel     The current activeChannel
 * @param currentLocale     The current Locale
 * @return
 */
function setSwitchLanguageLink(context, requestUri, activeChannel, currentLocale) {
    // This logic only applies as long as we have 2 languages!
    var newLocale = currentLocale == 'fr' ? 'en' : 'fr';
    context = context ? context : "";
    var controllerUrl = context + '/setlocale.html';
    var localeParam = 'LOCALE=' + newLocale.toUpperCase();
    var channelParam = 'ACTIVE_CHANNEL=' + activeChannel;
    var urlParam = 'REQUEST_URI=' + requestUri;
    var resultUri = controllerUrl + '?' + localeParam + '&' + channelParam + '&' + urlParam;
    var switchLink = document.getElementById(newLocale+'_switch');
//  switchLink.setAttribute("onclick", "javascript:switchLanguage('" + newLocale.toUpperCase() + "')");     // FF
//  switchLink.onclick = function(){switchLanguage(newLocale.toUpperCase())};                                   // IE 
//  switchLink.setAttribute("href", "javascript:void(0);");
    // Since IE6 has trouble with the onclick event, we just set the url2NL or url2FR vars...
    if (newLocale == 'fr') {
        url2FR = resultUri;
    } else {
        url2EN = resultUri;
    }
}
