//*******		FILENAME:  ButtonManagement.js (Top Window Code) 	*******//

//*******	Artware Button Management										*******//
//*******			Copyright 2005 by Artware Studios, Inc.  			*******//
//*******		Include in frameset page after ButtonConstants.js	*******//
//###																					#####
//#####--->>>	Standard Package: Not Customized.						#####
//###																					#####

//***	Global Variables referenced in ButtonTools.js or elsewhere			***//
var menuSelection = new Array(mainSubmenuArraySize);	// Current selection of menu or submenu.
var subMenuNotLoaded = new Array(mainSubmenuArraySize);// Keeps track of whether a submenu is loaded.
var subMenuPageArray = new Array(mainSubmenuArraySize);	// Stores subMenu page names.
var lastHistoryItem = 0;
//***	Global Variables referenced in ButtonTools.js or elsewhere			***//

//***	Global Functions referenced in ButtonTools.js or other files		***//
function changeContentFramePage(theContents)
{
	contentFrame.location.href = theContents;
}//function changeContentFramePage(theContents)

function changeFrameContent(theFrame, theContents)
{// Fills  theFrame  with  theContents.  Puts in history.
//alert("Changing Frame to " + theContents);
	theFrame.location.href = theContents;
}//function changeFrameContent(theFrame, theContents)

function doSubMenuSplashLoad(subMenuSplash)
{//Called ONLOAD from submenu splash pages, e.g. in  resetSubmenuLoadStatus().
//NOTE:  Is this function really needed for sub menu splash pages????.
//NOTE:  May need to change index on some loops.
//	preLoadImages();
//	setLocalVariables();
	mainMenuFrame.setClickState(menuSelection[subMenuSplash]);
	resetSubmenuLoadStatus(subMenuSplash);
	contentFrame.focus();
//	if (parent.contentFrame.document)
//		parent.contentFrame.document.links[0].focus();	//Is this 2nd one needed in order for IE to work?
}//function doSubMenuSplashLoad(subMenuSplash)

function initializeSite()
{//Called from init() in  mainMenuButtons.js .
	setSubMenuPages();	
	resetSubmenuLoadStatus(0);
	resetMenuSelections();
}//function initializeSite()

function loadSubMenuPage(pageIndex)
{//Called from setClickState in  mainMenuButtons.js .
alert("loadSubMenuPage: subMenuPageArray[i] = " + subMenuPageArray[pageIndex]);
	replaceFrameContent(subMenuFrame, subMenuPageArray[pageIndex]);
	resetSubmenuLoadStatus(pageIndex);
	
//	resetSubmenuLoadStatus(pageIndex);//Now in submenu.loadClick.????????????????
//	if (lastHistoryItem == SUBMENUPAGE)
//		replaceFrameContent(subMenuFrame, subMenuPageArray[pageIndex]);
//	else 
//		changeFrameContent(subMenuFrame, subMenuPageArray[pageIndex]);
//	lastHistoryItem = SUBMENUPAGE;
//	contentFrame.focus();
//	if (contentFrame.document)
//		contentFrame.document.links[0].focus();	//Is this 2nd one needed in order for IE to work?
alert("Exit loadSubMenuPage\n");
//	return true;
}//function loadSubMenuPage(pageIndex)

function replaceContentFramePage(theContents)
{
	contentFrame.location.replace(theContents);
}//function replaceContentFramePage(theContents)

function replaceFrameContent(theFrame, theContents)
{// Fills  theFrame  with  theContents.  Does NOT leave previous content in history.
	theFrame.location.replace(theContents);
}//function replaceFrameContent(theFrame, theContents)

function resetSubmenuLoadStatus(loadedSubmenu)
{//Sets state of all submenus to NOT loaded.
	for (var i=0; i<mainSubmenuArraySize; i++)
	{
		if (loadedSubmenu == i)
			subMenuNotLoaded[i] = false;
		else
			subMenuNotLoaded[i] = true;
	}
}//function resetSubmenuLoadStatus()

function setMenuStates(mainMenu, subMenu)
{//Sets click states for main menu and sub menus.
alert("setMenuStates: mainMenu, subMenu = "+ mainMenu + "  " + subMenu);
	closeContentPopups();
alert("setMenuStates: 1");
	menuSelection[mainMenu] = subMenu;	//Main menu button clicked.
alert("setMenuStates: 2");
//	if (mainMenuFrame.setClickState)
//	{
		mainMenuFrame.setClickState(mainMenu);
//	}
//subMenuFrame.focus();//THIS DOESN'T HELP EITHER
//if (subMenuFrame.setClickState)
//		{//THIS DOESN'T HELP TO CALL THIS AGAIN OUTSIDE mainMenuFrame.setClickState
//alert("setClickState exists in sub menu.  buttonClicked = " + buttonClicked);
//alert("parent.menuSelection[buttonClicked] = " + parent.menuSelection[buttonClicked]);
//			subMenuFrame.setClickState(parent.menuSelection[buttonClicked]);
//		}
alert("setMenuStates: 3");
	contentFrame.focus();
//	if (contentFrame.document)
//		contentFrame.document.anchors[0].focus();	//Focus on contentFrame thru anchor.
alert("setMenuStates: Exit");
}//function setMenuStates(mainMenu, subMenu)

function showPopupWindow(theIndex, theContents)
{
	popup[theIndex].display(theContents);
//	return true;
}//function showPopupWindow(theIndex, theContents)
//***	Global Functions referenced in ButtonTools.js or other files		***//

//***	Popup Window variables and functions 
popupArraySize = numberOfPopups + 1;
var popup = new Array(popupArraySize);//Referenced in ButtonTools.js as  var popup;
PAGE	 		= 0;
MENU 			= 1;
SITE 			= 2;
USER			= 3;
function PopupWindow()
{
	this.mother = PAGE;//... or MENU or SITE or USER
	this.width = 0;
	this.height = 0;
	this.top = 0;
	this.left = 0;
	this.theWindow = null;
}

popup[0] = new PopupWindow();

PopupWindow.prototype.display = function(theContents)
{
	if ((!this.theWindow) || (this.theWindow.closed))
	{
		var theFeatures =  "height=" + this.height + ",width=" + this.width;
		this.theWindow = window.open(theContents, "", theFeatures);
		this.theWindow.moveTo(this.left, this.top);
	}
	else
	{
		this.theWindow.location = theContents;
		this.theWindow.focus();
	}
	return true;
};

PopupWindow.prototype.close = function()
{
	this.theWindow.close();
	return true;
};

function initializePopups()
{
	for (var i=1; i<popupArraySize; i++)
	{
		popup[i] = new PopupWindow();
	}
}//function initializePopups()

initializePopups();
//***	Popup Window variables and functions 

//***	Local Functions used only in this file		***//
function closeContentPopups()
{//Called from setMenuStates() to close popups upon content page load.
	for (var i=1; i<popupArraySize; i++)
	{
		if (popup[i].theWindow)
		{
			if (popup[i].mother == PAGE)
			{
				popup[i].theWindow.close();
			}
		}
	}
}//function closeContentPopups()

function closeMenuPopups()
{//Called from doClick() in main menu.
	for (var i=1; i<popupArraySize; i++)
	{
		if (popup[i].theWindow)
		{
			if (popup[i].mother == MENU)
			{
				popup[i].theWindow.close();
			}
		}
	}
}//function closeMenuPopups()

function closePersistentPopups()
{//Called from window.onUnload() in frameset page.
	for (var i=1; i<popupArraySize; i++)
	{
		if (popup[i].theWindow)
		{
			if (popup[i].mother == SITE)
			{
				popup[i].theWindow.close();
			}
		}
	}
}//function closePersistentPopups()

function resetMenuSelections()
{
//alert("Enter resetMenuSelections\n");
	for (var i=0; i<mainSubmenuArraySize; i++)
		menuSelection[i] = defaultMenuButton[i];
//alert("Exit resetMenuSelections\n");
}//function resetMenuSelections()

function setSubMenuPages()
{//Specify names of sub menu pages using main button root names.
	subMenuPageArray[DEFAULTER] = siteRoot + "subMenuSplash.html";
	for (var i = 1; i < mainSubmenuArraySize; i++)
	{
		var rootName = 	siteRoot + mainButtonName[i].toLowerCase();//Specified in ButtonConstants.
		subMenuPageArray[i] = rootName + "Menu.html";
	}//for
}//function setSubMenuPages()
//***	Local Functions used only in this file		***//

//*******	Artware Button Management										*******//



