// set cookie Lang
var cookieLangName	= "CK_SDC_LANG";

// Get cookie, param
var cookieLangValue = scGetCookie(cookieLangName);
var paramLangValue  = scGetURLParam('lang');

// Redirect to en if wrong language requested 
if( (paramLangValue != '') && (paramLangValue != 'en') && (paramLangValue != 'fr') && (paramLangValue != 'es') && (paramLangValue != 'zh') ) 
{
    // Set cookie en and redirect to page without any language
    setLangCookie('en');
    window.location = location.protocol + '//' + location.hostname + location.pathname;
}
else
{
	if(paramLangValue == '')
	{
		// no language specified in URL
		if( (cookieLangValue != '') && (cookieLangValue != 'en') ) redirectLang(cookieLangValue);
	}
	else
	{
		// language is specified
		if(paramLangValue == 'en')
		{
			// language en is specified
			if( (cookieLangValue != 'en') && (cookieLangValue != '') ) setLangCookie('en');
			// Do not redirect
		}
		else 
		{
			// Other language is specified
			if(cookieLangValue != paramLangValue) setLangCookie(paramLangValue);
			// Do not redirect
		}
	}
}

function redirectLang(lang)
{
    // build up the equivalent URL
    var newUrl = location.protocol + '//' + location.hostname + location.pathname + location.search;
    if(location.search=='') newUrl +='?'; else newUrl +='&';
    newUrl += 'lang=' + lang;

    // redirect
    window.location = newUrl;
}
		
function setLangCookie(lang)
{
	
	document.cookie = cookieLangName + "=" + escape(lang) + "; domain=.swift.com; expires=Sun, 19 May 2019 06:40:00 UTC; path=/";
}


