/**
* Contains all translations related functions
* Revision: $Revision$
*/


if (typeof Belgacom == 'undefined') Belgacom = {};

Belgacom.Translations = {

	// Current language we are viewing, default to EN, overwrite on page
	currentLanguage: 'EN',

	// Current region we are viewing, default to be, overwrite on page
	currentRegion: 'BE',

	// Are we running on the runtime? This makes a difference for our URLs refreshes
	isRuntime: 0,

	/**
	* Switches the language cookie
	*
	* Revision: $Revision$
	*/
	switchLanguage: function (language, new_url) {

		$.cookie('SiteLanguage', language, { path: '/', expires: 7 });

		if (this.isRuntime) {
			// if we are on the LiveSite runtime, then we need to refresh, the language in the url as well as cookie

			if (typeof new_url == 'undefined' || new_url === null) {
				// default to current page, if none supplied
				new_url = window.top.location.href;
			}
			
			// replace the existing culture segment with new one (if any exists!)
			window.location = new_url.replace(new RegExp("/(" + this.currentRegion + "-)[a-z]{2}/", 'i'), '/$1' + language.toLowerCase() + '/');

		}
		else {

			// otherwise we are in TeamSite, so just need to perform a refresh and everything will be fine...
			if (typeof new_url == 'undefined' || new_url === null) {
				// window.top needed for changing language in Edit mode where we are nested within a couple of iframes
				var theLocation = window.top.location;
				if (!/\?/.test(theLocation)) {
					theLocation = theLocation + "?"; // We need this as language switch does not work if no "?" in the URL
				}
				window.top.location = theLocation;
			}
			else {
				window.location = new_url;
			}
		}

	} // end switchLanguage()

};
