/// <reference path="JsLib.js" />
var TM = {
	Print: function() {
		top.print();
		TM.GoogleAnalytics.trackEvent('print', TM.GoogleAnalytics.getDirectLinkValue());
		return false;
	}
};

TM.Browser = {
	Chrome: function() {
		if (Sys.Browser.agent === Sys.Browser.Safari) {
			if (typeof Sys._ScriptLoader.prototype._loadScriptsInternal_saved != "function") {
				Sys._ScriptLoader.prototype._loadScriptsInternal_saved = Sys._ScriptLoader.prototype._loadScriptsInternal;
				Sys._ScriptLoader.prototype._loadScriptsInternal = function() {
					var client = Sys.Browser.agent;
					Sys.Browser.agent = Sys.Browser.IE;
					this._loadScriptsInternal_saved();
					Sys.Browser.agent = client;
				}
			}
		}
	}
};

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.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);
		if (blank) window.open(url);
		else top.location = url;
	}
};

TM.GreyBox = {
    Opacity: 0.6,
    Duration: 0.4,
    Initialize: function (searchText) {
        if ($('greybox-overlay') == null) {
            $$('body')[0].appendChild(Builder.node('div', { id: 'greybox-overlay' }));
            var overlay = $('greybox-overlay');
            overlay.hide();
            this['overlay'] = overlay;

            $$('body')[0].appendChild(Builder.node('div', { id: 'loading-box' }));
            var loadingBox = $('loading-box');
            loadingBox.hide();
            this['loadingBox'] = loadingBox;
            loadingBox.innerHTML = "<div class='content'><div class='spinner'></div><p>" + searchText + "</p></div>";
        }
        else {
            this.Hide();
        }
    },
    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' });
        this.loadingBox.center();

        new Effect.Appear(this.overlay, { duration: this.Duration, from: 0.0, to: this.Opacity });
        new Effect.Appear(this.loadingBox, { duration: this.Duration });
    },
    Hide: function () {
        new Effect.Fade(this.overlay, { duration: this.Duration });
        new Effect.Fade(this.loadingBox, { 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.BookNow = {
	Display: function(obj) {		
		$$('.widget-position').each(function(elmt) {
			if (!elmt.visible()){
				var point = JsLib.Positioner.GetAbsolutePos(obj);
				elmt.style.top = point.y + $(obj).getHeight() + 'px';
				elmt.style.left = point.x + 'px';
				elmt.show();
			}else{
				elmt.hide();
			}
		});
	},
	Close: function(){
		$$('.widget-position').each(function(elmt) {
			elmt.hide();
		});
	}
};

TM.Pricing = {
	expandedCount:0,
	AdjustIframe:function(){
		JsLib.IFrame.AutoResize(document.getElementById('iframeContent'));
		top.TM.Footer.SetPosition();
	},
	Expand: function(){
		this.expandedCount++;
		JsLib.Utilities.Show('iframeBuffer');
		this.AdjustIframe();
	},
	Collapse:function(){
		this.expandedCount--;
		if (this.expandedCount == 0)
		{			
			JsLib.Utilities.Hide('iframeBuffer');
			this.AdjustIframe();
		}
	},
	Toggle: function(obj,panelid,text){
		var panel = $(panelid);
		var link = $(obj);
		
		panel.toggle();
		if (panel.visible()){
			link.originalHTML = link.innerHTML;
			link.innerHTML = text;
		}
		else{
			link.innerHTML = link.originalHTML;
			link.originalHTML = null;
		}
		
		this.AdjustIframe();
	}
}

TM.ShowNearBy = {
	isOpen: false,
	isLoaded: false,
	Init: function() {
		Sys.Application.add_navigate(TM.ShowNearBy.OnStateChanged);
	},
	Select: function(cddid, objid, text, value, control) {
		TM.GoogleAnalytics.trackEvent('map', 'nearby', text + ':' + TM.GoogleAnalytics.getDirectLinkValue(), '');
		Sys.Application.add_navigate(TM.ShowNearBy.OnStateChanged);
		Sys.Application.addHistoryPoint({ status: 'open', cddid: cddid, oid: objid, typeto: value, control: control, text: text }, document.title);
	},
	Close: function() {
		Sys.Application.addHistoryPoint({ status: 'close', cddid: null, oid: null, typeto: null, control: null, text: null }, document.title);
	},
	Opening: function(oid, typeto, control, text, cddid) {
		if ($(cddid) != null)
			$(cddid).innerHTML = (text == null) ? '' : text;

		var ddlist = $(cddid + '_list');
		if (ddlist != null)
			ddlist.style.display = 'none';

		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;
	},
	Closing: function() {
		if (this.isOpen){
			$('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();
	},
	OnStateChanged: function(sender, e) {
		var state = e.get_state();
		switch (state.status) {
			case 'open':
				TM.ShowNearBy.Opening(state.oid, state.typeto, state.control, state.text, state.cddid);
				break;
			default:
				TM.ShowNearBy.Closing();
				break;
		}
	}
};

TM.Bookmarking = {
	Name: '',
	Url: '',
	SupportBookmarking: function () {
		return !(window.chrome || window.opera) && (window.sidebar || window.external);
	},
	Display: function (obj, name, url) {
		this.Name = name;
		this.Url = url;

		switch (parent.$('hdnBookmarkStatus').value) {
			case '0':
				if (this.SupportBookmarking()) {
					var div = $('Bookmark');
					if (null == div) {
						div = document.createElement('div');
						div.id = 'Bookmark';
						div.className = 'PopUpWarning add-to-selections-popup';
						div.style.zIndex = 5000;
						div.innerHTML = JsLib.Ajax.LoadTEXT('/Tools/StaticContent.aspx?langid=' + currentLanguageId + '&c=Bookmark');
						document.body.appendChild(div);

						Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(TM.Bookmarking.Close);
					}

					div.style.display = 'block';

					var height = JsLib.Positioner.GetElementSize(div).y;
					var top = JsLib.Positioner.GetAbsolutePos(obj).y - height - 10;
					if (top > height)
						div.style.top = top + 'px';
					else
						div.style.top = (top + (height - top) + 10) + 'px';

					div.style.left = (JsLib.Positioner.GetAbsolutePos(obj).x + JsLib.Positioner.GetElementSize(obj).x - JsLib.Positioner.GetElementSize(div).x) + 'px';
				}
				break;
			case '1':
				if (this.SupportBookmarking()) {
					this.Bookmark();
				}
				break;
		}
	},
	Bookmark: function () {
		if (window.sidebar) {
			window.sidebar.addPanel(this.Name, this.Url, "");
		}
		else if (window.external) {
			window.external.AddFavorite(this.Url, this.Name);
		}

		var div = $('hdnBookmarkRemember');
		var hasValue = div != null && div.value != '';

		div = $('Bookmark');
		if (null != div)
			div.remove();

		if (hasValue) {
			parent.$('hdnBookmarkStatus').value = 1;
			BookmarkStatus('1');
		}
	},
	Close: function () {
		var div = $('hdnBookmarkRemember');
		var hasValue = div != null && div.value != '';

		div = $('Bookmark');
		if (null != div)
			div.remove();

		if (hasValue) {
			parent.$('hdnBookmarkStatus').value = 2;
			BookmarkStatus('2');
		}
	}
};

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 () {
		var url = currentLanguageId == 1 ? '/Aide' : '/Help';
		JsLib.POPUP.Window(url, 550, 400, 'Help');
	}
};

TM.LegalNotice = {
	visible: false,
	divId: 'div_legalnotice',
	legalNoticeO: -1,
	Open: function(o, legalnoticeid, width) {
		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.left = '12px';
			divLegalNotice.style.marginTop = '15px';
			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';
		this.visible = true;
		
		return $(this.divId).getHeight();
	},
	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++) {
			if( typeof(a[i])=='string'){
				$addHandler($(a[i]), 'click', function() {
						TM.Tabs.Activate(this,null); 
						return false;
					}
				);
			}else{
				$addHandler($(a[i].tabId), 'click', a[i].f);
				$addHandler($(a[i].tabId), 'click', function() {
						TM.Tabs.Activate(this);
						return false;
					}
				);
			}
			currentTab = a[0];
			($(a[0])).className = "tab roll";
		}
	},
	Activate: function(obj) {
		if (obj.id != currentTab) {
			TM.GoogleAnalytics.trackEvent('tab', 'open', obj.innerHTML);
			$("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();
		}
	},
	OpenPricing:function(url){
		var ifr = document.getElementById('ifrDetails');
		var ifrurl = ifr.src;
		if(!(-1!=ifrurl.indexOf(url) && ifrurl.indexOf(url)+url.length ==ifrurl.length)){
			ifr.src=url;
		}
	}
};

/* TOOLBAR */
TM.Toolbar = {
	LinkToThisPage: {
		Display: function(obj, oid, useState) {
			if (JsLib.Utilities.ShowHideR('linktothispage')) {
				if (useState) {
					var url = window.location.toString();
					var index = url.lastIndexOf('#&&');
					if (index > 0) {
						var txt = $(oid);
						if (txt.oldValue == undefined) {
							txt.oldValue = txt.value;
						}

						$(oid).value = txt.oldValue + url.substring(index);
					}
				}
				
				var div = $('linktothispage');
				$(oid).select();
				TM.Toolbar.LinkSendToFriend.Hide();
				TM.GoogleAnalytics.trackEvent('get direct link', 'invite', TM.GoogleAnalytics.getDirectLinkValue()); 
			}
		},
		Hide: function() {
			JsLib.Utilities.Hide('linktothispage');
		}
	},
	LinkSendToFriend: {
		Display: function(obj, txt, useState) {
			if (JsLib.Utilities.ShowHideR('sendtofriend')) {
				if (useState) {
					var url = window.location.toString();
					var index = url.lastIndexOf('#&&');
					if (index > 0) {
						$('hdnState').value = url.substring(index);
					}
				}

				var div = $('sendtofriend');
				($(txt)).focus();
				TM.Toolbar.LinkToThisPage.Hide();
				TM.GoogleAnalytics.trackEvent('send link', 'invite', 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, flSilo) {
		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', flSilo);
		so.addVariable('LangID', currentLanguageId);
		so.write('panel_flash');
	},
	InfoBox: {
		IsOpened: false,
		Open: function () {
			new Effect.Morph('dark-box-content', { style: 'open', duration: 0.2, afterFinish: function () { $('dark-box-content').removeClassName('closed'); } });
			TM.Flash.InfoBox.IsOpened = true;

			TM.Flash.Carousel.Stop();
		},
		Close: function () {
			$('dark-box-content').removeClassName('open');
			new Effect.Morph('dark-box-content', { style: 'closed', duration: 0.2 });
			TM.Flash.InfoBox.IsOpened = false;

			TM.Flash.Carousel.Start();
		}
	},
	Carousel: {
		IntervalID: null,
		Index: 0,
		Images: null,
		Initialize: function () {
			this.Images = $$('#selectors a');
			this.Start();
			Event.observe(window, 'load', this.Preload);
		},
		Preload: function () {
			var preload = [];
			for (var i = 0; i < TM.Flash.Carousel.Images.length; i++) {
				preload[i] = new Image();
				preload[i].src = TM.Flash.Carousel.Images[i].ImageUrl;
			}
		},
		Start: function () {
			if (this.IntervalID == null)
				this.IntervalID = window.setInterval(this.Interval, 6000);
		},
		Stop: function () {
			window.clearInterval(this.IntervalID);
			this.IntervalID = null;
		},
		Interval: function () {
			TM.Flash.Carousel.Index = (TM.Flash.Carousel.Index + 1) % TM.Flash.Carousel.Images.length;
			TM.Flash.Carousel.Change(TM.Flash.Carousel.Images[TM.Flash.Carousel.Index], false);
		},
		NextBox: function () {
			this.Index = (this.Index + 1) % this.Images.length;
			this.Change(this.Images[this.Index], true);
		},
		PreviousBox: function () {
			this.Index = this.Index == 0 ? this.Images.length - 1 : this.Index - 1;
			this.Change(this.Images[this.Index], true);
		},
		ChangeBox: function (obj) {
			this.Index = this.Images.indexOf(obj);
			this.Change(obj, true);
		},
		Change: function (obj, resetInterval) {
			$('box-title').update(obj.Title);
			$('box-subtitle').update(obj.SubTitle);
			$('box-description').update(obj.Description);
			$$('#img-bg img')[0].src = obj.ImageUrl;
			$('lnkLearnMore').href = obj.Url;

			if (TM.Flash.InfoBox.IsOpened) {
				TM.Flash.InfoBox.Close();
			}
			else if (resetInterval) {
				TM.Flash.Carousel.Stop();
				TM.Flash.Carousel.Start();
			}

			$$('.current')[0].removeClassName('current');
			obj.addClassName('current');
		}
	},
	FullScreen: {
		widthContenu: 975,
		widthImage: 1400,
		ratio: 3.66,
		imageID: null,
		buttonID: 'pnlMiddleButton',
		campaignButtonID: 'pnlCampaignButton',
		headerID: 'pnlHeader',
		logoID: 'pnlLogo',
		carouselID: 'pnlCarousel',
		infoBoxID: 'pnlInfoBox',
		Initialize: function (imageID) {
			this.imageID = imageID;

			Event.observe(window, 'load', this.SetPosition);
			Event.observe(window, 'resize', this.SetPosition);
		},
		SetPosition: function () {
			var clientWidth = document.documentElement.clientWidth;
			var widthBgImg = (clientWidth < TM.Flash.FullScreen.widthImage) ? TM.Flash.FullScreen.widthImage : clientWidth;
			var heightBgImage = widthBgImg / TM.Flash.FullScreen.ratio;
			var sizeBtn = $(TM.Flash.FullScreen.buttonID).getDimensions();
			var sizeMenu = $(TM.Flash.FullScreen.headerID).getDimensions();

			var width = clientWidth < TM.Flash.FullScreen.widthContenu ? TM.Flash.FullScreen.widthContenu : clientWidth;

			new Effect.Morph(TM.Flash.FullScreen.imageID, { style: { width: widthBgImg + 'px' }, duration: 0, afterFinish: function () { $(TM.Flash.FullScreen.imageID).style.visibility = 'visible'; TM.Footer.SetPosition(); } });
			new Effect.Morph(TM.Flash.FullScreen.buttonID, { style: { top: (heightBgImage / 2 - sizeBtn.height / 2) + 'px', left: (width / 2 - sizeBtn.width / 2) + 'px' }, duration: 0, afterFinish: 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, afterFinish: 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: ((width - TM.Flash.FullScreen.widthContenu) / 2) + TM.Flash.FullScreen.widthContenu - sizeLogo.width + 3 + 'px' }, duration: 0, afterFinish: function () { $(TM.Flash.FullScreen.logoID).style.visibility = 'visible'; } });
			}

			if ($(TM.Flash.FullScreen.carouselID) != null) {
				var sizeCarousel = $(TM.Flash.FullScreen.carouselID).getDimensions();
				new Effect.Morph(TM.Flash.FullScreen.carouselID, { style: { top: (heightBgImage - sizeCarousel.height - 6) + 'px', left: ((widthBgImg - TM.Flash.FullScreen.widthContenu) / 2) + TM.Flash.FullScreen.widthContenu - sizeCarousel.width + 3 + 'px' }, duration: 0, afterFinish: function () { $(TM.Flash.FullScreen.carouselID).style.visibility = 'visible'; } });
			}

			if ($(TM.Flash.FullScreen.infoBoxID) != null) {
				var sizeInfoBox = $(TM.Flash.FullScreen.infoBoxID).getDimensions();
				new Effect.Morph(TM.Flash.FullScreen.infoBoxID, { style: { top: (heightBgImage / 2 - sizeBtn.height / 2) + 'px', left: ((width - TM.Flash.FullScreen.widthContenu) / 2) + 'px' }, duration: 0, afterFinish: function () { $(TM.Flash.FullScreen.infoBoxID).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;
			TM.GoogleAnalytics.trackEvent('tab', 'open', 'mybookmarks', '');
		} else {
			if (TM.Panels.IFrameMyBookmarks.isVisible) {
				TM.Panels.HidePanels(TM.Panels.IFrameMyBookmarks, TM.Panels.TopNavMenu);
				top.TM.Footer.SetPosition();
				TM.GoogleAnalytics.trackEvent('tab', 'close', 'mybookmarks', '');
				return;
			} else {
				TM.Panels.IFrameMyBookmarks.Show();
				TM.GoogleAnalytics.trackEvent('tab', 'open', 'mybookmarks', '');
				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 && 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();

		if (TM.Panels.PnlMyMontreal)
			TM.Panels.PnlMyMontreal.className = 'tab roll';
		if (TM.Panels.PnlMyBookmarks)
			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();
			var pageName = currentSiloId == 1 ? "MyProfile" : "MyMontreal";
			$('IFrameMyMontreal').src = '/Silos/Common/MyMontreal/' + pageName + '.aspx?Action=' + this.lastAction + '&langid=' + currentLanguageId + '&SiloID=' + currentSiloId;
			this.isLoaded = true;
			TM.GoogleAnalytics.trackEvent('tab', 'open', action.toLowerCase(), '');
		}
		else {
			if (TM.Panels.IFrameMyMontreal.isVisible) {
				TM.Panels.HidePanels(TM.Panels.IFrameMyMontreal, TM.Panels.TopNavMenu);
				top.TM.Footer.SetPosition();
				TM.GoogleAnalytics.trackEvent('tab', 'close', action.toLowerCase(), '');
				return;
			} else {
				TM.GoogleAnalytics.trackEvent('tab', 'open', action.toLowerCase(), '');
				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';
		TM.GoogleAnalytics.trackEvent('tab', 'open', $('tab' + args[0]).innerHTML);
		top.TM.Footer.SetPosition();
	}
};

TM.Validation = {
	RoomSelection: function(source,args){
		var cddAdult = $(source.cddAdultClientId);
		var cddAgeChild1 = $(source.cddAgeChild1ClientId);
		var cddAgeChild2 = $(source.cddAgeChild2ClientId);
		var cddAgeChild3 = $(source.cddAgeChild3ClientId);
		var value =	parseInt(cddAdult.value) +
					(parseInt(cddAgeChild1.value) > 0 ? 1 : 0) +
					(parseInt(cddAgeChild2.value) > 0 ? 1 : 0) +
					(parseInt(cddAgeChild3.value) > 0 ? 1 : 0);
		args.IsValid = (value <= 5)
	},
	ReservationLength: function(source,args){
		var dateEnd = $(source.dateEndClientId);
		var dateStart = $(source.dateStartClientId);
		var dateEndHidden = $(source.dateEndHiddenFieldId);
		var dateStartHidden = $(source.dateStartHiddenFieldId);
		var end = new Date((parseInt(dateEndHidden.value) - dateEnd.defaultTicks)/dateEnd.ticksPerMillisecond);
		var start = new Date((parseInt(dateStartHidden.value) - dateStart.defaultTicks)/dateStart.ticksPerMillisecond);
		var one_day=1000*60*60*24
		args.IsValid = ((end.getTime()-start.getTime())/one_day <= 17);
	}
};

TM.Carousel = {
	Defaults: new Array(),
	Initialize: function (name, options) {
		var defaults = {
			ItemCount: 0,
			ItemIndex: 0,
			ItemSelector: '',
			DisplayedCount: 0,
			PrevButton: '',
			NextButton: '',
			IndexHiddenField: '',
			Container: '',
			ItemWidth: 0,
			Duration: 0.6,
			PrevCssClassOff: '',
			NextCssClassOff: '',
			Direction: 'left',
			MovedCount: 1,
			Infinite: false
		};
		this.Defaults[name] = Object.extend(defaults, options);

		$(this.Defaults[name].PrevButton).onclick = function () { TM.Carousel.MovePrev(name); return false; };
		$(this.Defaults[name].NextButton).onclick = function () { TM.Carousel.MoveNext(name); return false; };

		if (this.Defaults[name].IndexHiddenField != '') {
			var index = $(this.Defaults[name].IndexHiddenField).value;
			if (index != '') {
				var offset = (this.GetPosition(name) + (-this.Defaults[name].ItemWidth * parseInt(index))) + 'px';

				if (this.Defaults[name].Direction == 'right')
					$(this.Defaults[name].Container).style.right = offset;
				else
					$(this.Defaults[name].Container).style.left = offset;

				this.Defaults[name].ItemIndex = parseInt(index);
			}
		}

		if (this.Defaults[name].Infinite)
			this.InitializeInfinite(name);
		else
			this.SetNavigation(name);

		var items = $$(this.Defaults[name].ItemSelector);
		$(this.Defaults[name].Container).style.width = (items.length * this.Defaults[name].ItemWidth) + 'px';
	},
	GetPosition: function (name) {
		var container = $(this.Defaults[name].Container);
		var offset = parseInt((this.Defaults[name].Direction == 'left') ? container.style.left : container.style.right);
		return isNaN(offset) ? 0 : offset;
	},
	InitializeInfinite: function (name) {
		var items = $$(this.Defaults[name].ItemSelector);
		if (items.length > this.Defaults[name].DisplayedCount) {
			var index = this.Defaults[name].DisplayedCount + this.Defaults[name].MovedCount - 1;
			var item;

			for (var i = 0; i < index; i++) {
				if (i < items.length) {
					item = items[i].cloneNode(true);
				}
				else {
					item = item.cloneNode(true);
				}
				$(this.Defaults[name].Container).insert(item);
			}
		}
		else {
			var prevButton = $(this.Defaults[name].PrevButton);
			var nextButton = $(this.Defaults[name].NextButton);

			prevButton.addClassName(this.Defaults[name].PrevCssClassOff);
			prevButton.onclick = function () { return false; };

			nextButton.addClassName(this.Defaults[name].NextCssClassOff);
			nextButton.onclick = function () { return false; };
		}
	},
	SetInfinitePrev: function (name) {
		if (this.Defaults[name].ItemIndex < this.Defaults[name].MovedCount) {
			var index = this.Defaults[name].ItemIndex;
			index += (this.Defaults[name].ItemCount < this.Defaults[name].MovedCount) ? this.Defaults[name].MovedCount : this.Defaults[name].ItemCount;
			this.SetIndex(name, index, true);

			var offset = -(this.Defaults[name].ItemWidth * this.Defaults[name].ItemIndex) + 'px';

			if (this.Defaults[name].Direction == 'right')
				$(this.Defaults[name].Container).style.right = offset;
			else
				$(this.Defaults[name].Container).style.left = offset;
		}
	},
	SetInfiniteNext: function (name) {
		if (this.Defaults[name].ItemIndex > this.Defaults[name].ItemCount) {
			var index = this.Defaults[name].ItemIndex;
			index -= (this.Defaults[name].ItemCount < this.Defaults[name].MovedCount) ? this.Defaults[name].MovedCount : this.Defaults[name].ItemCount;
			this.SetIndex(name, index, true);

			var offset = -(this.Defaults[name].ItemWidth * this.Defaults[name].ItemIndex) + 'px';

			if (this.Defaults[name].Direction == 'right')
				$(this.Defaults[name].Container).style.right = offset;
			else
				$(this.Defaults[name].Container).style.left = offset;
		}
	},
	SetNavigation: function (name) {
		var prevButton = $(this.Defaults[name].PrevButton);
		var nextButton = $(this.Defaults[name].NextButton);
		var prevCssClassOff = this.Defaults[name].PrevCssClassOff;
		var nextCssClassOff = this.Defaults[name].NextCssClassOff;

		if (this.Defaults[name].ItemIndex <= 0) {
			prevButton.addClassName(prevCssClassOff);
			prevButton.oldclick = prevButton.onclick;
			prevButton.onclick = function () { return false; };
		}
		else {
			prevButton.removeClassName(prevCssClassOff);
			if (prevButton.oldclick) {
				prevButton.onclick = prevButton.oldclick;
				prevButton.oldclick = null;
			}
		}

		if (this.Defaults[name].ItemIndex + this.Defaults[name].DisplayedCount >= this.Defaults[name].ItemCount) {
			nextButton.addClassName(nextCssClassOff);
			nextButton.oldclick = nextButton.onclick;
			nextButton.onclick = function () { return false; };
		}
		else {
			nextButton.removeClassName(nextCssClassOff);
			if (nextButton.oldclick) {
				nextButton.onclick = nextButton.oldclick;
				nextButton.oldclick = null;
			}
		}
	},
	SetIndex: function (name, index, reset) {
		if (reset)
			this.Defaults[name].ItemIndex = index;
		else
			this.Defaults[name].ItemIndex += index;

		if (this.Defaults[name].IndexHiddenField != '')
			$(this.Defaults[name].IndexHiddenField).value = this.Defaults[name].ItemIndex;
	},
	MovePrev: function (name) {
		if (Effect.Queues.get(name).size() == 0 && TM.Carousel.Defaults[name].Infinite)
			TM.Carousel.SetInfinitePrev(name);

		new Effect.Morph(this.Defaults[name].Container, {
			style: this.Defaults[name].Direction + ':' + (this.GetPosition(name) + (this.Defaults[name].ItemWidth * this.Defaults[name].MovedCount)) + 'px',
			duration: this.Defaults[name].Duration,
			queue: { position: 'end', scope: name, limit: 1 },
			beforeSetup: function () { TM.Carousel.SetIndex(name, TM.Carousel.Defaults[name].MovedCount * -1); if (!TM.Carousel.Defaults[name].Infinite) TM.Carousel.SetNavigation(name); }
		});
	},
	MoveNext: function (name) {
		new Effect.Morph(this.Defaults[name].Container, {
			style: this.Defaults[name].Direction + ':' + (this.GetPosition(name) - (this.Defaults[name].ItemWidth * this.Defaults[name].MovedCount)) + 'px',
			duration: this.Defaults[name].Duration,
			queue: { position: 'end', scope: name, limit: 1 },
			beforeSetup: function () { TM.Carousel.SetIndex(name, TM.Carousel.Defaults[name].MovedCount); if (!TM.Carousel.Defaults[name].Infinite) TM.Carousel.SetNavigation(name); },
			afterFinish: function () { if (TM.Carousel.Defaults[name].Infinite) TM.Carousel.SetInfiniteNext(name); }
		});
	}
};

TM.Theme = {
	GayThemeID: -1,
	CurrentThemeID: -1,
	GayThemeChange: function (themeID) {
		if (TM.Theme.CurrentThemeID == -1) {
			TM.Theme.CurrentThemeID = currentThemeId;
		}

		var gayThemeID = 'theme_' + TM.Theme.GayThemeID;
		var oldThemeID = 'theme_' + TM.Theme.CurrentThemeID;
		var newThemeID = 'theme_' + themeID;

		TM.Theme.CurrentThemeID = themeID;

		var objOld = null;
		var objNew = null;
		var lnkOld = null;
		var lnkNew = null;

		if (TM.Theme.CurrentThemeID == TM.Theme.GayThemeID) {
			objOld = $(oldThemeID);
			objNew = $(gayThemeID);
			lnkOld = $$('.' + oldThemeID)[0];
			lnkNew = $$('.' + gayThemeID)[0];
		}
		else {
			objOld = $(gayThemeID);
			objNew = $(newThemeID);
			lnkOld = $$('.' + gayThemeID)[0];
			lnkNew = $$('.' + newThemeID)[0];
		}

		lnkOld.href = objOld.Url;
		lnkOld.onclick = function () { };
		lnkOld.removeClassName('selected');

		lnkNew.href = '#';
		lnkNew.onclick = function () { return false; };
		lnkNew.addClassName('selected');

		$('ctl00_MainHeader1_lnkChangeBusiness').innerHTML = '<span>' + objNew.Name + '</span>';
	}
};

function pageLoad() {
	TM.Browser.Chrome();
}

