var isNav,isIE
var coll = ""
var styleObj = ""
if (navigator.appName == "Netscape") {
	isNav = true
	currWidth = innerWidth
	currHeight = innerHeight
	window.captureEvents(Event.RESIZE)
	window.onresize = handleResize
} else {
	isIE = true
	coll = "all."
	styleObj = ".style"
}

function handleResize() {
	if ((innerWidth != currWidth) || (innerHeight != currHeight)) {
		location.reload()
		return false
	}
}

// Set Style Variables
var navColor = "#151597"
var navLightColor = "#0000cd"
var navDarkColor = "#000000"
var menuColor = "#151597"
var itemOnColor = "#C0EEF0"
var itemOffColor = "#151597"
var fontOnColor = "#cccccc"
var fontOffColor = "#E3123F"
var fontFace = "arial"
var fontSize = "10pt"
var semi = ";"
var numberTopLevelMenus = 6


//Set Misc Variables
var done = 0
var currMenuArray
var currItemArray
var currMenu
var currItem
var allNavs = new Array()
var navCoords = new Array()
var navState = 0
var allMenus = new Array()
var iCount
var ciCount
var childCount = 0
var activeItem
var nsGo = 0
var diagOn
    
var newWind
    
function noimageError() 
{
	alert("No image loaded yet. Select Open GIF from the GIFWorks File menu to load an image into GIFWorks.");
}
    

var preloadArrow = new Image();
preloadArrow.src = "/images/menu/arrow.gif";

//Mouse Over Nav Buttons
function navUp() {
	if (navState) {
		if (navState != this) {
			for (var i = 1; i <= numberTopLevelMenus; i++) {
				allNavs[i].off()
			}
		}
		this.down()
	} else {
		if (isNav) {
			this.bgColor = navLightColor
		} else {
			this.style.borderBottomColor = navDarkColor
			this.style.borderRightColor = navDarkColor
			this.style.borderTopColor = navLightColor
			this.style.borderLeftColor = navLightColor
			this.style.padding = 0
		}
	}
}

//Turn Off Nav Buttons
function navOff() {
	this.menu.reveal(1)
	if (isNav) {
		this.bgColor = navColor
	} else {
		this.style.borderBottomColor = navColor
		this.style.borderRightColor = navColor
		this.style.borderTopColor = navColor
		this.style.borderLeftColor = navColor
		this.style.padding = 0
	}
}

//Mouse Out Nav Buttons when menu is on
function navOut() {
	if (!navState) {
		if (isNav) {
			this.bgColor = navColor
		} else {
			this.style.borderBottomColor = navColor
			this.style.borderRightColor = navColor
			this.style.borderTopColor = navColor
			this.style.borderLeftColor = navColor
			this.style.padding = 0
		}
	}
}

//Mouse Over Nav Button when navState is On
function navDown() {
	this.menu.reveal()
	closeNewWind()
	if (isNav) {
		navState = allNavs[this.navNumber]
		allNavs[this.navNumber].bgColor = navDarkColor
	} else {
		navState = this
		this.style.borderBottomColor = navLightColor
		this.style.borderRightColor = navLightColor
		this.style.borderTopColor = navDarkColor
		this.style.borderLeftColor = navDarkColor
		this.style.paddingTop = 1
		this.style.paddingLeft = 1
	}
}

//Mouse Down Nav Buttons
function navClick(which) {
	if (!navState) {
		if (isNav) {
			closeNewWind()
			allNavs[which].menu.reveal()
			navState = allNavs[which]
			allNavs[which].bgColor = navDarkColor
			window.captureEvents(Event.MOUSEDOWN)
			window.onmousedown = clearnavState

		} else {
			closeNewWind()
			this.menu.reveal()
			navState = this
			this.style.borderBottomColor = navLightColor
			this.style.borderRightColor = navLightColor
			this.style.borderTopColor = navDarkColor
			this.style.borderLeftColor = navDarkColor
			this.style.paddingTop = 1
			this.style.paddingLeft = 1
			document.onmousedown = doNothing
			document.onmousemove = doNothing
			document.onmouseup = releaseIt
		}
	}
	return false
}

//Do Nothing Release 
function releaseIt(evt) {
	document.onmousedown = clearnavState
	document.onmouseup = "default"
	document.onmousemove = "default"
}

//Ignore further mousedowns
function doNothing(evt) {
	return false
}

//Ignore further mousedowns
function doNothing2(evt) {
	return false
}

//Hide All Menus and Return All Nav Buttons to Normal
function clearnavState(evt) {
	var e = new Object()
	if (isNav) {
		window.releaseEvents(Event.MOUSEDOWN)
		var aM = navState.menu
		aM.right = aM.left + aM.width
		aM.bottom = aM.top + aM.clip.bottom - 3
		e.x = evt.pageX; e.y = evt.pageY
	} else {
		e.x = event.clientX; e.y = event.clientY
		document.onmousedown = "default"
	}
	for (var i = 1; i <= numberTopLevelMenus; i++) {
		if (((e.x > allNavs[i].x) && (e.x < allNavs[i].r)) && ((e.y > allNavs[i].y) && (e.y < allNavs[i].b))) {
			navState = 0
			allNavs[i].menu.reveal(1)
			allNavs[i].up()
			continue
		}
		allNavs[i].off()
	}
	navState = 0
}

function hiLight() {
	if (isNav) {
		this.item.bgColor = itemOnColor
		activeItem = this.item
		this.captureEvents(Event.MOUSEUP)
		this.onmouseup = goUrl
		if (this.item.hasChild) {
			if (this.item.container.childOn) {
				this.item.container.child.reveal(1)
			}
			this.item.child.reveal()
			this.item.container.childOn = 1
			this.item.container.child = this.item.child
		} else if (this.item.container.childOn) {
			this.item.container.child.reveal(1)
		}		
	} else {
		this.style.backgroundColor = itemOnColor
		if (this.hasChild) {
			if (this.container.childOn) {
				this.container.child.reveal(1)
			}
			this.child.reveal()
			this.container.childOn = 1
			this.container.child = this.child
		} else if (this.container.childOn) {
			this.container.child.reveal(1)
		}
	}		
}

function unLight() {
	if (isNav) {
		this.item.bgColor = itemOffColor
		this.releaseEvents(Event.MOUSEUP)
	} else {
		this.style.backgroundColor = itemOffColor
	}
}

function goUrl() {
	if (isNav) {
		if (this.item.url.length) {
			window.location= this.item.url
		}
	} else {
		if (this.url.length) {
			window.location= this.url
		}
	}
}

function revealIt(state) {
	if (state) {
		if (isNav) {
			this.visibility = "hidden"
			if (this.childOn) {
				this.child.visibility = "hidden"
			}
		} else {
			this.style.visibility = "hidden"
			if (this.childOn) {
				this.child.style.visibility = "hidden"
			}
		}
	} else {
		if (isNav) {
			this.visibility = "visible"
		} else {
			this.style.visibility = "visible"
		}
	}

}

function makeNav(w) {
	this.up = navUp
	this.down = navDown
	this.click = navClick
	this.off = navOff
	this.out = navOut
	this.onmouseover = navUp
	this.onmousedown = navClick
	this.onmouseout = navOut
	if (isNav) {
		this.left = this.x = navX
		this.top = this.y = navY
		this.r = this.x + this.document.width
		this.b = this.y + 24
		this.bgColor = navColor
		this.visibility = "visible"
		this.clip.left = -3
		this.clip.top = -2
		this.clip.bottom = 22
		this.clip.right += 3
	} else {
		this.style.borderStyle = "solid"
		this.style.borderWidth = 2
		this.style.borderColor = navColor
		this.style.pixelLeft = this.x = navX
		this.style.pixelTop = this.y = navY
		this.r = this.x + w
		this.b = this.y + 24
		this.style.backgroundColor = navColor
		this.style.visibility = "visible"
		this.up()
		this.out()
	}
	navX += (w + 10)
}

function makeItem(count) {
	if (isNav) {
		this.bgColor = itemOffColor
		this.visibility = "inherit"
		this.clip.left = -2
		this.clip.top = -2
		this.clip.right = currMenu.width - 3
		this.clip.bottom += 2
		this.container = this.parentLayer
		this.left = 2
		this.top = (count == 1) ? 2 : this.prev.top + this.prev.document.height + 4
	} else {
		this.style.cursor = "default"
		this.style.color = ((this.url || this.hasChild) && this.url.indexOf("nofileError") == -1) ? fontOnColor : fontOffColor
		this.style.backgroundColor = itemOffColor
		this.style.fontFamily = fontFace
		this.style.fontSize = fontSize
		this.style.padding = 2
		this.container = this.offsetParent
		this.onmousedown = goUrl
		this.onmouseover = hiLight
		this.onmouseout = unLight
	}
}

function makeMenu(isChild) {
	this.reveal = revealIt
	if (isNav) {
		this.bgColor = navDarkColor
		this.visibility = "hidden"
		this.top = (isChild) ? this.Parent.container.nav.b + this.Parent.top : this.nav.b + 2
		this.left = (isChild) ? this.Parent.container.nav.x + this.Parent.container.width : this.nav.x
		this.clip.left = -3
		this.clip.top = -3
		this.clip.right = currMenuArray.mwidth + 3
		this.clip.bottom = this.lastItem.top + this.lastItem.document.height + 5
	} else {
		this.style.backgroundColor = itemOffColor
		this.style.visibility = "hidden"
		this.style.top = (isChild) ? (this.Parent.container.nav.b + this.Parent.offsetTop) : this.nav.b
		this.style.left = (isChild) ? (this.Parent.container.nav.x + this.Parent.container.width -2) : this.nav.x
		this.style.borderStyle = "solid"
		this.style.borderWidth = 2
		this.style.borderTopColor = "#EDEDED"
		this.style.borderLeftColor = "#EDEDED"
		this.style.borderRightColor = "#AAAAAA"
		this.style.borderBottomColor = "#AAAAAA"
	}
}

function makeLayer(n,w,wrapper) {
	if (isNav) {
		eval("n = new Layer(w," + wrapper + ")")
	} else {
		divHTML = "<DIV ID=" + n + " STYLE=\"position:absolute \; width:" + w + "\"></DIV>"
		document.body.insertAdjacentHTML("BeforeEnd",divHTML)
	}
	return eval(n)
}

function Navs() {
	for (var i = 1; i <= numberTopLevelMenus; i++) {
		currMenuArray = eval("menu" + i)
		currNav = currMenuArray.Name
		currNav = makeLayer(currMenuArray.Name,currMenuArray.nwidth,"window")
		allNavs[i] = currNav
		var imgString = "<IMG SRC=\"\/images/menu/menu" + i + ".gif\" border=0 width=" + currMenuArray.nwidth + " height=20>"
		if (isNav) {
			imgString = "<A HREF=\"javascript: void doNothing2()\" onclick=\"navClick(" + i + ")\">" + imgString + "</A>"
			currNav.document.write(imgString)
			currNav.document.close()
		} else {
			currNav.innerHTML = imgString
		}
		currNav.make = makeNav
		currNav.make(currMenuArray.nwidth)
		currNav.navNumber = i
	}
}

function NSMenus() {
	for (i = 1; i <= numberTopLevelMenus; i++) {
		currMenuArray = eval("menu" + i)
		currMenu = currMenuArray.Name + "menu"
		currMenu = makeLayer(currMenuArray.Name + "menu", currMenuArray.mwidth,"window")
		allMenus[i] = currMenu
		currMenu.width = currMenuArray.mwidth
		currMenu.make = makeMenu
		currMenu.nav = allNavs[i]
		allNavs[i].menu = currMenu
		iCount = 1
		while (currMenuArray["item" +iCount]) {
			previous = (iCount > 1) ? currItem : null
			currItemArray = eval(currMenuArray["item" + iCount])
			arrowString = (currItemArray.isParent) ? "<IMG SRC=\"/images/menu/arrow.gif\" width=14 height=14 border=0 align=right>" : ""
			currItemName = currMenuArray.Name + "Item" + iCount
			currItem = makeLayer(currItemName,currMenuArray.mwidth,"currMenu")
			currItem.url = currItemArray.url
			currItem.text = "\&nbsp\;\&nbsp\;\&nbsp\;" + currItemArray.itext
			currItem.html = "<SPAN ID=" + currItemName + ">" + arrowString + currItem.text + "</SPAN>"
			var fColor = ((currItemArray.url || currItemArray.isParent) && currItemArray.url.indexOf("nofileError") == -1) ? fontOnColor : fontOffColor
			currItem.html = "<FONT FACE=\"tahoma,arial,helvetica\" SIZE=2 COLOR=\"" + fColor + "\">" + currItem.html + "</FONT>"
			currItem.document.open()
			currItem.document.write(currItem.html)
			currItem.document.close()
			currItem.hasChild = currItemArray.isParent
			currItem.prev = previous
			currItem.make = makeItem
			currItem.make(iCount)
			currItem.cover = makeLayer(currItemName + "cover",currMenuArray.mwidth,"currMenu")
			currItem.cover.item = currItem
			currItem.cover.visibility = "inherit"
			currItem.cover.top = currItem.top
			currItem.cover.left = currItem.left 
			currItem.cover.clip.left = currItem.clip.left
			currItem.cover.clip.top = currItem.clip.top 
			currItem.cover.clip.right = currItem.clip.right
			currItem.cover.clip.bottom  = currItem.clip.bottom
			currItem.cover.onmouseover = hiLight
			currItem.cover.onmouseout = unLight
			if (currItem.hasChild) {
				childCount++
				currItem.child = NSChild(childCount,i)
			}
			iCount++
		}
		childCount = 0
		currMenu.lastItem = currItem
		currMenu.make()
	}			
}

function NSChild(cNumber,mNumber) {
	childMenuArray = eval("menu" + mNumber + "" + cNumber)
	childMenu = makeLayer(childMenuArray.Name,childMenuArray.mwidth,"window")
	childMenu.make = makeMenu
	ciCount = 1
	while (childMenuArray["item" + ciCount]) {
		cprevious = (ciCount > 1) ? childItem : null
		childItemArray = eval(childMenuArray["item" + ciCount])
		childItemName = childMenuArray.Name + "Item" + ciCount
		childItem = makeLayer(childItemName,childMenuArray.mwidth,"childMenu")
		childItem.url = childItemArray.url
		childItem.text = "\&nbsp\;\&nbsp\;\&nbsp\;" + childItemArray.itext
		childItem.html = "<SPAN ID=" + childItemName + ">" + childItem.text + "</SPAN>"
		var cfColor = (childItemArray.url && childItemArray.url.indexOf("nofileError") == -1) ? fontOnColor : fontOffColor
		childItem.html = "<FONT FACE=\"tahoma,arial,helvetica\" SIZE=2 COLOR=\"" + cfColor + "\">" + childItem.html + "</FONT>"
		childItem.document.open()
		childItem.document.write(childItem.html)
		childItem.document.close()
		childItem.prev = cprevious
		childItem.make = makeItem
		childItem.make(ciCount)
			childItem.cover = makeLayer(childItemName + "cover",childMenuArray.mwidth,"childMenu")
			childItem.cover.item = childItem
			childItem.cover.visibility = "inherit"
			childItem.cover.top = childItem.top
			childItem.cover.left = childItem.left 
			childItem.cover.clip.left = childItem.clip.left
			childItem.cover.clip.top = childItem.clip.top 
			childItem.cover.clip.right = childItem.clip.right
			childItem.cover.clip.bottom  = childItem.clip.bottom
			childItem.cover.onmouseover = hiLight
			childItem.cover.onmouseout = unLight
		ciCount++
	}
	childMenu.Parent = currItem
	childMenu.lastItem = childItem
	childMenu.make(1)
	return childMenu
}

function IEMenus() {
	for (i = 1; i <= numberTopLevelMenus; i++) {
		currMenuArray = eval("menu" + i)
		currMenu = currMenuArray.Name + "menu"
		currMenu = makeLayer(currMenuArray.Name + "menu",currMenuArray.mwidth)
		allMenus[i] = currMenu
		currMenu.width = currMenuArray.mwidth
		currMenu.make = makeMenu
		currMenu.nav = allNavs[i]
		allNavs[i].menu = currMenu
		iCount = 1
		var itemHTML = ""
		while (currMenuArray["item" + iCount]) {
			currItemArray = eval(currMenuArray["item" + iCount])
			arrowString = (currItemArray.isParent) ? "<IMG SRC=\"/images/menu/arrow.gif\" width=14 height=14 align=right>" : ""
			currItemName = currMenuArray.Name + "Item" + iCount
			itemString = "<SPAN ID=\"" + currItemName + "\" STYLE=\"width:" + currMenuArray.mwidth + "\">" + arrowString + "\&nbsp\;\&nbsp\;\&nbsp\;" + currItemArray.itext + "</SPAN><BR>"
			itemHTML += itemString
			iCount++
		}
		currMenu.innerHTML += itemHTML
		allItems = currMenu.children.tags("SPAN")
		for (it = 0; it < allItems.length; it++) {
			currItemArray = eval(currMenuArray["item" + (it + 1)])
			currItem = eval(currMenuArray.Name + "Item" + (it + 1))
			currItem.url = currItemArray.url
			currItem.hasChild = currItemArray.isParent
			currItem.make = makeItem
			currItem.make()
			if (currItem.hasChild) {
				childCount++
				currItem.child = IEChild(i,childCount)
			}
		}
		currMenu.make()	
		childCount = 0
	}
}

function IEChild(mNumber,cNumber) {
	childMenuArray = eval("menu" + mNumber + "" + cNumber)
	childMenu = makeLayer(childMenuArray.Name,childMenuArray.mwidth)
	childMenu.make = makeMenu
	ciCount = 1
	var childItemHTML = ""
	while (childMenuArray["item" + ciCount]) {
		childItemArray = eval(childMenuArray["item" + ciCount])
		childItemName = childMenuArray.Name + "Item" + ciCount
		childItemString = "<SPAN ID=\"" + childItemName + "\" STYLE=\"width:" + childMenuArray.mwidth + "\">" + "\&nbsp\;\&nbsp\;" + childItemArray.itext + "</SPAN><BR>"
		childItemHTML += childItemString
		ciCount++
	}
	childMenu.innerHTML = childItemHTML
	allchildItems = childMenu.children.tags("SPAN")
	for (ci = 0; ci < allchildItems.length; ci++) {
		childItemArray = eval(childMenuArray["item" + (ci + 1)])
		childItem = eval(childMenuArray.Name + "Item" + (ci + 1))
		childItem.url = childItemArray.url
		childItem.make = makeItem
		childItem.make()
	}
	childMenu.Parent = currItem
	childMenu.make(1)
	return childMenu
}


function makeNewWindow(theURL,winName,features) {
	if (isNav) {
		features += ",screenX=100,screenY=75"
	} else {
		features += ",left=100,top=75"
	}
	newWind = window.open(theURL,winName,features)
	if (newWind != null && newWind.opener == null) {
		newWind.opener = self
	}

}  

function closeNewWind()	{
	if (newWind && !newWind.closed)	{
		newWind.close()
	}
}
	
var pLeft = 2;
var pTop = 2;
var navX;
var navY;


// Function to initialise a standard page, function create toolbar dropdown menu 
function init() {
	marker = eval("document.images.markerImg");
	if (isIE) {
		myParent = marker.offsetParent;
		while (myParent) {
			pLeft += myParent.offsetLeft;
			pTop += myParent.offsetTop;
			myParent = myParent.offsetParent;
		}
	}
	navX = (isNav) ? marker.x : pLeft
	navY = (isNav) ? marker.y : pTop
	window.focus()
	Navs()
	if (isNav) { NSMenus() } else { IEMenus() }
}

// Function to initialise a standard page, function create toolbar dropdown menu and
// also goes to first field in form.
function finit() {
	marker = eval("document.images.markerImg");
	if (isIE) {
		myParent = marker.offsetParent;
		while (myParent) {
			pLeft += myParent.offsetLeft;
			pTop += myParent.offsetTop;
			myParent = myParent.offsetParent;
		}
	}
	navX = (isNav) ? marker.x : pLeft
	navY = (isNav) ? marker.y : pTop
	window.focus()
	Navs()
	if (isNav) { NSMenus() } else { IEMenus() }
	document.forms[0][0].focus();	
}



// Functions used for context sensitive help

function ShowCSHelp(HelpID,features) {
	if (isNav) {
		features += ",screenX=100,screenY=75,width=400,height=500,scrollbars=yes"
	} else {
		features += ",left=100,top=75,width=400,height=500,scrollbars=yes"
	}
	CSHWind = window.open('/help/csh/contextsenshelp.asp?p_HID='+HelpID,'CSHelp',features)
	if (CSHWind != null && CSHWind.opener == null) {
		CSHWind.opener = self
	}

}


// General create new window routine

function makeNewWindow(theURL,winName,features) {
	if (isNav) {
		features += ",screenX=100,screenY=75"
	} else {
		features += ",left=100,top=75"
	}
	newWind = window.open(theURL,winName,features)
	if (newWind != null && newWind.opener == null) {
		newWind.opener = self
	}

}

// Find a person window

function PersonFind(url){
	mapWin = window.open('person_find_popup.asp' + location.search + '&P_RETURL=' + url, 'personFind' , 'width=400,height=400,toolbar=0,directories=0,menubar=0,status=,resizable=0,location=0,scrollbars=auto,copyhistory=0')
	mapWin.window.focus()
}
