/*******************************

 NavPages.js, Version 4.0.5, 10-Jan-2008
 Copyright Northgate Information Solutions UK Limited, 2002-2008

 *******************************/

/***********************
 NavPages class

 Constructor:
	NavPages(siteMap, defaultSection, localIndex)
 Properties:
	controlFolder
	helpRoot
	index
	siteMap
	contentsPage
	searchPage
	globalSearchData
	localSearchData
	linksFrame
	glossary
 Methods:
	getContents()
	getIndex()
	getSearch()
	getSearchData()
	getLinksFrame()
	getGlossary()
	setContents(value)
	setIndex(value)
	setSearch(value)
	setGlobalSearchData(value)
	setLocalSearchData(value)
	setLinksFrame(value)
	setGlossary(value)
	setControlPath(topicUrl)

 ***********************/

// *** Constructor for NavPages class ***
function NavPages(siteMap, defaultSection, localIndex) {
	this.indexPage = ["indexData.htm"];
	this.contentsPage = ["contents.htm"];
	this.searchPage = ["search/search.htm"];
	this.globalSearchData = ["search/searchdata.htm"];
	this.localSearchData = ["searchdata.htm"];
	this.linksFrame = ["linksfra.htm"];
	this.glossary = ["glossary/glossaryFrameset.htm"];
	
	this.index = 0;
	this.localIndex = (localIndex != null);

	// Local site maps flags.
	this.siteMap = siteMap;
	this.defaultSection = defaultSection;

	this.topicFolder = "topics";
	this.controlFolder = "_control";
	this.controlPath = ""
}

// *** NavPages instance methods ***
	// Returns the URL of the contents page.
NavPages.prototype.getContents = function npGetContents() {
	return this.getProperty(this.contentsPage);
}

	// Sets the URL of the contents page.
NavPages.prototype.setContents = function npSetContents(value) {
	this.setProperty("contentsPage", value);
}

	// Returns the URL of the index page.
NavPages.prototype.getIndex = function npGetIndex() {
	if (this.localIndex)
		return this.getProperty(this.indexPage);
	else
		return this.getProperty(this.indexPage, true);
}

	// Sets the URL of the index page.
NavPages.prototype.setIndex = function npSetIndex(value) {
	this.setProperty("indexPage", value);
}

	// Returns the URL of the search page.
NavPages.prototype.getSearch = function npGetSearch() {
	/* The search page is a special case, in that, if local site maps
	   is selected, the common search page is used with a local file
	   list and search index. The search file name is therefore
	   appended to the control folder instead of to the control path. */
	if (this.controlFolder == "")
		return null;

	return (this.controlFolder
		+ (this.searchPage[this.index] == null
			? this.searchPage[0]
			: this.searchPage[this.index]));
}

	// Sets the URL of the search page.
NavPages.prototype.setSearch = function npSetSearch(value) {
	this.setProperty("searchPage", value);
}

	// Returns the URL of the search data file.
NavPages.prototype.getSearchData = function npGetSearchData() {
	if (siteMap)
		return this.getProperty(this.localSearchData, false);
	else
		return this.getProperty(this.globalSearchData, false);
}

	// Sets the URL of the search data file.
NavPages.prototype.setGlobalSearchData = function npSetSearchData(value) {
	this.setProperty("globalSearchData", value);
}

	// Sets the URL of the search data file.
NavPages.prototype.setLocalSearchData = function npSetLocalSearchData(value) {
	this.setProperty("localSearchData", value);
}

	// Returns the URL of the links frame.
NavPages.prototype.getLinksFrame = function npGetLinksFrame() {
	return this.getProperty(this.linksFrame);
}

	// Sets the URL of the links frame.
NavPages.prototype.setLinksFrame = function npSetLinksFrame(value) {
	this.setProperty("linksFrame", value);
}

	// Returns the URL of the glossary frameset.
NavPages.prototype.getGlossary = function npGetGlossary() {
	return this.getProperty(this.glossary, true);
}

	// Sets the URL of the glossary frameset.
NavPages.prototype.setGlossary = function npSetGlossary(value) {
	this.setProperty("glossary", value);
}

	// Sets the URL of the control folder.
NavPages.prototype.setControlPath = function npSetControlPath(topicUrl) {
	var temp = "";

	if (topicUrl.startsWith(this.controlFolder, true))
		temp = this.topicFolder.pathConcat(this.defaultSection);
	else if (this.siteMap)
		// Get the root of the subweb (2 levels down from root).
		temp = topicUrl.split("/").slice(0, 2).join("/");
	if (temp != "")
		temp += "/";
	
	// Append the control folder.
	temp += this.controlFolder;
	// Set the path.
	this.controlPath = temp;
}

	// Return the URL of a navigation file.
NavPages.prototype.getProperty = function npGetProperty(prop, global) {
	var temp;
	
	if (this.controlFolder == "")
		return null;

	if (!global)
		temp = this.controlPath;
	else
		temp = this.controlFolder;
	return (temp + (prop[this.index] == null ? prop[0] : prop[this.index]));
}

	// Set the URL of a navigation file.
NavPages.prototype.setProperty = function npSetProperty(prop, value) {
	for (var p in value)
		value[p] = value[p].toLowerCase();
	this[prop] = value;
}

