

function beginWindowModeChange(desiredSetting, originalPage)
{		
	if(window.top.frames[0].topNavigationSection.setting == desiredSetting){return;}

	var windowModeChangeLink = '';

	//Build the link based on the desired setting		
	if(desiredSetting == 'single'){
		windowModeChangeLink = '/contentManaged/windowModeChange/toSingleWindow.aspx?sourcePage=' + escape(originalPage);
		window.top.frames[0].topNavigationSection.startingWindowChange = true;
		window.top.frames[1].location.href = 'http://' + parentWindow.content.location.hostname + windowModeChangeLink;
	}else{
		windowModeChangeLink = '/default.aspx?redirect=' + escape('/contentManaged/windowModeChange/toMultipleWindow.aspx');	
		window.top.location.href = windowModeChangeLink
	}
	
}



function cancelChange()
{
	//Parse and isolate the return redirect
	var redirect = new String(unescape(document.location.search));
	redirect = redirect.substring(redirect.indexOf('http'), redirect.length);
	
	window.top.frames[0].topNavigationSection.startingWindowChange = false;
	window.top.frames[1].location.href = redirect;
	//window.top.frames[1].location.href = 'http://' + window.top.frames[1].location.hostname + redirect;
}


function continueChange(changeTo)
{
	setNamedCookie('preferredWindowMode', changeTo);
	
	if(changeTo == 'single')
	{	
		var windowMaps = window.top.frames[0].rootWindow.windowPageMappings;
		var thisWindowMapping;
		var homeWindowMapping;
		
		//Search the window page mappings for window references
		for(var i = 0; i < windowMaps.length; i++)
		{
			if(windowMaps[i].link.indexOf('home.aspx') > -1)
			{
				homeWindowMapping = windowMaps[i];
			}
			
			if(windowMaps[i].windowRef == window.top)
			{
				thisWindowMapping = windowMaps[i];
			}
			
			//If the window page mapping has a window reference and it isn't this window and it not closed, then close this window
			if(windowMaps[i].windowRef == undefined)
			{
				continue;
			}else if(windowMaps[i] != thisWindowMapping && windowMaps[i] != homeWindowMapping && !windowMaps[i].windowRef.closed)
			{				
				windowMaps[i].windowRef.close();
				windowMaps[i].windowRef = undefined;
			}
		}	
	
		if(homeWindowMapping.windowRef == undefined)
		{
			homeWindowMapping.windowRef = window.top;		
		}
	
		//Update the navigation section with the desired setting
		homeWindowMapping.windowRef.frames[0].topNavigationSection.startingWindowChange = false;
		homeWindowMapping.windowRef.frames[0].setNavigationStyle(changeTo);
		
		//Redirect the home mapping if it isn't already at the home page
		if(homeWindowMapping.windowRef.frames[1].document.location.pathname.indexOf('/contentManaged/home/home.aspx') == -1)
		{
			homeWindowMapping.windowRef.frames[1].document.location = '/contentManaged/home/home.aspx';
		}
	
		//Close this window if it isn't the home window
		if(homeWindowMapping != thisWindowMapping)
		{
			thisWindowMapping.windowRef.close();
		}
		
	}else if(changeTo == 'multiple'){
		//Update the navigation section with the desired setting
		window.top.frames[0].topNavigationSection.startingWindowChange = false;
		window.top.frames[0].setNavigationStyle(changeTo);
	
		window.top.document.location = '/default.aspx?s=v';
	}
}


function homeIsClosing()
{		
	var closeWebsiteWindow;
	
	//Exit if we are entering a window change mode
	if(window.top.frames[0].topNavigationSection.startingWindowChange){return;}
	
	var windowMaps = window.top.frames[0].windowPageMappings;
	
	//Search the window page mappings for window references
	for(var i = 0; i < windowMaps.length; i++)
	{
		if(windowMaps[i].windowRef != undefined)
		{						
			//Only check for, and close, windows other than this one
			if(!windowMaps[i].windowRef.closed && windowMaps[i].windowRef != window.top)
			{
				//Pop up the close website window if it hasn't been loaded yet
				if(closeWebsiteWindow == undefined)
				{
					closeWebsiteWindow = window.open('/contentManaged/windowModeChange/closeWebsite.aspx');
				}
					
				windowMaps[i].windowRef.close();
			}
		}
	}
}





/*
function checkCloseWebsiteWindowLoading()
{
	loopIteration++;
	window.status = 'WINDOW STATUS:' + closeWindow.document.body.readyState + ' - ITERATION:' + loopIteration;
	try{
		if(closeWindow.document.body.readyState == 'loaded' || closeWindow.document.body.readyState == 'complete')
		{
			//Update the close website window with references to all known open windows
			window.status = 'Finished loading closeWebsiteWindow';
			closeWindow.windowPageMappings = homeIsClosingWindowPageMappings;
		}else{
			//Repeat the loop
			closeWindowTimer = window.setTimeout('checkCloseWebsiteWindowLoading()', 1000);
		}
	}catch(e){
		//Repeat the loop
		closeWindowTimer = window.setTimeout('checkCloseWebsiteWindowLoading()', 1000);		
	}
}
*/








/*


function toggleSetting(desiredSetting)
{	
	navDisabled = false;	
		
	//Leave if they selected what they had before
	if(topNavigationSection.setting == desiredSetting){return;}
	
	//If we are going from multi window to single window, check if we have references to windows
	if(desiredSetting == 'single')
	{
		var closeAllWindowsButRoot;
		
		//Search the window page mappings for window references
		for(var i = 0; i < windowPageMappings.length; i++)
		{
			//If the window page mapping has a window reference and it isn't the root window, then process its window for closing
			if(windowPageMappings[i].windowRef != undefined && !windowPageMappings[i].isRoot && !windowPageMappings[i].windowRef.closed)
			{
				if(closeAllWindowsButRoot == undefined)
				{					
					closeAllWindowsButRoot = confirm('\t   SWITCHING FROM MULTIPLE WINDOWS TO A SINGLE WINDOW\n' +
						'--------------------------------------------------------------------------------------------------------------\n' + 
						'--------------------------------------------------------------------------------------------------------------\n\n' + 
						'\tYou are currently using single window mode for browing the Discover\n' +
						'\tGuide Map web site. The all links for the site will open in this window.\n\n' +
						'\tYou can close all other Discover Guide Map windows by selecting "OK"\n' +
						'\tbelow. IF YOU DO NOT WANT TO CLOSE ALL OTHER BROWSER\n' +
						'\tWINDOWS, please select "CANCEL".\n\n' + 						
						'--------------------------------------------------------------------------------------------------------------\n' + 
						'--------------------------------------------------------------------------------------------------------------');
				
				
					i = -1;				
				}else if(closeAllWindowsButRoot)
				{
					windowPageMappings[i].windowRef.close();
					windowPageMappings[i].windowRef = undefined;				
				}else{
					//Tell the window that it is the root window and is in single window mode
					windowPageMappings[i].windowRef.header.rootWindow = windowPageMappings[i].windowRef.header;
					
					for(var j = 0; j < windowPageMappings[i].windowRef.header.windowPageMappings.length; j++)
					{
						windowPageMappings[i].windowRef.header.windowPageMappings[j].windowRef = undefined;
					}
					
					windowPageMappings[i].windowRef.header.topNavigationSection.toggleSetting('single');
				}
			}
		}	
	}
	
	//Tell each opened window we have a reference for that it is the root window and is in single window mode
	for(var i = 0; i < windowPageMappings.length; i++)
	{
		windowPageMappings[i].windowRef = undefined;		
	}
	
	//Update the navigation section with the desired setting
	setNavigationStyle(desiredSetting);	
}


*/
