{
	function MainPage()
	{
		/// <summary>Page object for the application main HTML page</summary>
	}


	function MainPage_onExtSearch()
	{	
		var action='http://www.tucantravel.com/index.php';
		var qparams='?topic_id=1233&wl=&findbytourcode=submit';
		var tourcode='';

		var oTourCodeField=document.getElementById(MainPage.ElementIDs.TourCodeFieldID);
		if(oTourCodeField)
		{
			tourcode=oTourCodeField.value;
			if(tourcode=='') {
				alert('Please enter a tour code');
			} else {
				window.open(action + qparams +'&tour_code='+tourcode);
			}
		}
		return false;
	}

	MainPage.ElementIDs = 
	{		
		ContentDiv                      : "contentdiv",		
		IEScriptWarningFrameID	        : "IEScriptWarningFrame",
		MainTabStripID                  : "mainTabStrip",
		IssueDateID                     : "issueDate",
		PaneToolbarID                   : "paneToolbar",
		PaneMaximizeCommandID           : "paneMaximizeCommand",
		DocumentToolbarID	            : "ctrlDocViewerBar",
		PageItemCoverID                 : "pageItemCover",
		PageItemHelpID                  : "pageItemHelp",
		PageItemSearchID                : "pageItemSearch",
		PageItemmyClippingsID           : "myClippings",
		//SearchFormTextFieldID		: "searchformtextfield",
		TourCodeFieldID			: "tourcodetextfield",
		Popup_OkToChangeIssueID         : "popup_OkToChangeIssue",
		Popup_BookmarkInFirefoxNoteID   : "popup_BookmarkInFirefoxNote",
		Popup_moreIssuesID              : "popup_moreIssues",
		// From Navigation.htm.js
		MainPageSwitcherID              : "mainPageSwitcher",
		ContentsTitleID                 : "contentsTitle",		
		ContentsMainTabStripID          : "contentsMainTabStrip",
		ContentsMainPageSwitcherID      : "contentsMainPageSwitcher",
		ContentsFrameID                 : "contentsFrame",
		SearchFrameID                   : "searchFrame",
		CtrlAllContentsID               : "ctrlAllContents",
		PageItemContentsID              : "pageItemContents",
		PaneListContentsID              : "paneNavigate",		
		ContentsPublicationNameID       : "contentsPublicationName",
		CtrlContentsPaneID              : "ctrlContentsPane",
		splashscreenID              : "splashscreen"
	};
	
	MainPage.Commands = 
	{
		OK_ChangeIssue   : "OK_ChangeIssue",
		Cancel_ChangeIssue : "Cancel_ChangeIssue",
		OK_BookmarkInFirefoxNote : "OK_BookmarkInFirefoxNote",
		// from Viewer.htm.js
		PrintDocument   : "PrintDocument",
		ExtSearch   : "ExtSearch",
		CopyLink        : "CopyLink",
		AddToFavorites  : "AddToFavorites",
		SendMail        : "SendMail",
		MoreIssues      : "MoreIssues",
		ShowICViewer    : "ShowICViewer",
		PDFDocDownload  : "PDFDocDownload",
		PDFPageDownload : "PDFPageDownload",
		SaveForOffline  : "SaveForOfflinePage",
		DoBookmark      : "DoBookmark",
		HideContentPane : "HideContentPane",
		OpenOliveSoftwareWebsite : "OpenOliveSoftwareWebsite"
	};
	
	MainPage.ResourceStrings = 
	{
	    PopupInfo_Firefox_Bookmarks_Title                    :  "PopupInfo_Firefox_Bookmarks_Title",
	    PopupInfo_Firefox_Bookmarks_Introduction             :  "PopupInfo_Firefox_Bookmarks_Introduction", 
	    PopupInfo_Firefox_Bookmarks_Info                     :  "PopupInfo_Firefox_Bookmarks_Info",
	    PopupInfo_Firefox_Bookmarks_HowTo1                   :  "PopupInfo_Firefox_Bookmarks_HowTo1",
	    PopupInfo_Firefox_Bookmarks_HowTo1_WORD_Bookmarks    : "PopupInfo_Firefox_Bookmarks_HowTo1_WORD_Bookmarks",
	    PopupInfo_Firefox_Bookmarks_HowTo1_WORD_menu         : "PopupInfo_Firefox_Bookmarks_HowTo1_WORD_menu",
	    PopupInfo_Firefox_Bookmarks_HowTo1_WORD_right_click  : "PopupInfo_Firefox_Bookmarks_HowTo1_WORD_right_click",
	    PopupInfo_Firefox_Bookmarks_HowTo1_WORDS             :  "PopupInfo_Firefox_Bookmarks_HowTo1_WORDS",
	    PopupInfo_Firefox_Bookmarks_HowTo1_WORD_Properties   : "PopupInfo_Firefox_Bookmarks_HowTo1_WORD_Properties",
	    PopupInfo_Firefox_Bookmarks_HowTo2                   :  "PopupInfo_Firefox_Bookmarks_HowTo2",
	    PopupInfo_Firefox_Bookmarks_HowTo2_WORDS             :  "PopupInfo_Firefox_Bookmarks_HowTo2_WORDS",
	    PopupInfo_Firefox_Bookmarks_HowTo3                   :  "PopupInfo_Firefox_Bookmarks_HowTo3",
	    PopupInfo_Firefox_Bookmarks_WORD_OK                  :  "PopupInfo_Firefox_Bookmarks_WORD_OK",
	    PopupInfo_Firefox_Bookmarks_Checkbox                 :  "PopupInfo_Firefox_Bookmarks_Checkbox",
	    SearchPane_Empty    : "SearchPane_Empty",  
		// from Viewer.htm.js
		TabItem_Contents    : "TabItem_Contents",
		TabItem_Search      : "TabItem_Search",
		TabItem_Clippings    : "TabItem_Clippings",
		Command_MoreIssue   : "Command_MoreIssue",
		MenuItem_GoToPreviousPage : "MenuItem_GoToPreviousPage",
		MenuItem_GoToPage   : "MenuItem_GoToPage",
		MenuItem_GoToNextPage : "MenuItem_GoToNextPage",
		MenuItem_ZoomOut    : "MenuItem_ZoomOut",
		MenuItem_ZoomIn     : "MenuItem_ZoomIn",
		MenuItem_EMailImage : "MenuItem_EMailImage",
		MenuItem_EMail      : "MenuItem_EMail",
		MenuItem_PrintImage : "MenuItem_PrintImage",
		MenuItem_Print      : "MenuItem_Print",
		MenuItem_ExtSearchImage : "MenuItem_ExtSearchImage",
		MenuItem_ExtSearch  : "MenuItem_ExtSearch",
		MenuItem_SaveImage  : "MenuItem_SaveImage",
		MenuItem_Save       : "MenuItem_Save",
		MenuItem_DownloadPDF: "MenuItem_DownloadPDF",
		MenuItem_DownloadPagePDF : "MenuItem_DownloadPagePDF",
		MenuItem_Offline    : "MenuItem_Offline",
		MenuItem_Bookmark   : "MenuItem_Bookmark",
		MenuItem_ShareImage : "MenuItem_ShareImage",
		MenuItem_Share      : "MenuItem_Share",
		MenuItem_Digg       : "MenuItem_Digg",
		MenuItem_PostToDel  : "MenuItem_PostToDel",
		MenuItem_CopyToClipBoard : "MenuItem_CopyToClipBoard",
		MenuItem_MinimizeToolbar : "MenuItem_MinimizeToolbar",
		MenuItem_MinimizeToolbarParent : "MenuItem_MinimizeToolbarParent",
		MenuItem_OliveSoftwareWebsite : "MenuItem_OliveSoftwareWebsite",	
		Command_MaximizeToolbar  : "Command_MaximizeToolbar",
		Command_MaximizeToolbarParent  : "Command_MaximizeToolbarParent",
		FlashPane_NoDocument	: "FlashPane_NoDocument",
		// From Navigation.htm.js
		TabItem_Cover       : "TabItem_Cover",		
		TabItem_TableOfContents : "TabItem_TableOfContents",
		TabItem_Help        : "TabItem_Help",
		Button_Close        : "Button_Close"
	};
	
	MainPage.ErrorCodes = 
	{
		DocViewerAggAbsence : 12001,
		FlashViewerAbsence  : 12002
	};
	
	MainPage.IFrames = 
	{
		ContentsPane    : "ContentsPane.htm",
		SearchPane      : "SearchPane.htm",
		IEScriptWarning : "IEScriptWarning.htm",
		HelpIFrame      : "Help/Help.htm"		
	};
	
	MainPage.TabTitles = 
	{
		cover   : "cover",		
		toc     : "toc",
		help    : "help"
	};
	
	MainPage.TabIndexes = 
	{
		cover   : 0,
		toc     : 1,
		help    : 2
	};
		
	MainPage.DeclareType = function MainPage_DeclareType()
	{
		/// <summary>
		///		Declares methods and properties of MainPage Web page class
		/// </summary>
		this.DeclareField("m_oPopupWindow_ChangeIssue", null);
		this.DeclareField("m_sCookieName_ChangeIssue", "olv_activemag_open_new_issue"); //TODO get from config file
		this.DeclareField("m_oContentItem_ChangeIssue", null);
		this.DeclareField("m_controlDoNotAskAgain_ChangeIssue", null);
		this.DeclareField("m_oPopupWindow_BookmarkInFirefoxNote", null);
		this.DeclareField("m_sCookieName_BookmarkInFirefoxNote", "olv_activemag_save_bookmark_page_in_firefox_browser"); //TODO get from config file
		this.DeclareField("m_controlDoNotAskAgain_BookmarkInFirefoxNote", null);		
		this.DeclareField("m_oPopupWindow_MoreIssues", null);
		this.DeclareField("m_oArchiveThumbList", null);
		this.DeclareField("m_oMainPageSwitcher", null);
		this.DeclareField("m_oMainTabStrip", null);
		this.DeclareField("m_oContentsMainTabs", null);
		this.DeclareField("m_oPageItemCover", null);
		this.DeclareField("m_oPageItemHelp", null);
		this.DeclareField("m_oPageItemSearch", null);

		// Nested HTML pages
        this.DeclareField("m_oSearchPage", null);
        this.DeclareField("m_oContentPage", null);

		// From Viewer.htm.js
		this.DeclareField("m_docViewerAgg", null);
		this.DeclareField("m_flashViewer", null);
		this.DeclareField("m_docViewerBar", null);
		this.DeclareField("m_oContentsTitle", null);
		this.DeclareField("m_oIssueDate", null);
        this.DeclareField("m_oPaneListContents", null);
        this.DeclareField("m_oContentsPublicationName", null);

		this.OverrideMethod("postInitialize", MainPage_postInitialize);
		this.DeclareMethod("OpenDocument", MainPage_OpenDocument);
		this.DeclareMethod("OpenComponent", MainPage_OpenComponent);
		this.DeclareMethod("SendMail", MainPage_SendMail);	
		
		this.DeclareMethod("OpenOkToChangeIssueDialog", MainPage_OpenOkToChangeIssueDialog);				
		this.DeclareMethod("changeIssue_Cancel", MainPage_changeIssue_Cancel);
		this.DeclareMethod("changeIssue_OK", MainPage_changeIssue_OK);
		
		this.DeclareMethod("OpenBookmarkInFirefoxDialog", MainPage_OpenBookmarkInFirefoxDialog);
		this.DeclareMethod("bookmarkInFirefoxNote_OK", MainPage_bookmarkInFirefoxNote_OK);
		
		this.DeclareMethod("openAccessNotificationDialog", MainPage_openAccessNotificationDialog);
		this.DeclareMethod("_loadIEScriptWarning", MainPage_LoadIEScriptWarning);

		this.DeclareMethod("_closeAndSetCookie", MainPage_closeAndSetCookie);

		// Event handlers		
		this.DeclareMethod("bindContentPage", MainPage_bindContentPage);
		this.DeclareMethod("bindSearchPage", MainPage_bindSearchPage);
		this.DeclareMethod("onEntityDoubleClicked", MainPage_onEntityDoubleClicked);
		this.DeclareMethod("onDocumentLoaded", MainPage_onDocumentLoaded);
        this.DeclareMethod("onStateChanged", MainPage_onPageItemActivated);

		// Command handlers
		this.DeclareMethod("_onPrintDocument", MainPage_onPrintDocument);
		this.DeclareMethod("_onExtSearch", MainPage_onExtSearch);
		this.DeclareMethod("_PrintDocumentPages", MainPage_PrintDocumentPages);
		this.DeclareMethod("_onSendMail", MainPage_onSendMail);
		this.DeclareMethod("_onCopyLink", MainPage_onCopyLink);
		this.DeclareMethod("_onAddToFavorites", MainPage_onAddToFavorites);
		this.DeclareMethod("_onDoBookmark", MainPage_onDoBookmark);
		this.DeclareMethod("_onMoreIssues", MainPage_onMoreIssues);
		this.DeclareMethod("_onThumbListSelectionChanged", MainPage_onThumbListSelectionChanged);
		this.DeclareMethod("_onPDFDocDownload", MainPage_onPDFDocDownload);
		this.DeclareMethod("_onPDFPageDownload", MainPage_onPDFPageDownload);
		this.DeclareMethod("_onSaveForOffline", MainPage_onSaveForOffline);		
		this.DeclareMethod("_onNavigationPaneVisibilityChanged", MainPage_onNavigationPaneVisibilityChanged);
		this.DeclareMethod("_updatePDFPageState", MainPage_updatePDFPageState);
		this.DeclareMethod("_updatePDFDocumentState", MainPage_updatePDFDocumentState);
		this.DeclareMethod("_updateSaveForOfflineState", MainPage__updateSaveForOfflineState);
		this.DeclareMethod("_onContentsPaneResized", MainPage_onContentsPaneResized);
		this.DeclareMethod("_HideContentPane", MainPage_HideContentPane);		
		this.DeclareMethod("_OpenOliveSoftwareWebsite", MainPage_OpenOliveSoftwareWebsite);
						
		// Helper functions		
		this.OverrideMethod("_getContentItem", MainPage_getContentItem);
		this.DeclareMethod("_findControls", MainPage_findControls);
		this.DeclareMethod("_followPageLink", MainPage_followPageLink);
		this.DeclareMethod("_updateIFrame", MainPage_updateIFrame);		
		this.DeclareMethod("_importScripts", MainPage_importScripts);
		this.DeclareMethod("_clearThumbnails", MainPage_clearThumbnails);		
		this.DeclareMethod("_bindTabs", MainPage_bindTabs);	

		this.DeclareMethod("get_SearchPage", MainPage_get_SearchPage);
		this.DeclareMethod("get_ContentPage", MainPage_get_ContentPage);
	}
	
	MainPage.ApplyPrototype = function MainPage_ApplyPrototype(classProto)
	{
		/// <summary>
		///		Declares events and commands of MainPage Web page class
		/// </summary>
		/// <param name="classProto" type="object">
		///		Reference to the prototype of <see cref="MainPage" /> class.
		///		You may use it to declare commands and events for the class.
		/// </param>
		// Commands
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.OK_ChangeIssue, "changeIssue_OK");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.Cancel_ChangeIssue, "changeIssue_Cancel");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.OK_BookmarkInFirefoxNote, "bookmarkInFirefoxNote_OK");
		// From Viewer.htm.js
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.PrintDocument, "_onPrintDocument");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.ExtSearch, "_onExtSearch");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.SendMail, "_onSendMail");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.CopyLink, "_onCopyLink");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.AddToFavorites, "_onAddToFavorites");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.DoBookmark, "_onDoBookmark");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.MoreIssues, "_onMoreIssues");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.PDFDocDownload, "_onPDFDocDownload", "_updatePDFDocumentState");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.PDFPageDownload, "_onPDFPageDownload", "_updatePDFPageState");
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.SaveForOffline, "_onSaveForOffline", "_updateSaveForOfflineState");	
		Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.HideContentPane, "_HideContentPane");
	    Olive.CmdTarget.RegisterCommand(classProto, MainPage.Commands.OpenOliveSoftwareWebsite, "_OpenOliveSoftwareWebsite");	    
	};

	function MainPage_postInitialize(popupArguments)
	{
		/// <summary>
		///		Initializes HTML pages after all controls are created.
		/// </summary>
		/// <param name="popupArguments" type="object">
		///		Reference to the arguments passed to this page by opener.
		///		If this page is not loaded in a popup window or opener did not
		///		pass any arguments to this page, <paramref name="popupArguments" />
		///		will be <c>null</c>
		/// </param>
		/// <remarks>
		///		This initialization routine is called after all Web controls on 
		///		this page are created.  This is a good place to binds controls 
		///		to each other, attaches event handlers and perform other 
		///		initialization tasks.
		/// </remarks>
		var oSplashScreen = document.getElementById( MainPage.ElementIDs.splashscreenID );
		if( oSplashScreen )
		{
			var oSplashParent = oSplashScreen.parentNode;
			if( oSplashParent )
			{
				oSplashParent.removeChild( oSplashScreen );
			}
		}

		if (isVersionOf_IE_Script_LessThan(5, 7))
		{
			this._loadIEScriptWarning();
			return;
		}
		
		// get controls
		this._findControls();
		
        // Register for panes resized event.
        this.m_oPaneListContents.attachOwcEventHandler("panesResized", this._onContentsPaneResized, this);
        
        // set src for help and search pane iframes only by demand
        this.m_oPageItemHelp.attachOwcEventHandler("stateChanged", this._updateIFrame, this);
        this.m_oPageItemSearch.attachOwcEventHandler("stateChanged", this._updateIFrame, this);
        
        
		
		// bind tab strips and page switchers
		this._bindTabs();

		// attach event handler for "navigationPaneVisibilityChanged" event
		this.m_docViewerAgg.attachOwcEventHandler("navigationPaneVisibilityChanged", this._onNavigationPaneVisibilityChanged, this);
			
		// set resources strings
		for (var res_str in MainPage.ResourceStrings)
		    this.WebApplication.setResString(window.document, res_str);

		this.bindContentPage();
		this.bindSearchPage();

		this.m_bInitialized = true;
		this.WebApplication.onMainPageLoaded();
		
		// catch event close search pane
		Olive.EventSource.RegisterEventHandler("", "closeSearchPane", false, this._HideContentPane, this);
    }
    
    function MainPage_OpenDocument(contentItem, bCreateCopy, bUpdateThumbnails, bCheckIfActive, bClearSearchRes)
	{
		var oContentItem = contentItem;
		if (!oContentItem)
			return;
		
		if (bCreateCopy || oContentItem.m_sContentSrc == OwcContentSrc_Link)
		{
		    var oDocumentViewSource = Olive.ContentItem.CreateByType(OwcContentItem_Document);
		    oDocumentViewSource.copyDocRefFrom(oContentItem);
		    if (oContentItem.m_nPageNo)
		        oDocumentViewSource.m_nPageNo = oContentItem.m_nPageNo;
		    oContentItem = oDocumentViewSource;
		}		

		this.WebApplication.m_documentViewSource = oContentItem;	
		this.m_docViewerAgg.contentLoadItem(oContentItem);

		// Load TOC, load thmbnails etc. TODO: add methods into DocViewerAgg
		this.m_docViewerAgg.m_oTOCCtrl.setLoadingDataMessage();

		if (bClearSearchRes && this.m_docViewerAgg.m_oSearchResCtrl)
		    this.m_docViewerAgg.m_oSearchResCtrl.clearContent();
		
		if (bUpdateThumbnails)
		    this._clearThumbnails(oContentItem, bCheckIfActive);		    

		// Update other frames
	    this.WebApplication.m_sDocHRef = oContentItem.getDocHRef();
		var searchPage = this.get_SearchPage()
		if (searchPage)
           searchPage._updateSearchIn();
	}
	
	function MainPage_clearThumbnails(oContentItem, bCheckIfActive)
	{
		var contentPage = this.get_ContentPage();
        if (this.m_docViewerAgg.m_oPageThumbnailsCtrl)
        {
            if (bCheckIfActive && contentPage && contentPage.m_thumbnailsPage.isStateSet(Olive.IState.State.Active))
            {
                this.m_docViewerAgg.m_oPageThumbnailsCtrl.contentLoadItem(oContentItem);
            }
            else
            {
                this.m_docViewerAgg.m_oPageThumbnailsCtrl.clearContent();
                this.m_docViewerAgg.m_oPageThumbnailsCtrl.m_oContentItem = null;
            }		            
        }
        
        if (this.m_docViewerAgg.m_oFeaturedPagesCtrl)
        {
            if (bCheckIfActive && contentPage && contentPage.m_featuredPagesPage.isStateSet(Olive.IState.State.Active))
            {
                this.m_docViewerAgg.m_oFeaturedPagesCtrl.contentLoadItem(oContentItem);
            }
            else
            {
                this.m_docViewerAgg.m_oFeaturedPagesCtrl.clearContent();
                this.m_docViewerAgg.m_oFeaturedPagesCtrl.m_oContentItem = null;
            }
        }
	}
	
	function MainPage_bindContentPage()
	{
		var contentPage = this.get_ContentPage();
		if (!contentPage || !contentPage.m_bInitialized)
			return;

		contentPage.BindDocViewerParts(this.m_docViewerAgg, [this.m_oContentsPageItem, this.m_oAllContentsPageItem]);
	}

	function MainPage_bindSearchPage()
	{
		var searchPage = this.get_SearchPage()
		if (!searchPage || !searchPage.m_bInitialized)
			return;

		searchPage.BindDocViewerParts(this.m_docViewerAgg);

	    // clear initial message "Downloading data. Please, wait..."
	    var oEmptySearchPane = getObj(MainPage.ResourceStrings.SearchPane_Empty);
	    if (oEmptySearchPane)
	        oEmptySearchPane.innerHTML = ""; 
	}

	function MainPage_OpenComponent(contentItem)
	{
		/// <summary>
		///		Opens component identified by the passed content item
		///		in popup window.
		///	</summary>
		/// <param name="contentItem" type="Olive.Data.ContentItem">
		///		Content item that defines which component should be opened
		/// </param>
		
        var oWindowOptions = new Olive.Data.PopupWindowOptions(); 
        var nICPopupWindowMaxTitleLength = this.WebApplication.m_nICPopupWindowMaxTitleLength;   //Maximum character to display in PopUpWindow title 
        if (oWindowOptions)
        {
            // Temporary set the popup window title to "Loading...". It will be updated after the IC popup window is loaded
            oWindowOptions.setTitle( this.getResString("Popup_ICViewer_InitialTitle") );
            oWindowOptions.target = "popup_componentViewer";
            oWindowOptions.setIsResizable(true);
            oWindowOptions.setMinimalWidth(265);
		    oWindowOptions.setMinimalHeight(150);        
            this.openPopup("ComponentViewerForm.htm", oWindowOptions, contentItem, null, true);
        }
	}
	
	function MainPage_onThumbListSelectionChanged(eventArgs)
	{
	    var oSelectedContentItem = this.m_oArchiveThumbList.getSelectedContentItem();

		if (this.WebApplication.isDocHRefDifferent(oSelectedContentItem))
		{
			//this.WebApplication.ClosePopups(true);// onDocumentLoaded closes popups
		    
		    //update the this.WebApplication.m_sDocHRef
		    var sDocHRef = oSelectedContentItem.getDocHRef();
		    this.WebApplication.m_sDocHRef = sDocHRef;
		    
		    this.m_oMainTabStrip.setActiveItem(0);
		    this.m_oContentsMainTabs.setActiveItem(MainPage.TabIndexes.toc);
		    
		    this.OpenDocument(oSelectedContentItem, true, true, true, true);		    
		} 
	    
	    if (this.m_oPopupWindow_MoreIssues)
		    this.m_oPopupWindow_MoreIssues.close();
	}

	function MainPage_SendMail(mailParams, bIsEntity, oOpenerPage)
	{  
		/// <summary>
		///		Opens component identified by the passed content item
		///		in popup window.
		///	</summary>
		/// <param name="mailParams" type="Array">
		///		Associative array (or object with properties) that contains mail field.
		//		Key in array (or property name) represents a mail field name (in lower case) 
		//		and value of item in array (or property value in an object) is a value 
		//		of corresponding mail field.
		/// </param>
        
        if (!mailParams)
			return;
        
        var oWindowOptions = new Olive.Data.PopupWindowOptions();
        oWindowOptions.target = "popup_mailForm";
        oWindowOptions.setIsResizable(false);
        oWindowOptions.setHeight(380);
        oWindowOptions.setWidth(360);
         
        //set correct title for e-mail popup window
        var sPopupTitle = "";
        if (bIsEntity)   
        {   
            var sEntityType = this.WebApplication.getEntityType(mailParams.oSrcContentItem.m_sEntityId);  
            switch(sEntityType.toLowerCase())
            {
                case Olive.ContentItem.Entity.EntityTypes.article:
                        sPopupTitle = this.getResString("Popup_Email_Article");
                        break;
                case Olive.ContentItem.Entity.EntityTypes.ad:
                        sPopupTitle = this.getResString("Popup_Email_Ad");
                        break;
                case Olive.ContentItem.Entity.EntityTypes.picture:
                        sPopupTitle = this.getResString("Popup_Email_Picture");
                        break;
                default:
                        break;
            }           
        }    
        else // it is a "document"
        {
            sPopupTitle = this.getResString("Popup_Email_Page");
        }
        oWindowOptions.setTitle(sPopupTitle);
        
        // Check if we open the e-mail popup from main or from Component Viewer
        if (!oOpenerPage)
        {
            oOpenerPage = this;
        }
        oOpenerPage.openPopup("SendMailForm.htm", oWindowOptions, mailParams, null, true);
	}
	
	function MainPage_closeAndSetCookie(oPopupWindow, bSetCookie, sCookieName)
	{		
		// Close window
		if (oPopupWindow)
		    oPopupWindow.close();		

		if (bSetCookie)
		    DHTML.setCookie(sCookieName, "true");		
	}	
	
	function MainPage_OpenOkToChangeIssueDialog(oPopupArgs)
	{
	    var oWindowOptions = new Olive.Data.PopupWindowOptions();
        oWindowOptions.target = MainPage.ElementIDs.Popup_OkToChangeIssueID;
        oWindowOptions.setIsResizable(false);
        oWindowOptions.setHeight(180);
        oWindowOptions.setWidth(405);
        oWindowOptions.setTitle("Do you want to view a different issue?");        

		if (oPopupArgs)
		{
			this.m_oContentItem_ChangeIssue = oPopupArgs.oContentItem;

            var oPriorDate = OwcGetControl("priordate");
            var oNewDate = OwcGetControl("newdate");
			var sPriorDate = oPopupArgs.sPriorDocHRef.substring(oPopupArgs.sPriorDocHRef.indexOf("/") + 1);
			var sNewDate = oPopupArgs.sNewDocHRef.substring(oPopupArgs.sNewDocHRef.indexOf("/") + 1);
			if (sPriorDate)
			    oPriorDate.setValue(sPriorDate);
			if (sNewDate)
			    oNewDate.setValue(sNewDate);
		}
		this.m_controlDoNotAskAgain_ChangeIssue = OwcGetControl("bDoNotAskAgain_ChangeIssue");
		this.m_controlDoNotAskAgain_ChangeIssue.setValue(false);
				
		this.openPopup("", oWindowOptions, oPopupArgs, null, true);    
	}
	
	function MainPage_changeIssue_Cancel()
	{
		// Close window	and set cookie if need
		var bDoNotAskAgain = this.m_controlDoNotAskAgain_ChangeIssue.getValue();
		this._closeAndSetCookie(this.m_oPopupWindow_ChangeIssue, bDoNotAskAgain, this.m_sCookieName_ChangeIssue);
	}
	
	function MainPage_changeIssue_OK()
	{		
		// Close window	and set cookie if need
		var bDoNotAskAgain = this.m_controlDoNotAskAgain_ChangeIssue.getValue();
		this._closeAndSetCookie(this.m_oPopupWindow_ChangeIssue, bDoNotAskAgain, this.m_sCookieName_ChangeIssue);		

		this.WebApplication._openDifferentDocument(this.m_oContentItem_ChangeIssue);
	}		
	
	//open pop-up with info about bookmark in Firefox browser
	function MainPage_OpenBookmarkInFirefoxDialog(docViewerAgg)
	{  
		var sValue = DHTML.getCookie(this.m_sCookieName_BookmarkInFirefoxNote);
		
		if (sValue != "true")  
		{ 
			var oWindowOptions = new Olive.Data.PopupWindowOptions();
            oWindowOptions.target = MainPage.ElementIDs.Popup_BookmarkInFirefoxNoteID; 
            oWindowOptions.setIsResizable(false);
            oWindowOptions.setHeight(240);
            oWindowOptions.setWidth(500);
            oWindowOptions.setTitle(this.getResString("PopupInfo_Firefox_Bookmarks_Title")); 
            
            this.m_controlDoNotAskAgain_BookmarkInFirefoxNote = OwcGetControl("bDoNotAskAgain_BookmarkInFirefoxNote");
	        this.m_controlDoNotAskAgain_BookmarkInFirefoxNote.setValue(false);
            
		    this.openPopup("", oWindowOptions, docViewerAgg, null, true);
		}	    
	}
	
	function MainPage_bookmarkInFirefoxNote_OK()
	{		
		// Close window	and set cookie if need
		var bDoNotAskAgain = this.m_controlDoNotAskAgain_BookmarkInFirefoxNote.getValue();
		this._closeAndSetCookie(this.m_oPopupWindow_BookmarkInFirefoxNote, bDoNotAskAgain, this.m_sCookieName_BookmarkInFirefoxNote);	
	}
	
	function MainPage_findControls()
	{
		/// <summary>Find controls needed by the other methods on the page</summary>
	    // get document viewer aggregated object
		this.m_docViewerAgg = this.findControlByType(Olive.Controls.controlTypeNames.DocViewerAgg);
		if (!this.m_docViewerAgg)
		{
			this.reportError(DHTML.newError(MainPage.ErrorCodes.DocViewerAggAbsence, "Internal error: Cannot find Olive.Controls.DocViewerAgg control on HTML page"));
			return;
		}

		this.m_flashViewer = this.m_docViewerAgg.m_oViewerCtrl;
		if (!this.m_flashViewer)
		{
			this.reportError(DHTML.newError(MainPage.ErrorCodes.FlashViewerAbsence, "Internal error: Cannot find Olive.Controls.FlashViewer control on HTML page"));
			return;
		}
			
		this.m_docViewerBar = OwcGetControl(MainPage.ElementIDs.DocumentToolbarId);
		this.m_oContentsTitle = OwcGetControl(MainPage.ElementIDs.ContentsTitleID);
		this.m_oIssueDate = OwcGetControl(MainPage.ElementIDs.IssueDateID);
		this.m_oContentsPublicationName = OwcGetControl(MainPage.ElementIDs.ContentsPublicationNameID);
		
        this.m_oAllContentsPageItem = OwcGetControl(MainPage.ElementIDs.CtrlAllContentsID);        
        this.m_oContentsPageItem = OwcGetControl(MainPage.ElementIDs.PageItemContentsID);       
		
		this.m_oPaneListContents = OwcGetControl(MainPage.ElementIDs.PaneListContentsID);
		this.m_oPopupWindow_ChangeIssue = OwcGetControl(MainPage.ElementIDs.Popup_OkToChangeIssueID);
		this.m_oPopupWindow_BookmarkInFirefoxNote = OwcGetControl(MainPage.ElementIDs.Popup_BookmarkInFirefoxNoteID);
		this.m_oPopupWindow_MoreIssues = OwcGetControl(MainPage.ElementIDs.Popup_moreIssuesID);
		
		this.m_oPageItemCover = OwcGetControl(MainPage.ElementIDs.PageItemCoverID);
		this.m_oPageItemHelp = OwcGetControl(MainPage.ElementIDs.PageItemHelpID);
		this.m_oPageItemSearch = OwcGetControl(MainPage.ElementIDs.PageItemSearchID);
				
	}
	
	function MainPage_bindTabs()
	{
		/// <summary>bind tab strips and page switchers</summary>		
		this.m_oMainPageSwitcher = OwcGetControl(MainPage.ElementIDs.MainPageSwitcherID);
		if (this.m_oMainPageSwitcher)
		{
	        this.m_oMainTabStrip = OwcGetControl(MainPage.ElementIDs.MainTabStripID);
		    if (this.m_oMainTabStrip && this.m_docViewerAgg)
		    {
		        this.m_oMainTabStrip.attachOwcEventHandler("itemActivating", this.m_docViewerAgg._onTabActivating, this.m_docViewerAgg);
			    Olive.Binding.SyncActiveItems.BindControls(this.m_oMainTabStrip, this.m_oMainPageSwitcher);
		    }
		}		
		
		this.m_oContentsMainTabs = OwcGetControl(MainPage.ElementIDs.ContentsMainTabStripID);
		var oContentsMainPageSwitcher = OwcGetControl(MainPage.ElementIDs.ContentsMainPageSwitcherID);		
		if (this.m_oContentsMainTabs && oContentsMainPageSwitcher)
		{			
			Olive.Binding.SyncActiveItems.BindControls(this.m_oContentsMainTabs, oContentsMainPageSwitcher);
			var nInitialTab = MainPage.TabIndexes.cover;
			var sInitialTab = this.WebApplication.m_sInitialTab;
			switch (sInitialTab)
			{
			    case MainPage.TabTitles.cover:
			        nInitialTab = MainPage.TabIndexes.cover;
			        break;
			    case MainPage.TabTitles.toc:
			        nInitialTab = MainPage.TabIndexes.toc;
			        break;
			    case MainPage.TabTitles.help:
			        nInitialTab = MainPage.TabIndexes.help;
			        break;			    
			}
			this.m_oContentsMainTabs.setActiveItem(nInitialTab);
		}
	}

	function MainPage_get_ContentPage()
	{
		if (!this.m_oContentPage)
		{
			var frameElement = document.getElementById("contentsFrame");
			var frameDocument = DHTML_GetIFrameDocument(frameElement);
			this.m_oContentPage = Olive.Page.GetPageForDocument(frameDocument);
		}
		return this.m_oContentPage;
	}

	function MainPage_get_SearchPage()
	{
		if (!this.m_oSearchPage)
		{
			var frameElement = document.getElementById("searchFrame");
			var frameDocument = DHTML_GetIFrameDocument(frameElement);
			this.m_oSearchPage = Olive.Page.GetPageForDocument(frameDocument);
		}
		return this.m_oSearchPage;
	}

	function MainPage_onPageItemActivated(eventArgs)
    {
        var oSrcObject = eventArgs.srcObject;
        if (!oSrcObject || oSrcObject.controlType != Olive.Controls.controlTypeNames.PageItem)
            return;
                
        var stateChanged = eventArgs.prevState ^ eventArgs.newState;
		if ((stateChanged & Olive.IState.State.ActiveMask) != 0)
		{
			var pageItemActivated = ((eventArgs.newState & Olive.IState.State.ActiveMask) == Olive.IState.State.Active);
			if (!pageItemActivated)
			    return;
			if (this.m_oPaneListContents)
                this.m_oPaneListContents.recalcLayout();    
            if (isSafari())
            {
				var contentPage = this.get_ContentPage();
	            if (contentPage)
	               contentPage._onPageItemActivated();
	        }
		}
    }
	
	function MainPage_getContentItem()
	{
		/// <summary>Get the content item of the doc viewer agg</summary>
		/// <returns type="Olive.ContentItem">The content item of the doc viewer agg</returns>
		if (!this.m_docViewerAgg)
			return null;
		var sourceContentItem = this.m_docViewerAgg.getContentItem();
		return sourceContentItem;
	}

	function MainPage_onEntityDoubleClicked(eventArgs)
	{
		/// <summary>
		///		Handler for the <c>entityDoubleClicked</c> event of document
		///		viewer control.  Opens a component in a popup window
		/// </summary>
		/// <param name="eventArgs" type="Olive.Event">
		///		Event arguments object.
		/// </param>
	    var oContentItem = new Olive.ContentItem.Entity();
		oContentItem.m_sDocHRef = eventArgs.sBaseHref;
		oContentItem.m_sEntityId = eventArgs.sEntityID;
		oContentItem.m_sPublicationDescription = eventArgs.srcObject.getContentItem().m_sPublicationDescription;
		
		// TODO: show hits if exists
		
	    // open the ICViewer in viewMode specified in configuration settings
		oContentItem.expando = true;
		oContentItem.viewMode = this.WebApplication.m_sICViewMode;
	    this.WebApplication.OpenComponent(oContentItem);
	}
	
	function MainPage_onDocumentLoaded(eventArgs)
	{
		/// <summary>
		///		Handler for the <c>documentLoaded</c> event of document
		///		viewer control.  Parse the date of the issue. Open ICViewer if required.
		/// </summary>
		/// <param name="eventArgs" type="Olive.Event">
		///		Event arguments object.
		/// </param>
	    this.m_docViewerAgg.m_oTOCCtrl.contentLoadItem(this.m_docViewerAgg.getContentItem());

	    // parse date of the issue      
        var sDocHRef = eventArgs.sBaseHref;
		if (sDocHRef)
		{
			this.WebApplication.m_sDocHRef = sDocHRef;
			var sDate = sDocHRef.substring( sDocHRef.indexOf("/") + 1 );
			var sFormat = this.WebApplication.m_sDateFormat;

			if (this.m_oIssueDate)
			{
			    this.m_oIssueDate.setFormat(sFormat);
			    this.m_oIssueDate.setValue(sDate);			    
			}
			
			if (this.m_oContentsTitle)
		    {
		        this.m_oContentsTitle.setFormat(sFormat);
		        this.m_oContentsTitle.setValue(sDate);
		    }
		}
		
		if (this.m_oContentsPublicationName)
        {
            this.m_oContentsPublicationName.setValue(eventArgs.sPublicationDescription + String.fromCharCode(160, 160));
        } 

        var oContentItem = this._getContentItem();        
        if (!oContentItem)
	        return;
		    
        // if there is an EntityId (got from url) => open IC Viewer
        if (oContentItem.m_sEntityId && this.WebApplication.m_bOpenICViewerOnDocumentLoad)
        {   
            // open the ICViewer in viewMode specified in configuration settings
	        oContentItem.expando = true;
	        oContentItem.viewMode = this.WebApplication.m_sICViewMode;
            this.WebApplication.OpenComponent(oContentItem);
        }
        else
        {
			this.WebApplication.ClosePopups(false);//not necessary - popups were closed before loading document
        }
        
        // if there is an PrimId (got from url) => highlight the primitive
        if (oContentItem.m_sPrimId)
        {    	    
            if (this.m_flashViewer)
		    {
		        var nPageNo = oContentItem.m_nPageNo;
		        var sPrimId = oContentItem.m_sPrimId;
		        var sEntityId = oContentItem.m_sEntityId;
		        this.m_flashViewer.gotoPageWithHighlighting(nPageNo, sPrimId, sEntityId);		
		    }
        }
 
		this.WebApplication.m_bOpenICViewerOnDocumentLoad = false; //re-initialize - not needed
	}	

	function MainPage_followPageLink(nPageNo)
	{
		/// <summary>Handler for clicking on a page link: go to page</summary>
		///	<param name="nPageNo" type="number">Page number of the link</param>
		if (nPageNo > 0 && this.m_flashViewer)
			this.m_flashViewer.gotoPageWithHighlighting(nPageNo, "");
	}

	function MainPage_onPrintDocument()
	{
		/// <summary>
		///		Opens &quot;Print Document Pages&quot; form and prints 
		///		document pages if user confirms this operation
		/// </summary>
        var oWindowOptions = new Olive.Data.PopupWindowOptions();
        oWindowOptions.target = "popup_printForm";
        oWindowOptions.setHeight(387);
        oWindowOptions.setWidth(340);
        oWindowOptions.setTitle("Print Document");
        oWindowOptions.setIsResizable(false);
		
		var printFormData = this.m_docViewerAgg.PreparePrintData();
		if (!printFormData)
			return;
        var callbackOnClose = Delegate.CreateDelegate(this._PrintDocumentPages, this);
        this.openPopup("PrintPagesForm.htm", oWindowOptions, printFormData, callbackOnClose, true);
	}

	function MainPage_onSendMail()
	{
		/// <summary>
		///		Opens &quot;Send By e-Mail&quot; form for the current view
		/// </summary>
		var contentItem = this._getContentItem();		
		this.WebApplication.SendItemByMail(contentItem, false, null, this.m_docViewerAgg);
	}

	function MainPage_onCopyLink()
	{
		/// <summary>
		///		Copies link to the current view to the clipboard
		/// </summary>
		this.WebApplication.copyItemToClipboard(this.m_docViewerAgg);
	}

	function MainPage_onAddToFavorites()
	{  
		/// <summary>
		///		Adds link to the current view to the browser's favorites
		/// </summary>		
		if (isMozilla())  //show pop-up with info about adding bookmark in Firefox browser
		{
		    this.WebApplication._checkOkToBookmarkPageInFirefoxBrowser(this.m_docViewerAgg);
		}
		this.WebApplication.addItemToFavorites(this.m_docViewerAgg);
	}
	
	function MainPage_onDoBookmark(oCmdParams)
	{
		/// <summary>
		///		Adds link to the current view to the online bookmarking service (digthis, delicious, etc.)
		/// </summary>
		var oSourceConrtrol = this.m_docViewerAgg;
		var oContentItem = this.m_docViewerAgg.getContentItem();
		
		//AJH:2008/04/25 --Add clipping code
		//addClipping method comes from DPCCode.js
		if (oCmdParams=="DiggThis") {
		
		var sTitle ;
		sTitle  = this.WebApplication.buildBookmarkTitle(oContentItem, oSourceConrtrol);
		
		var sUrl ;
		sUrl  = this.WebApplication.buildBookmarkURL(oContentItem, oSourceConrtrol);
			
			addClipping(sTitle,sUrl);
	
		}
		else
		{
			this.WebApplication.createBookmark(oCmdParams, oContentItem, oSourceConrtrol);
		}
		
	}
		
	function MainPage_onPDFDocDownload()
    {
		/// <summary>Handler for requesting to download the pdf of the document</summary>
        var sLink = this.WebApplication.createPDFDownloadLink(this.m_flashViewer, OwcPDFDownloadItem_Doc);
		window.open(sLink, "DownloadPDF");
    }
    
    function MainPage_onPDFPageDownload()
    {
		/// <summary>Handler for requesting to download the pdf of the page</summary>
        var sLink = this.WebApplication.createPDFDownloadLink(this.m_flashViewer, OwcPDFDownloadItem_Page);
		window.open(sLink, "DownloadPagePDF");
    }
    
    function MainPage_updatePDFPageState(oCmdUiState)
    {
		/// <summary>Enables the Page-PDF menu-item if page-pdf exists and a document is loaded</summary>
		/// <param name="oCmdUiState" type="Olive.CmdUiState">Reference to object storing command's UI state</param>
        var bEnableCommand = false;
        if (this.m_flashViewer && this.m_flashViewer.hasOnePagePDF() && this.m_flashViewer.getDocumentLoaded())
            bEnableCommand = true;
        
        oCmdUiState.enableCommand(bEnableCommand);
    }
    
    function MainPage_updatePDFDocumentState(oCmdUiState)
    {
        /// <summary>Enables the Download magazine PDF menu-item if pdf document exists and a document is loaded</summary>
		/// <param name="oCmdUiState" type="Olive.CmdUiState">Reference to object storing command's UI state</param>
        var bEnableCommand = false;
        var bDownloadPDF = this.WebApplication.m_bDownloadPDF;
        
        if (bDownloadPDF && this.m_flashViewer && this.m_flashViewer.hasDocumentPDF() && this.m_flashViewer.getDocumentLoaded())
            bEnableCommand = true;
        
        oCmdUiState.enableCommand(bEnableCommand);
    }

	function MainPage__updateSaveForOfflineState(oCmdUiState)
	{
        /// <summary>Disables the SaveForOffline menu-item for Safari</summary>
		/// <param name="oCmdUiState" type="Olive.CmdUiState">Reference to object storing command's UI state</param>
		var bEnableCommand = !isSafari();
        oCmdUiState.enableCommand(bEnableCommand);
	}

    function MainPage_onSaveForOffline()
    {
		/// <summary>Handler for requesting to save the document for offline viewing</summary>
	    //this.WebApplication.SaveForOffline(this._getContentItem());
	    
	    var oContentItem = this._getContentItem();
	    if (!oContentItem)
		    return;
		    //getIssueName(oContentItem, sFormatingStringIdentifier)
		var sLinkTitle = this.WebApplication.getIssueName(oContentItem, "AM3IssueShortDescription");
		var sDocHref = oContentItem.getDocHRef();
		if (sLinkTitle == "")
		{
			sLinkTitle = "Document "+ sDocHref;
		}
		var oArguments = { SaveForOffline : true };		
		var sURL = "SaveForOffline.htm?DocHRef="+sDocHref+"&DocTitle="+sLinkTitle+"&UniqueId=" + generateUniqueID();
		var oOptions = new Olive.Data.PopupWindowOptions();
		oOptions.target = "popup_SaveForOffline";
		oOptions.setMinimalWidth(265);
		oOptions.setMinimalHeight(150);
		oOptions.SaveForOffline = true;
		this.openPopup(sURL, oOptions, oArguments, null, true);
    }
	
	function MainPage_onMoreIssues()
	{
		/// <summary>
		///		Adds link to the current view to the browser's favorites
		/// </summary>
		var oWindowOptions = new Olive.Data.PopupWindowOptions();
        oWindowOptions.target = MainPage.ElementIDs.Popup_moreIssuesID;
        oWindowOptions.setWidth(510);
        oWindowOptions.setHeight(620);
        oWindowOptions.setTitle("More Issues");
        oWindowOptions.setIsResizable(false);
        
        var contentItem = this._getContentItem();
        if (!contentItem)
            return;
        this.openPopup("", oWindowOptions, contentItem, null, true);
               
        this.m_oYearList = this.findControlByType(Olive.Controls.controlTypeNames.YearList);
		if (!this.m_oYearList)
		{
			this.reportError(DHTML.newError(-1, "Cannot find the Olive.Controls.controlTypeNames.YearList control on HTML page."));
			return;
		}

		this.m_oArchiveThumbList = this.findControlByType(Olive.Controls.controlTypeNames.ThumbList);
        if (!this.m_oArchiveThumbList)
		{			
			this.reportError(DHTML.newError(-1, "Cannot find the Olive.Controls.controlTypeNames.ThumbList control on HTML page."));
			return;
		}
    
        if (this.m_oArchiveThumbList)
        {
		    // clear content, before showing the new one
		    this.m_oArchiveThumbList.clearControls();
		    this.m_oArchiveThumbList.HtmlElement.innerHTML = "";
		}
		    
		if (this.m_oPopupWindow_MoreIssues)
		{		    
		    var nPopupHeight = DHTML.getElemHeight(this.m_oPopupWindow_MoreIssues.HtmlElement);    		
		    var nTopBorderHeight = DHTML.getElemHeight(this.m_oPopupWindow_MoreIssues.getUiElement("popupwindowtopborder"));
		    var nBottomBorderHeight = DHTML.getElemHeight(this.m_oPopupWindow_MoreIssues.getUiElement("popupwindowbottomborder"));		    
		    var nCaptionHeight = DHTML.getElemHeight(this.m_oPopupWindow_MoreIssues.getUiElement("popupwindowcaption"));
		    var oHeaderMoreIssues = getObj("headerMoreIssues");
		    var nHeaderHeight = DHTML.getElemHeight(oHeaderMoreIssues);
		    
		    var nPopupWidth = DHTML.getElemWidth(this.m_oPopupWindow_MoreIssues.HtmlElement);
		    var nLeftBorderWidth = DHTML.getElemWidth(this.m_oPopupWindow_MoreIssues.getUiElement("popupwindowcontentleftborder"));
		    var nRightBorderWidth = DHTML.getElemWidth(this.m_oPopupWindow_MoreIssues.getUiElement("popupwindowcontentrightborder"));
		    
		    var nConstantOffset = 4;
    				    
		    DHTML.setElemHeight(this.m_oArchiveThumbList.HtmlElement, nPopupHeight - nTopBorderHeight - nBottomBorderHeight - nCaptionHeight - nHeaderHeight - nConstantOffset);
		    DHTML.setElemWidth(this.m_oArchiveThumbList.HtmlElement, nPopupWidth - nLeftBorderWidth - nRightBorderWidth - nConstantOffset);
		}
		
        var sPublication = "";
        var sYear = "";
        if (!contentItem)
           return; 
        if (contentItem.m_sDocHRef && contentItem.m_sDocHRef !== "")
        {
            var nFirstSlashIndex = contentItem.m_sDocHRef.indexOf("/");
            sPublication = contentItem.m_sDocHRef.substring(0, nFirstSlashIndex);
            
            var nSecondSlashIndex = contentItem.m_sDocHRef.indexOf("/", nFirstSlashIndex + 1);
            sYear = contentItem.m_sDocHRef.substring(nFirstSlashIndex + 1, nSecondSlashIndex);
        }
        
	    var oContentItemYearRange = Olive.ContentItem.CreateByType(OwcContentItem_YearRange);
        oContentItemYearRange.m_sPublication = sPublication;
        //this.m_oYearList.m_sYear = sYear; // show "All Years" initially
	    
        Olive.Binding.BindContentsOnValueChanging.BindControls(this.m_oYearList, this.m_oArchiveThumbList);
        this.m_oArchiveThumbList.onSelectionItemClicked = Delegate.CreateDelegate(this._onThumbListSelectionChanged, this); 
        
        this.m_oYearList.m_oContentItem = oContentItemYearRange;		    
	    this.m_oYearList.contentLoad();
        
        // ---------- Initialize magnifier control ----------
	    if (this.m_magnifierControl)
	    {
	        this.m_magnifierControl.setMaxWidth(this.WebApplication.m_nMagnifierMaxWidth);
	        this.m_magnifierControl.setMaxHeight(this.WebApplication.m_nMagnifierMaxHeight);
	        this.m_magnifierControl.setMagPercent(this.WebApplication.m_nMagnifierMagPercent);
	    }
	}
	
	function MainPage_onNavigationPaneVisibilityChanged(eventArgs)
	{
	    var oDocViewer = this.m_docViewerAgg;
	    
	    var oNavTabStrip = oDocViewer.m_oNavTabStrip;
	    var oNavPageSwitcher = this.m_oMainPageSwitcher;
	    var bPaneVisible = eventArgs.bPaneVisible;
	    
	    if (!oNavTabStrip || !oNavPageSwitcher)
	        return;
	    
	    if (!bPaneVisible)
	    {
	        // set the inactive state for the tab item with active state
	        var oActiveTabItem = oNavTabStrip.getActiveItem();
	        oActiveTabItem.changeState(false, oNavTabStrip.m_dwActiveItemState, oNavTabStrip.m_dwActiveItemStateMask);
	        oNavTabStrip.m_iActiveItem = -1;
	    }
	    else
	    {
	        // set the active state for the tab item corresponding to the page item with active state
	        // happens only when the user comes to the 1st page of the FlashViewer and it switches to the single page mode
	        var iActivePageItemIndex = oNavPageSwitcher.getActiveItemIndex(); 	        
	        oNavTabStrip.setActiveItem(iActivePageItemIndex, true);
	    }
	}

	function MainPage_PrintDocumentPages(dialogResult, returnValue, popupInfo)
	{
		/// <summary>
		///		Internal method, which is called when end-user confirms or
		///		cancels printing of document pages by closing the &quot;Print
		///		Document Pages&quot; form.
		/// </summary>
		/// <param name="dialogResult"></param>
		/// <param name="returnValue"></param>
		/// <param name="popupInfo"></param>
        if (dialogResult == Olive.PopupInfo.DialogResult.Cancel)
			return;	// Nothing to do

		var contentItem = this.m_docViewerAgg.getContentItem();
		var printData = new Olive.ContentItem.Print();
		printData.copyFrom(contentItem);
        printData.m_oPrintFormData = returnValue;
		
		this.openPopup("PrintPagesView.htm", "popup_printDocumentView", printData, null, true);
	}	
	
	function MainPage_openAccessNotificationDialog( oPopupArgs )
	{
		var callbackOnClose = Delegate.CreateDelegate(this.WebApplication._AccessNotificationCallback, this.WebApplication);
		this.openPopup("AccessNotificationDialog.htm", "popup_AccessNotification", oPopupArgs, callbackOnClose, true);
	}

	function MainPage_LoadIEScriptWarning()
	{
        var oContentDiv = getObj(MainPage.ElementIDs.ContentDiv);
		if (oContentDiv)
		{
			oContentDiv.innerHTML = "<iframe id='" + MainPage.ElementIDs.IEScriptWarningFrameID + "' src='" + MainPage.IFrames.IEScriptWarning + "' frameborder='0'></iframe>";
		}
	}
	
	function MainPage_updateIFrame(eventArgs)
	{
	    var oPageItem = eventArgs.srcObject;
	    if (!oPageItem || !oPageItem.get_HtmlElement)
	        return;
	        
	    var oFrame = getChildObjectByTag(oPageItem.get_HtmlElement(), "iframe");
	    
	    switch (oPageItem)
	    {
	        case this.m_oPageItemHelp:
	            oFrame.src = MainPage.IFrames.HelpIFrame;
	            break;
	        case this.m_oPageItemSearch:
	            oFrame.src = MainPage.IFrames.SearchPane;
	            break;
	           
	    }
	            
        oPageItem.detachOwcEventHandler("stateChanged", this._updateIFrame, this);
	}
	
	function MainPage_importScripts(src)
	{
        var scriptElem = document.createElement('script');
        scriptElem.setAttribute('src',src);
        scriptElem.setAttribute('type','text/javascript');
        document.getElementsByTagName('head')[0].appendChild(scriptElem);
	}

    function MainPage_onContentsPaneResized(oEvent)
    {
        var oContentsPane = document.getElementById(MainPage.ElementIDs.CtrlContentsPaneID);
        
        var oPageSwitcher = document.getElementById(MainPage.ElementIDs.MainPageSwitcherID);
        var oAllContents = document.getElementById(MainPage.ElementIDs.CtrlAllContentsID);

        // Resize the DIVs that wrap the contens pane (they are not resized by the pane list).
        oAllContents.style.width = oContentsPane.style.width;
        oAllContents.style.height = oContentsPane.style.height;
        oPageSwitcher.style.width = oContentsPane.style.width;
        oPageSwitcher.style.height = oContentsPane.style.height;
    } // MainPage._onContentsPaneResized
        
    // hide navigation pane when user click on close button
    function MainPage_HideContentPane()
    {
        if( this.m_docViewerAgg )
        {
            this.m_docViewerAgg._HideNavigationPane();
        }
    }
    
    // Open olivesoftware.com homepage when clicking on Olive logo
    function MainPage_OpenOliveSoftwareWebsite()
    {
        window.open("http://www.digitalpc.co.uk/","_blank","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=yes, width=930, height=750");
    }

	JScript.Type.RegisterClass("MainPage", MainPage, Olive.Page);
}

Olive.WindowBinder.RegisterPageClass(window, MainPage);

