﻿/// <reference path="JsLib.js" />
var TM = {
	Print: function() {
		TM.GoogleAnalytics.customLink("print", "print:" + TM.GoogleAnalytics.getDirectLinkValue(), "");
		top.print();
	}
};

TM.Partner = {
	display: function() {
		var div = $('div_footerpartners');
		JsLib.Utilities.ShowHide('div_footerpartners');
		div.style.marginTop = -(JsLib.Positioner.GetElementSize(div).y - 200);
		top.TM.Footer.SetPosition();
	}
}

TM.Search = {
	trackGAResult: function(qty) {
		var utm_keyword = location.pathname.match(/([^/]*)$/i);
		TM.GoogleAnalytics.setPagename(location.pathname,"utm_keyword="+utm_keyword[1]+"&utm_nbresults="+(qty>0 ? "match":"none"));
	}
}

TM.ReserveOnline = {
	Redirect: function(gakey, url, blank, key) {
		TM.GoogleAnalytics.customLink("reservation:" + TM.GoogleAnalytics.getDirectLinkValue(), "reservation:" + TM.GoogleAnalytics.getDirectLinkValue() + ":" + key, ""); TM.GoogleAnalytics.trackCommerce("reservation", key, "reservation:" + key);
		ADCENTRIC.tourmtl.callPixels()
		if (blank) window.open(url);
		else top.location = url;
	}
};

TM.GreyBox = {
	Opacity: 0.8,
	Duration: 0.2,
	Initialize: function() {
		$$('body')[0].appendChild(Builder.node('div', { id: 'greybox-overlay' }));
		var overlay = $('greybox-overlay');
		overlay.hide();
		this['overlay'] = overlay;
	},
	Show: function() {
		var arrayPageSize = JsLib.Utilities.GetPageSize();

		$$('select', 'object', 'embed').each(function(node) { node.style.visibility = 'hidden' });
		this.overlay.setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
		new Effect.Appear(this.overlay, { duration: this.Duration, from: 0.0, to: this.Opacity });
	},
	Hide: function() {
		new Effect.Fade(this.overlay, { duration: this.Duration });
		$$('select', 'object', 'embed').each(function(node) { node.style.visibility = 'visible' });
	}
};

TM.Toolkit = {
	previewWindow: null,
	Timeout: {
		timeoutID: 0,
		SetTimeout: function(url) {
			this.timeoutID = window.setTimeout('Refresh(\'' + url + '\');', 5000);
		},
		ClearTimeout: function() {
			window.clearTimeout(this.timeoutID);
		}
	},
	downloadPopUp: function ToolkitDownload(key, qty, lang, vidformat) {
		var url = '/Tools/ToolkitDownload.aspx?key=' + key + '&qty=' + qty + '&lang=' + lang + '&videoformat=' + vidformat + '&langid=' + currentLanguageId;
		JsLib.POPUP.Window(url, 400, 150, 'ToolkitDownload');
	},
	createPreview: function(o, url) {
		var div = $(o.id + '_preview');
		if (null == div) {
			div = document.createElement('div');
			div.id = o.id + '_preview';
			div.style.position = 'absolute';
			o.appendChild(div);
			var content = JsLib.Ajax.LoadTEXT(url);
			div.innerHTML = content;
			div.style.display = 'block';
			div.style.marginLeft = '10px';
			this.previewWindow = div;
		}
	},
	previewImage: function(o, url) {
		this.closePreview();
		this.createPreview(o.parentNode, '/Tools/ToolkitPreviewImage.aspx?url=' + url + '&langid=' + currentLanguageId);
	},
	previewVideo: function(o, url) {
		this.closePreview();
		this.createPreview(o.parentNode, '/Tools/ToolkitPreviewVideo.aspx?url=' + url + '&langid=' + currentLanguageId);
	},
	previewLoop: function(o, vi, url) {
		this.closePreview();
		var div = $(o.id + '_previewloop');
		if (null == div) {
			switch (vi) {
				case 1: url = '/Tools/ToolkitPreviewImage.aspx?url=' + url + '&langid=' + currentLanguageId; break;
				case 2: url = '/Tools/ToolkitPreviewVideo.aspx?url=' + url + '&langid=' + currentLanguageId; break;
			}
			div = document.createElement('div');
			div.id = o.id + '_previewloop';
			div.style.position = 'absolute';
			o.parentNode.appendChild(div);
			var content = JsLib.Ajax.LoadTEXT(url);
			div.innerHTML = content;
			div.style.display = 'block';
			div.style.marginLeft = (-(JsLib.Positioner.GetElementSize(div).x + 30)) + 'px';
			this.previewWindow = div;
		}
	},
	closePreview: function() {
		if (null != this.previewWindow && null != this.previewWindow.parentNode) {
			this.previewWindow.parentNode.removeChild(this.previewWindow);
			this.previewWindow = null;
		}
	}
};

TM.ShowNearBy = {
	isOpen: false,
	isLoaded: false,
	Select: function(cddid, objid, text, value, control) {
		$(cddid).innerHTML = text;
		TM.GoogleAnalytics.trackEvent('map', 'proximite', text + ':' + TM.GoogleAnalytics.getDirectLinkValue(), '');
		window.setTimeout('TM.ShowNearBy.Open(\'' + objid + '\',\'' + value + '\',\'' + control + '\')', 1);
	},
	Open: function(oid, typeto, control) {
		var iframe = $('iframe_shownearby');
		if (!this.isLoaded) {
			if (!this.isOpen) {
				Effect.SlideDown($('shownearby_iframe'), { duration: 0.5 });
				$('content').style.display = 'none';
			}
			iframe.src = '/Tools/ShowNearBy.aspx?control=' + control + '&objectid=' + oid + '&typeto=' + typeto + '&langid=' + currentLanguageId + '&SiloID=' + currentSiloId + '&typefrom=' + currentWebSiloSectionId;
		} else {
			if (!this.isOpen) {
				Effect.SlideDown($('shownearby_iframe'), { duration: 0.5, afterFinishInternal: function() { iframe.contentWindow.RefreshShowNearBy(oid, typeto, control); } });
				$('content').style.display = 'none';
			}
		}
		this.isOpen = true;
		this.isLoaded = true;
	},
	Close: function() {
		$('content').style.display = 'block';
		Effect.SlideUp($('shownearby_iframe'), { duration: 0.5, afterFinishInternal: function() { $('shownearby_iframe').style.display = 'none'; top.TM.Footer.SetPosition(); } });
		this.isOpen = false;
	},
	CloseOnLoad: function() {
		if (this.isOpen)
			this.Close();
	}
};

TM.PopUpWarning = {
	timerId: new Array(),
	DisplayWarning: function(name) {
		window.setTimeout('TM.PopUpWarning.DisplayDelay(\'' + name + '\')', 1000);
	},
	DisplayDelay: function(name) {
		var width = 385;
		var div = $(name);
		if (null == div) {
			div = document.createElement('div');
			div.id = name;
			div.className = 'PopUpWarning';
			div.style.position = 'absolute';
			div.style.width = width + 'px';
			div.style.top = '150px';
			div.style.left = ((screen.width) ? (screen.width - 385) / 2 : 100) + 'px';
			div.style.zIndex = 5000;
			div.innerHTML = JsLib.Ajax.LoadTEXT('/Tools/StaticContent.aspx?langid=' + currentLanguageId + '&c='+name);
			document.body.appendChild(div);
		}
		div.style.display = 'block';
		this.timerId[name] = window.setTimeout('TM.PopUpWarning.Close(\''+name+'\')', 15000);
	},
	Close: function(name) {
		$(name).style.display = 'none';
		window.clearTimeout(this.timerId[name]);
	}
};

TM.Help = {
	visible: false,
	divId: 'div_help',
	helpTypeId: -1,
	Open: function() {
		JsLib.POPUP.Window((currentLanguageId == 1 ? '/Aide' : '/Help'), 550, 400, 'Help');
	}
};

TM.LegalNotice = {
	visible: false,
	divId: 'div_legalnotice',
	legalNoticeO: -1,
	Open: function(o, legalnoticeid, width, offsetX, offsetY, closeID) {
		if (this.visible && o == this.legalNoticeO) {
			this.Close();
			return;
		}
		this.legalNoticeO = o;
		var divLegalNotice = $(this.divId);
		if (null == divLegalNotice) {
			divLegalNotice = document.createElement('div');
			divLegalNotice.style.position = 'absolute';
			divLegalNotice.style.zIndex = 1000;
			divLegalNotice.id = this.divId;
		}
		var p = JsLib.Positioner.GetAbsolutePos(o);
		var s = JsLib.Positioner.GetElementSize(o);
		divLegalNotice.style.width = width + 'px';
		divLegalNotice.innerHTML = JsLib.Ajax.LoadTEXT('/Tools/LegalNotice.aspx?legalnoticeid=' + legalnoticeid + '&langid=' + currentLanguageId);
		o.parentNode.appendChild(divLegalNotice);
		divLegalNotice.style.display = 'block';
		divLegalNotice.style.marginTop = '12px';
		divLegalNotice.style.marginLeft = '-77px';
		this.visible = true;
		new Draggable(this.divId, { scroll: window, handle: 'htmlpopup_drag' });
	},
	Close: function() {
		$(this.divId).style.display = 'none';
		this.visible = false;
	}
};

TM.FAQ = {
	activeCounter: -1,
	Display: function(counter) {
		if (this.activeCounter > -1 && this.activeCounter != counter) {
			JsLib.Utilities.ShowHide('item' + this.activeCounter);
			JsLib.Utilities.ShowHide('itemt' + this.activeCounter);
		}
		JsLib.Utilities.ShowHide('item' + counter);
		JsLib.Utilities.ShowHide('itemt' + counter);
		this.activeCounter = counter;
		top.TM.Footer.SetPosition();
	},
	Hide: function(counter) {
		JsLib.Utilities.ShowHide('item' + counter);
		JsLib.Utilities.ShowHide('itemt' + counter);
		this.activeCounter = -1;
		top.TM.Footer.SetPosition();
	}
};

TM.ViewJournal = {
	activeCounter: -1,
	Display: function(counter) {
		if (this.activeCounter > -1 && this.activeCounter != counter) {
			JsLib.Utilities.Hide('item' + this.activeCounter);
		}
		JsLib.Utilities.ShowHide('item' + counter);
		this.activeCounter = counter;
	},
	ImageSource: function(imgID, imgUrl) {
		$(imgID).src = imgUrl;
	}
};

/* TABS */
TM.Tabs = {
	currentTab: '',
	Initialize: function() {
		var a = TM.Tabs.Initialize.arguments;
		for (i = 1; i < a.length; i++) {
			$addHandler($(a[i]), 'click', ($(a[i])).onclick = function() {
				TM.Tabs.Activate(this); return false;
			});
			currentTab = a[0];
			($(a[0])).className = "tab roll";
		}
	},
	Activate: function(obj) {
		if (obj.id != currentTab) {
			TM.GoogleAnalytics.customLink('switch_tab', 'switch_tab:' + obj.innerHTML + ':' + TM.GoogleAnalytics.getDirectLinkValue(), '');
			$("div" + currentTab).className = "tab_section hidden";
			$("div" + obj.id).className = "tab_section";
			$(currentTab).className = "tab";
			$(obj.id).className = "tab roll";
			currentTab = obj.id;
			var t = $(currentTab);
			if (null != t.attributes['ontabclick'] && null != t.attributes['ontabclick'].value) {
				window.setTimeout(t.attributes['ontabclick'].value, 1);
				t.attributes['ontabclick'].value = null;
			}
			top.TM.Footer.SetPosition();
		}
	}
};

/* TOOLBAR */
TM.Toolbar = {
	LinkToThisPage: {
		Display: function(obj, oid) {
			if (JsLib.Utilities.ShowHideR('linktothispage')) {
				var div = $('linktothispage');
				$(oid).select();
				TM.Toolbar.LinkSendToFriend.Hide();
				TM.GoogleAnalytics.customLink('direct_link','direct_link:'+TM.GoogleAnalytics.getDirectLinkValue(),'');
			}
		},
		Hide: function() {
			JsLib.Utilities.Hide('linktothispage');
		}
	},
	LinkSendToFriend: {
		Display: function(obj, txt) {
			if (JsLib.Utilities.ShowHideR('sendtofriend')) {
				var div = $('sendtofriend');
				($(txt)).focus();
				TM.Toolbar.LinkToThisPage.Hide();
				TM.GoogleAnalytics.customLink("send_to_friend", "send_to_friend_form:" + TM.GoogleAnalytics.getDirectLinkValue(), "");
			}
		},
		Hide: function(txt) {
			JsLib.Utilities.Hide('sendtofriend');
		}
	},
	LanguageMenu: {
		IsVisible: false,
		Initialize: function(clientId) { },
		Display: function(obj, oid) {
			if (this.IsVisible) {
				TM.Toolbar.LanguageMenu.Hide();
			} else {
				var div = $('languagemenu');
				div.style.display = 'block';
				this.IsVisible = true;
			}
		},
		Hide: function() {
			var div = $('languagemenu');
			div.style.display = 'none';
			this.IsVisible = false;
		}
	}
};

TM.Footer = {
	footerID: 'partners_main_panel',
	SetPosition: function() {
		var footer = $(TM.Footer.footerID);

		if (footer) {
			var sizeFooter = footer.getDimensions();

			if (document.body.clientHeight + sizeFooter.height <= document.documentElement.clientHeight) {
				footer.style.top = (document.documentElement.clientHeight - sizeFooter.height) + 'px';
				footer.style.visibility = 'visible';
			}
			else {
				footer.style.top = document.body.clientHeight + 'px';
				footer.style.visibility = 'visible';
			}
		}
	}
}

/* FLASH */
TM.Flash = {
	ReadCuePoint: function() {
		return document.cookie;
	},
	WriteCuePoint: function(cuePoint) {
		document.cookie = cuePoint;
	},
	Create: function(swf, path) {
		var so = new SWFObject(swf, 'TMFlash', '975', '525', '8', '#766E63');
		so.addParam('allowScriptAccess', 'sameDomain');
		so.addParam('quality', 'high');
		so.addParam('align', 'middle');
		so.addParam('play', 'true');
		so.addParam('loop', 'true');
		so.addParam('scale', 'noscale');
		so.addParam('wmode', 'transparent');
		so.addParam('devicefont', 'false');
		so.addParam('menu', 'true');
		so.addParam('allowFullScreen', 'false');
		so.addParam('allowScriptAccess', 'sameDomain');
		so.addParam('salign', '');
		so.addParam('defer', 'defer');
		so.addVariable('path', path);
		so.addVariable('Silo', currentSiloId);
		so.addVariable('LangID', currentLanguageId);
		so.write('panel_flash');
	},
	FullScreen: {
		widthContenu: 975,
		ratio: 3.66,
		imageID: null,
		buttonID: 'pnlMiddleButton',
		campaignButtonID: 'pnlCampaignButton',
		headerID: 'pnlHeader',
		logoID: 'pnlLogo',
		Initialize: function(imageID) {
			this.imageID = imageID;
			this.SetPosition();

			Event.observe(window, 'resize', this.SetPosition);
		},
		SetPosition: function() {
			var widthBgImg = (document.documentElement.clientWidth < TM.Flash.FullScreen.widthContenu) ? TM.Flash.FullScreen.widthContenu : document.documentElement.clientWidth;
			var heightBgImage = widthBgImg / TM.Flash.FullScreen.ratio;
			var sizeBtn = $(TM.Flash.FullScreen.buttonID).getDimensions();
			var sizeMenu = $(TM.Flash.FullScreen.headerID).getDimensions();

			new Effect.Morph(TM.Flash.FullScreen.imageID, { style: { width: widthBgImg + 'px' }, duration: 0.1, afterFinishInternal: function() { TM.Footer.SetPosition(); } });
			new Effect.Morph(TM.Flash.FullScreen.buttonID, { style: { top: (heightBgImage / 2 - sizeBtn.height / 2) + 'px', left: (widthBgImg / 2 - sizeBtn.width / 2) + 'px' }, duration: 0.1, afterFinishInternal: function() { $(TM.Flash.FullScreen.buttonID).style.visibility = 'visible'; } });

			if ($(TM.Flash.FullScreen.campaignButtonID) != null) {
				var sizeBtnCampaign = $(TM.Flash.FullScreen.campaignButtonID).getDimensions();
				new Effect.Morph(TM.Flash.FullScreen.campaignButtonID, { style: { top: (heightBgImage / 2 - sizeBtnCampaign.height / 2) + 'px', left: ((widthBgImg - TM.Flash.FullScreen.widthContenu) / 2) + TM.Flash.FullScreen.widthContenu - sizeBtnCampaign.width + 'px' }, duration: 0.1, afterFinishInternal: function() { $(TM.Flash.FullScreen.campaignButtonID).style.visibility = 'visible'; } });
			}

			if ($(TM.Flash.FullScreen.logoID) != null) {
				var sizeLogo = $(TM.Flash.FullScreen.logoID).getDimensions();
				new Effect.Morph(TM.Flash.FullScreen.logoID, { style: { top: (heightBgImage - sizeLogo.height - 6) + 'px', left: ((widthBgImg - TM.Flash.FullScreen.widthContenu) / 2) + TM.Flash.FullScreen.widthContenu - sizeLogo.width + 3 + 'px' }, duration: 0.1, afterFinishInternal: function() { $(TM.Flash.FullScreen.logoID).style.visibility = 'visible'; } });
			}
		}
	}
};

TM.Cookie = {
	getCookie: function(NameOfCookie) {
		if (document.cookie.length > 0) {
			begin = document.cookie.indexOf(NameOfCookie + "=");
			if (begin != -1) {
				begin += NameOfCookie.length + 1;
				end = document.cookie.indexOf(";", begin);
				if (end == -1) {
					end = document.cookie.length;
				}
				return unescape(document.cookie.substring(begin, end));
			}
		}
		return null;
	},
	setCookie: function(NameOfCookie, value, expiredays) {
		var ExpireDate = new Date();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
	},
	delCookie: function(NameOfCookie) {
		if (getCookie(NameOfCookie)) {
			document.cookie = NameOfCookie + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}
};

/* MAP */
TM.Map = {
	ViewLarger: function(boxSmall, boxLarge, googleVar, latitude, longitude) {
		var s = $(boxSmall);
		var l = $(boxLarge);
		l.style.zIndex = 15000;
		var ss = JsLib.Positioner.GetElementSize(s);
		var sp = JsLib.Positioner.GetAbsolutePos(s);
		l.style.position = 'absolute';
		l.style.top = sp.y + 'px';
		l.style.left = ((ss.x + sp.x) - 618) + 'px';
		l.style.display = 'block';
		googleVar.checkResize();
		googleVar.setCenter(new GLatLng(latitude, longitude), googleVar.getZoom());
	},
	CloseLargerMap: function(boxLarge) {
		var l = $(boxLarge);
		l.style.display = 'none';
	}
};

/* COMMENTS */
TM.Comments = {
	DisplayList: function(o, oid, divlistid, divnewid) {
		$(divlistid).style.display = '';
		$(divnewid).style.display = 'none';
		o.className = 'selected';
		$(oid).className = '';
		top.TM.Footer.SetPosition();
		return false;
	},
	DisplayNew: function(o, oid, divlistid, divnewid, titleid) {
		$(divlistid).style.display = 'none';
		$(divnewid).style.display = '';
		o.className = 'selected';
		$(oid).className = '';
		$(titleid).focus();
		top.TM.Footer.SetPosition();
		return false;
	},
	OpenAbusive: function(commentid, languageid) {
		JsLib.POPUP.WindowNoScroll('/Silos/Common/Popups/AbusiveContent.aspx?langid=' + languageid + '&commentid=' + commentid, 332, 232, 'reportabuse');
	}
};

TM.Itinerary = {
	ItineraryId: null,
	DeleteConfirm: function(o, itineraryid) {
		this.ItineraryId = itineraryid;
		var panel = $('itinerary_delete');
		var p1 = JsLib.Positioner.GetAbsolutePos(o);
		var s1 = JsLib.Positioner.GetElementSize(o);
		panel.style.top = p1.y + 'px';
		panel.style.left = (p1.x + s1.x + 10) + 'px';
		panel.style.display = 'block';
	},
	Delete: function() {
		ItineraryDelete(this.ItineraryId);
		$('itinerary_delete').style.display = 'none';
	},
	Cancel: function() {
		$('itinerary_delete').style.display = 'none';
		this.ItineraryId = null;
	},
	OpenInappropriateContent: function(itineraryid, languageid) {
		JsLib.POPUP.WindowNoScroll('/Silos/Common/Popups/InappropriateContent.aspx?langid=' + languageid + '&itineraryid=' + itineraryid, 350, 260, 'reportinappropriatecontent');
	}
};

TM.FileType = {
	Validate: function(sender, args) {
		var regularExpression = sender.getAttribute('RegularExpression');
		var ex = new RegExp(regularExpression, "i");
		args.IsValid = ex.test(args.Value);
	}
};

/* NAVIGATION */
TM.Navigation = {
	ResizeFlash: function(url, h) {
		top.location.href = url;
	}
};

/* PANELS */
TM.Panels = {
	MainMenu: null,
	SubMenu: null,
	Filters: null,
	ToolBarResultBack: null,
	ContentMiddle: null,
	ContentMiddleLarge: null,
	Footer: null,
	Home: null,
	IFrameMyMontreal: null,
	IFrameMyBookmarks: null,
	TopNavMenu: null,
	TopNavBar: null,
	TopPnlRFP: null,
	TopPnlToolkit: null,
	TopPnlTrips: null,
	PnlMyMontreal: null,
	PnlMyBookmarks: null,
	Initialize: function() {
		this.MainMenu = this.InitializePanel($('main_menu'), true);
		this.SubMenu = this.InitializePanel($('submenu'), true);
		this.Filters = this.InitializePanel($('filters'), true);
		this.ToolBarResultBack = this.InitializePanel($('toolbar'), true);
		this.ContentMiddle = this.InitializePanel($('content'), true);
		this.ContentMiddleLarge = this.InitializePanel($('content_middle'), true);
		this.Footer = this.InitializePanel($('footer'), true);
		this.IFrameMyMontreal = this.InitializePanel($('iframe_mymontreal'), false);
		this.IFrameMyBookmarks = this.InitializePanel($('iframe_mybookmarks'), false);
		this.TopNavMenu = this.InitializePanel($('top_nav_menu'), false);
		this.TopNavBar = this.InitializePanel($('pnlTopNavBar'), true);
		this.TopPnlRFP = this.InitializePanel($('pnlRFP'), false);
		this.TopPnlToolkit = this.InitializePanel($('pnlToolkit'), false);
		this.TopPnlTrips = this.InitializePanel($('pnlTrips'), false);
		this.PnlMyMontreal = this.InitializePanel($('pnlMyMontreal'), false);
		this.PnlMyBookmarks = this.InitializePanel($('pnlMyBookmarks'), false);
	},
	InitializePanel: function(o, visible) {
		if (null != o) {
			o.Show = function() {
				this.style.display = '';
				this.previousVisibility = this.isVisible;
				this.isVisible = true;
			};
			o.Hide = function() {
				this.style.display = 'none';
				this.previousVisibility = this.isVisible;
				this.isVisible = false;
			};
			o.RestoreVisibility = function() {
				if (this.previousVisibility) {
					this.style.display = '';
				} else {
					this.style.display = 'none';
				}
				this.isVisible = this.previousVisibility;
			};
			o.isVisible = visible;
		}
		return o;
	},
	InitializePanelIFrame: function(o, visible) {
		if (null != o) {
			o.IFrame = $(o.attributes['IFrameID'].value);
			o.Show = function() {
				this.style.display = '';
				this.previousVisibility = this.isVisible;
				this.isVisible = true;
			};
			o.Hide = function() {
				this.style.display = 'none';
				this.previousVisibility = this.isVisible;
				this.isVisible = false;
			};
			o.RestoreVisibility = function() {
				if (this.previousVisibility) {
					this.style.display = 'content';
				} else { this.style.display = 'none'; }
				this.isVisible = this.previousVisibility;
			};
			o.isVisible = visible;
		}
		return o;
	},
	ShowPanels: function() {
		var panels = arguments;
		for (var i = 0; i < panels.length; i++) {
			if (null != panels[i]) { panels[i].Show(); }
		}
	},
	HidePanels: function() {
		var panels = arguments;
		for (var i = 0; i < panels.length; i++) {
			if (null != panels[i]) { panels[i].Hide(); }
		}
	},
	RestoreAllVisibility: function() {
		if (null != TM.Panels.SubMenu)
			TM.Panels.SubMenu.RestoreVisibility();
		if (null != TM.Panels.MainMenu)
			TM.Panels.MainMenu.RestoreVisibility();
		if (null != TM.Panels.IFrameMyMontreal)
			TM.Panels.IFrameMyMontreal.RestoreVisibility();
		if (null != TM.Panels.IFrameMyBookmarks)
			TM.Panels.IFrameMyBookmarks.RestoreVisibility();
		if (null != TM.Panels.Filters)
			TM.Panels.Filters.RestoreVisibility();
		if (null != TM.Panels.ToolBarResultBack)
			TM.Panels.ToolBarResultBack.RestoreVisibility();
		if (null != TM.Panels.ContentMiddle)
			TM.Panels.ContentMiddle.RestoreVisibility();
		if (null != TM.Panels.ContentMiddleLarge)
			TM.Panels.ContentMiddleLarge.RestoreVisibility();
		if (null != TM.Panels.Footer)
			TM.Panels.Footer.RestoreVisibility();
		if (null != TM.Panels.TopNavMenu)
			TM.Panels.TopNavMenu.RestoreVisibility();
	}
};

/* MODE */
TM.Mode = {
	IsInitialize: false,
	LastMode: '',
	CurrentMode: '',
	OldBackroundFlashFullClass: '',
	Initialize: function(oid, flaghome) {
		if (!this.IsInitialize) {
			var oShow = $('lnkShowExperientiel');
			var oClose = $('lnkCloseExperientiel');
			oShow.clicked = false;
			oClose.clicked = true;
			oShow.Image = $('imgShowExperientiel');
			oClose.Image = $('imgCloseExperientiel');
			oShow.CloseLink = oClose;
			oClose.ShowLink = oShow;
			var languageCode = currentLanguageId == 1 ? 'Fr' : 'En';
			oShow.imageUrl = '/Images/' + languageCode + '/buttons/bt_tv_mode.gif';
			oShow.overImageUrl = '/Images/' + languageCode + '/buttons/bt_tv_mode_on.gif';
			oShow.clickImageUrl = '/Images/' + languageCode + '/buttons/bt_tv_mode_sel.gif';
			oClose.imageUrl = '/Images/' + languageCode + '/buttons/bt_portal_mode.gif';
			oClose.overImageUrl = '/Images/' + languageCode + '/buttons/bt_portal_mode_on.gif';
			oClose.clickImageUrl = '/Images/' + languageCode + '/buttons/bt_portal_mode_sel.gif';
			oShow.onmouseover = function() {
				if (!this.clicked) { this.Image.src = this.overImageUrl; }
			};
			oShow.onclick = function() {
				if (!this.clicked) {
					this.Image.src = this.clickImageUrl;
					this.clicked = true;
					this.CloseLink.unclick();
				}
				return false;
			};
			oShow.onclickExtern = function() {
				if (!this.clicked) {
					this.Image.src = this.clickImageUrl;
					this.clicked = true;
					this.CloseLink.unclick();
				}
				return false;
			};
			oShow.onmouseout = function() {
				if (!this.clicked) { this.Image.src = this.imageUrl; }
			};
			oShow.unclick = function() {
				this.clicked = false;
				this.Image.src = this.imageUrl;
			};

			oClose.onmouseover = function() {
				if (!this.clicked) { this.Image.src = this.overImageUrl; }
			};
			oClose.onclick = function() {
				if (!this.clicked) {
					this.Image.src = this.clickImageUrl;
					this.clicked = true;
					this.ShowLink.unclick();
				}
				return false;
			};
			oClose.onclickExtern = function() {
				if (!this.clicked) {
					this.Image.src = this.clickImageUrl;
					this.clicked = true;
					this.ShowLink.unclick();
				}
				return false;
			};
			oClose.onmouseout = function() {
				if (!this.clicked) { this.Image.src = this.imageUrl; }
			};
			oClose.unclick = function() {
				this.clicked = false;
				this.Image.src = this.imageUrl;
			};

			if (null != oid)
				$(oid).onmouseover();

		}
		this.IsInitialize = true;
	},
	ChangeMode: function(newMode) {
		if (newMode == this.CurrentMode) {
			return;
		}
		this.LastMode = this.CurrentMode;
		this.CurrentMode = newMode;
		if (this.LastMode == 'Experientiel') {
			$("backround_flashfull").className = this.OldBackroundFlashFullClass;
		}
	}
};

TM.MyBookmarks = {
	refreshIFrameLast: false,
	isLoaded: false,
	CurrentCount: 0,
	Display: function() {
		TM.MyMontreal.Close();
		TM.Panels.TopNavMenu.Show();
		TM.Panels.PnlMyBookmarks.className = 'tab roll';
		TM.Panels.PnlMyMontreal.className = 'tab';

		if (TM.Panels.TopPnlTrips)
			TM.Panels.TopPnlTrips.className = 'mytrips';

		if (!this.isLoaded) {
			TM.Panels.IFrameMyBookmarks.Show();
			$('IFrameMyBookmarks').src = '/Silos/Common/MyMontreal/MyBookmarks.aspx?langid=' + currentLanguageId + '&SiloID=' + currentSiloId;
			this.isLoaded = true;
		} else {
			if (TM.Panels.IFrameMyBookmarks.isVisible) {
				TM.Panels.HidePanels(TM.Panels.IFrameMyBookmarks, TM.Panels.TopNavMenu);
				top.TM.Footer.SetPosition();
				return;
			} else {
				TM.Panels.IFrameMyBookmarks.Show();
				try { $('IFrameMyBookmarks').contentWindow.RefreshMySelections(); }
				catch (e) { }
			}
		}
		if ($('ctl00_MainHeader1_TopNavBar1_lnkMySelections'))
			$('ctl00_MainHeader1_TopNavBar1_lnkMySelections').className = this.isVisible ? 'bookmarks roll' : 'bookmarks';
		if ($('ctl00_C1_VSM1_Bookmarks1_lnkMySelections'))
			$('ctl00_C1_VSM1_Bookmarks1_lnkMySelections').className = this.isVisible ? 'bookmarks roll' : 'bookmarks';

		if (TM.Panels.TopPnlTrips)
			TM.Panels.TopPnlTrips.className = 'mytrips mytrips-on';

		top.TM.Footer.SetPosition();
	},
	Close: function() {
		if (TM.Panels.IFrameMyBookmarks.isVisible)
			TM.Panels.HidePanels(TM.Panels.IFrameMyBookmarks, TM.Panels.TopNavMenu);
			
		if (TM.Panels.TopPnlTrips)
			TM.Panels.TopPnlTrips.className = 'mytrips';
		if (TM.Panels.PnlMyBookmarks)
			TM.Panels.PnlMyBookmarks.className = 'tab';

		top.TM.Footer.SetPosition();
	},
	UpdateUIBookmarks: function(count, refreshIFrame) {
		this.refreshIFrameLast = refreshIFrame;
		this.CurrentCount = count;
		var oTop = $('BOOKMARK_TOP');
		var oTopSlide = $('BOOKMARK_TOPSLIDE');
		var oTopSubNav = $('BOOKMARK_TOPSUBNAV');
		var oTopSubNavSlide = $('BOOKMARK_TOPSUBNAVSLIDE');
		var oRight = $('BOOKMARK_RIGHT');
		var oRightSlide = $('BOOKMARK_RIGHTSLIDE');

		if (null != oTop) {
			new Effect.SlideUp(oTopSlide, { duration: 0.4, queue: { scope: 'bookmark_top', position: 'front' }, afterFinishInternal: function() { $('BOOKMARK_TOP').innerHTML = '[' + TM.MyBookmarks.CurrentCount + ']'; } });
			new Effect.SlideDown(oTopSlide, { duration: 0.4, queue: { scope: 'bookmark_top', position: 'end'} });
		}
		if (null != oTopSubNav) {
			new Effect.SlideUp(oTopSubNavSlide, { duration: 0.4, queue: { scope: 'bookmark_topsubnav', position: 'front' }, afterFinishInternal: function() { $('BOOKMARK_TOPSUBNAV').innerHTML = '[' + TM.MyBookmarks.CurrentCount + ']'; } });
			new Effect.SlideDown(oTopSubNavSlide, { duration: 0.4, queue: { scope: 'bookmark_topsubnav', position: 'end'} });
		}
		if (null != oRight) {
			new Effect.SlideUp(oRightSlide, { duration: 0.4, queue: { scope: 'bookmark_right', position: 'front' }, afterFinishInternal: function() { $('BOOKMARK_RIGHT').innerHTML = '[' + TM.MyBookmarks.CurrentCount + ']'; } });
			new Effect.SlideDown(oRightSlide, { duration: 0.4, queue: { scope: 'bookmark_right', position: 'end' }, afterFinishInternal: function() { TM.MyBookmarks.RefreshIFrame(); } });
		}
	},
	RefreshIFrame: function() {
		if (this.refreshIFrameLast && null != TM.Panels.IFrameMyBookmarks) {
			if (TM.Panels.IFrameMyBookmarks.isVisible) {
				var iframe = $('IFrameMyBookmarks');
				if (null != iframe) {
					iframe.contentWindow.RefreshMySelections();
				}
			}
		}
	}
};

TM.MyMontreal = {
	lastAction: '',
	isLoaded: false,
	Display: function(action) {
		TM.MyBookmarks.Close();
		TM.Panels.TopNavMenu.Show();
		TM.Panels.PnlMyMontreal.className = 'tab roll';
		TM.Panels.PnlMyBookmarks.className = 'tab';
		
		if (TM.Panels.TopPnlRFP)
			TM.Panels.TopPnlRFP.className = 'sectionarrow';
		if (TM.Panels.TopPnlToolkit)
			TM.Panels.TopPnlToolkit.className = 'sectionarrow';
		if (TM.Panels.TopPnlTrips)
			TM.Panels.TopPnlTrips.className = 'mytrips';

		if (!action)
			action = 'Home';
		var actionChanged = action != this.lastAction;
		this.lastAction = action;
		if (!this.isLoaded || actionChanged) {
			TM.Panels.IFrameMyMontreal.Show();
			$('IFrameMyMontreal').src = '/Silos/Common/MyMontreal/MyMontreal.aspx?Action=' + this.lastAction + '&langid=' + currentLanguageId + '&SiloID=' + currentSiloId;
			this.isLoaded = true;
		}
		else {
			if (TM.Panels.IFrameMyMontreal.isVisible) {
				TM.Panels.HidePanels(TM.Panels.IFrameMyMontreal, TM.Panels.TopNavMenu);
				top.TM.Footer.SetPosition();
				return;
			}
			else {
				TM.Panels.IFrameMyMontreal.Show();
			}
		}

		switch (action) {
			case 'RFP':
				TM.Panels.TopPnlRFP.className = 'sectionarrow sectionarrow-on';
				TM.Panels.TopNavBar.Hide();
				break;
			case 'Toolkit':
				TM.Panels.TopPnlToolkit.className = 'sectionarrow sectionarrow-on';
				TM.Panels.TopNavBar.Hide();
				break;
			default:
				TM.Panels.TopPnlTrips.className = 'mytrips mytrips-on';
				break;
		}

		top.TM.Footer.SetPosition();
	},
	Close: function() {
		if (TM.Panels.IFrameMyMontreal.isVisible) {
			with (TM.Panels) {
				ShowPanels(MainMenu, SubMenu, Filters, ToolBarResultBack, ContentMiddle, ContentMiddleLarge, Footer);
				HidePanels(IFrameMyMontreal, TopNavMenu);

				if (TopPnlRFP)
					TopPnlRFP.className = 'sectionarrow';
				if (TopPnlToolkit)
					TopPnlToolkit.className = 'sectionarrow';
				if (TopPnlTrips)
					TopPnlTrips.className = 'mytrips';
				if (PnlMyMontreal)
					PnlMyMontreal.className = 'tab';
			}
		}

		top.TM.Footer.SetPosition();
	},
	ShowHideItineraryDay: function(divid, imgid) {
		JsLib.Utilities.ShowHide(divid);
		$(imgid).src = '/Images/Common/pictures/pi_brownheader_arrow_' + ($(divid).style.display == 'none' ? 'right' : 'bottom') + '.gif';
		top.TM.Footer.SetPosition();
	},
	RefreshOnLogin: function() {
		if (top.RefreshOnLogin) {
			top.RefreshOnLogin();
		}
	}
};

TM.GettingTo = {
	SwitchTab: function() {
		var args = arguments;
		for (var i = 0; i < args.length; i++) {
			$('tab' + args[i]).className = 'tab';
			$('div' + args[i]).style.display = 'none';
		}
		$('tab' + args[0]).className = 'tab roll';
		$('div' + args[0]).style.display = 'block';

		top.TM.Footer.SetPosition();
	}
};