// Hello source-viewers
// --------------------
// This code ©2001 MMT Ltd.
// Author: Alex Norcliffe alex.n@mmtltd.com
//
// Version History: 1.1
// Purpose: Checks existence of a page in navbar. Should the page not
//  be loaded, it loads it. Otherwise, it leaves it be. Saves navbar
//  refreshes if a user is navigating one area of a site.
//
// Usage: checkUpdateNavbar('name of navbar page')


// First some booleans for determining system state. Version 1.1 does not detect
// properly on Macs, so on those machines we'll just have to keep refreshing the
// navigation bar for now
var js_pathToMainSite
var NS4		= (document.layers);
var IE4		= (document.all);
var ver4	= (NS4 || IE4);
var IE5		= (IE4 && navigator.appVersion.indexOf("5.")!=-1);
var isMac	= (navigator.appVersion.indexOf("Mac") != -1);

var navbarRoot = "../html_navbars/"

var mmt_SharedResourceLoaded = true

function checkUpdateNavbar(strPathToNavFrame,strNavBarPageCompare,strQSCompare)
{
 eval('var objFrame = ' + strPathToNavFrame)
 
 if (!objFrame)
 {
	_checkDoRedirect()
	return(false)
 }
 else
 {
	try{
		 

		//var strTest = objFrame.location + "\n" + objFrame.location.hash + "\n" + objFrame.location.host + "\n" + objFrame.location.hostname + "\n" + objFrame.location.href + "\n" + objFrame.location.pathname + "\n" + objFrame.location.port + "\n" + objFrame.location.protocol + "\n" + objFrame.location.search

		var strNavBarPage
		var strNavBarQS
		var bolRefresh = false
		var strNavBarPageCompareCheck

		var strNavBarHostRoot = strNavBarPageCompare.substring(strNavBarPageCompare.indexOf('/'),strNavBarPageCompare.lastIndexOf('/'))

		strNavBarPage = objFrame.location.pathname
		strNavBarQS = objFrame.location.search

		strNavBarPageCompareCheck = strNavBarPageCompare.substring(strNavBarPageCompare.lastIndexOf('/')+1,strNavBarPageCompare.length)
		strNavBarPage = strNavBarPage.substring(strNavBarPage.lastIndexOf('/')+1,strNavBarPage.length)

		strNavBarPageCompareCheck = strNavBarPageCompareCheck.toLowerCase()
		strNavBarPage = strNavBarPage.toLowerCase()

		strNavBarQS = strNavBarQS.toLowerCase()
		strQSCompare = strQSCompare.toLowerCase()

		//alert(strNavBarPageCompareCheck + ' - ' + strNavBarPage + "|" + strNavBarQS + ' - ' + strQSCompare)

		if (strNavBarPage != strNavBarPageCompareCheck || strNavBarQS != strQSCompare)
		{
			bolRefresh = true
		}

		//alert('Refresh ' + bolRefresh);

		if (bolRefresh != false)
		{
			var strRefreshTo = strNavBarPageCompare + strQSCompare
			//alert(strRefreshTo)
			//objFrame.location = strRefreshTo;
			objFrame.location.replace(strRefreshTo)
		}
	}
	catch(oErr){
		_checkDoRedirect()
		return(false)
	}
 }
}

function _checkDoRedirect()
{
 	 //alert("There was an error refreshing the navigation bar.\nYour browser may not fully support scripting, or there may be a script error.\nPlease contact the site administrator with this information.")
 	 var bolDoRedirect = window.confirm("There was an error refreshing the navigation bar. This page is designed to reside within a frameset. Would you like to relocate to the website's main frameset now?\n\nThis should make the navigation bar available.")
 	 if (bolDoRedirect)
 	 {
 		if (js_pathToMainSite != "")
 		{
 			window.name = "top";
 			//top.location.href = js_pathToMainSite
 			top.location.replace(js_pathToMainSite)
 		}
 		else
 		{
 			alert("Unfortunately we couldn't redirect to the main frameset. Try removing everything in the address bar apart from the domain name.")
 		}
 	 }
}

function _checkUpdateNavbar(strCurrPage)
{
 alert('checkUpdateNavbar')
 var objFrame = top.navbar;
 alert(objFrame)
 var strTest = objFrame.location + "\n" + objFrame.location.hash + "\n" + objFrame.location.host + "\n" + objFrame.location.hostname + "\n" + objFrame.location.href + "\n" + objFrame.location.pathname + "\n" + objFrame.location.port + "\n" + objFrame.location.protocol + "\n" + objFrame.location.search

 alert(strTest)

 var strCheck;
 //strCheck = checkCurrLoc(strCurrPage);

 //alert('Function returned ' + strCheck);

 if (strCheck != -1)
  {
    ///////////top.navbar.location.href = strCheck;
  }
}

function checkCurrLoc(strPage)
{
 var strBoolean
 var currLoc
 currLoc = top.navbar.location.href
 strBoolean = currLoc.indexOf(strPage);

 //alert('Current location ' + currLoc);
 //alert('Looked for ' + strPage + ',\nfound it at ' + strBoolean);

 if (strBoolean == -1 || isMac)
  {
    var strReturn;
    strReturn = navbarRoot + strPage
    return(strReturn);
  }
  else
   {
    return(-1);
   }
 //return(strBoolean);
}
