//------------Browser Check ----------------------- 
var browser = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) ||((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )));
var ie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )); 
var ie5 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 5 )); 
var ns4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4 )); 
var ns5 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5 )); 
var mac = (navigator.appVersion.indexOf("Macintosh") != -1);


//---------Get correct style sheet for Mac or PC and Netscape 6----------

	if (mac && ns4){
	document.write('<LINK rel="stylesheet" href="../css/homeMac.css">');
		}else{
		document.write('<LINK rel="stylesheet" href="../css/home.css">');
	}

//---------Pop up window handler ----------

function popUp(myURL,myWidth,myHeight){ 
	opts = "toolbar=no,status=no,location=no,menubar=no,resizable=yes,scrollbars=yes";
	opts += ",height=" +myHeight  + ",width=" +myWidth ;
	popwin = window.open(myURL, "_new", opts);
	popwin.moveTo(20,20); 
} 

//-- call from file within any GPM root level folder
function openGlossary(anchorName){
	popUp("../reference/glossary.html#"+anchorName,450,450);
}
	
//------------Re-position Menus on Resize-------------

var menusLocTop = "77";

function placeMenus(){
	for (i=0; i< menus.length; i++){
		menuCellID = document.getElementById(menus[i].name);
		if (mac & ie4){
			menuCellLeft = menuCellID.parentNode.offsetLeft + menuCellID.offsetLeft-5;
		}else{
			menuCellLeft = menuCellID.parentNode.offsetLeft;
		}
		menuCellTop = menuCellID.style.top + menusLocTop;
		menuID = document.getElementById(menus[i].name+"Menu");
		menuID.style.left = menuCellLeft;
		menuID.style.top = menuCellTop;
	}
}

onresize = placeMenus;




//-----------Global Variables and Init  ---------------------------
var docLoaded = false;
var s=location.search;
var curPageIndex; 
				//----track for next and back arrows

if (location.href.indexOf("shared") != -1){
	var fromSection = s.substring(s.indexOf("fromSect=")+9);
	
	if (s.indexOf("subId")!=-1 && s.indexOf("fromSect") !=-1 ){
		var subId = s.substring(s.indexOf("subId=")+6,s.indexOf("&"));
	}
	
}else{
	if (s.indexOf("subId")!=-1 && s.indexOf("fromSect") !=-1 ){
		var subId = s.substring(s.indexOf("subId=")+6,s.indexOf("&"));
	}else{
		fromSection = "";
		subId = s.substring(s.indexOf("subId=")+6);
	}
}


function init(){
	placeMenus();
	docLoaded = true;
}

//------------Define Menus---------------------------

//------- Links for Hardcoded Nav Elements --------
	
function goTo(whichMenu){
	myMenu = eval(whichMenu);
	link = myMenu.menuItems[0].url;
		
	if (thisSection == whichMenu){
		relPath = "";
	} 
	else if (thisSection == "Home"){
		relPath= whichMenu+"/";
	} 
	else {
		relPath= "../"+whichMenu+"/";
	}
	if (nestedPage!=0){
		for (p=0; p < nestedPage; p++){
			dirsUp += "../";
		}
	}

	fullLink = dirsUp + relPath + link;
	this.location.href = fullLink;
}
	
// ---------Show Page Menu Subs -------
function showHideSubs(whichSubDivIdNum){
	subDivEl = eval(document.getElementById("subs"+whichSubDivIdNum));
	twisteeEl = eval(document.getElementById("twist"+whichSubDivIdNum));
	
	if (twisteeEl.src.indexOf("collapse")!=-1) {
		subDivEl.style.display="none";
		twisteeEl.src="../images/global/expand.gif"
	}else{
		subDivEl.style.display="block";
		twisteeEl.src="../images/global/collapse.gif";
	}
}

//---------- Create Utility Menu ------
function utilityMenu(){
	indent = '&nbsp; ';
	uMenu ='<p align="left"><br/>';
	uMenu += indent+'<a href = "javascript:openGlossary()" class= "navItem">Glossary</a>';
	uMenu +='<br/>';
	uMenu +=indent+'<a href = "../reference/Site_Map.html" class= "navItem">Site Map</a>';
	uMenu +='</p>';
	return uMenu
}

//---------- Create Page Menu ------
function pageMenu(whichMenu){

	var dirsUp ="";
	var startDiv = false;
	var firstLoop = true;
	var subDivIdNum = 0;
	
	if (nestedPage!=0){
		for (p=0;p<nestedPage;p++){
			dirsUp += "../";
		}
	}

	var myMenu ="";
		myMenu +=' <table border="0" cellpadding="0" cellspacing="0" width="100%" class="pageMenu">';
		myMenu +=' <tr> ';
		myMenu +=' <td width="10">&nbsp;</TD> ';
		myMenu +=' <td height="25" width= "100% " valign="top">';
		
		for (m=0; m < whichMenu.menuItems.length; m++){
			var goToShared = false;
			var indent="";
			var cls = "";
			var dirsUp ="";
			
			var labelStr = whichMenu.menuItems[m].label
			var myUrl =	whichMenu.menuItems[m].url;	
			var subParam = 'subId='+subDivIdNum;
			var fromParam =  'fromSect=' + thisSection;
			
			if (myUrl.indexOf("shared") !=-1){
				link = whichMenu.menuItems[m].url;
				goToShared = true;
			}
			else if (myUrl.indexOf("javascript")!=-1){
				link = whichMenu.menuItems[m].url;
			}
			else{
				link = '../'+thisSection+'/'+myUrl;
			}
			
			txt = whichMenu.menuItems[m].label;
			if (thisPage == txt){
					cls = 'Class = "here"';
					curPageIndex = m;
			} 
			else { 
					cls = 'Class = "navItem"'; 
			}
				
			if (whichMenu.menuItems[m].heading == 1){
				if (subDivIdNum == subId && subId !=""){
					twistFileName="collapse.gif";
				}else{
					twistFileName="expand.gif";
				}
				
				twistee = '<img src="../images/global/'+twistFileName+'" id="twist'+subDivIdNum+'" style ="handCursor" border="0" onclick = "showHideSubs('+subDivIdNum +')">';
				
				if (startDiv == false && firstLoop == false){
					myMenu += '</div>';
					
				}
				myMenu += twistee;
				myMenu +='&nbsp;<a href="';
				myMenu += link+'?'+ subParam;
				if (goToShared){
					myMenu += '&'+fromParam;
					
				}
				myMenu += '"'+ cls +'>';
				myMenu += txt+'</a><br>';
				
				firstLoop = false;
				startDiv = true;

			} 
			else if (whichMenu.menuItems[m].heading == 0){
				if (startDiv == false && firstLoop == false){
					myMenu += '</div>';
					
				}
					myMenu +='<a href="'+link +'" '+ cls+'>';
					myMenu += txt+'</a><br>';
			}
		
			else{
				
				if (nestedPage!=0){
					for (p=0; p < nestedPage; p++){
						dirsUp += "../";
					}
				}
				
				
				if (startDiv == true){
					if (subDivIdNum == subId && subId !=""){
						displayStyle ="display:block";
					}else{
						displayStyle ="display:none";
					}
					
					myMenu += '<div  id = "subs'+subDivIdNum+'" style="'+displayStyle+'">';
					startDiv = false;
					++subDivIdNum;
				}
				
				subParam = 'subId='+(subDivIdNum-1);
				link += '?'+ subParam;
				if (goToShared){
					link += '&'+fromParam;
				} 
				fullLink = dirsUp + link;
				myMenu += '&nbsp; &nbsp;<a href="'+fullLink+'" '+ cls+'style="color:993300">';
				myMenu += txt+'</a><br>';
			
				
				
			}
		
		}
	myMenu +='</td>';
	myMenu +=' </tr>';
	myMenu +=' </table>';
	return myMenu

}

//--- Write Footer ------

function nextLink(){
	if (curPageIndex == thisMenu.menuItems.length-1){
		thisLink='<img src="../images/global/spacer.gif" width = "60" align="right">';
	}
	else{
		myUrl = thisMenu.menuItems[curPageIndex+1].url;
		
		if (myUrl.indexOf("shared")== -1){
			link = '../'+thisSection+'/'+myUrl+location.search;
			
		} 
		else {
			if ((location.search.indexOf("subId") !=-1) && (location.search.indexOf("fromSect") !=-1)){
				link = myUrl + location.search; 
			} 
			else if (location.search.indexOf("subId") !=-1 && (location.search.indexOf("fromSect") == -1)){
				link = myUrl+ location.search+'&fromSect=' + thisSection; 
			}
			else if (location.search ==""){
				link = myUrl+ location.search+'?fromSect=' + thisSection; 
			} 
			else {
				link = myUrl + location.search;
			}
		}
		
		title = thisMenu.menuItems[curPageIndex+1].label;
		thisLink = '<a href ="'+ link;
		thisLink += '" title ="'+ title+'">';
		thisLink += '<img src="../images/global/next.gif" border = "0" align="right">';
		thisLink += '</a>';
	}
	return thisLink;
}

function backLink(){
	if (curPageIndex == 0){
		thisLink="";
	}
	else{
		myUrl = thisMenu.menuItems[curPageIndex-1].url;
		if (myUrl.indexOf("shared") == -1){
			link = '../'+thisSection+'/'+myUrl+location.search;
		}
		else {
			if ((location.search.indexOf("subId") !=-1) && (location.search.indexOf("fromSect") !=-1)){
				link = myUrl + location.search; 
			} 
			else if (location.search.indexOf("subId") !=-1 && (location.search.indexOf("fromSect") == -1)){
				link = myUrl+ location.search+'&fromSect=' + thisSection; 
			} 
			else if (location.search ==""){
				link = myUrl+ location.search+'?fromSect=' + thisSection; 
			} 
			else {
				link = myUrl + location.search;
			}
		}
		
		title = thisMenu.menuItems[curPageIndex-1].label;
		thisLink = '<a href ="'+ link;
		thisLink += '" title ="'+ title+'">';
		thisLink += '<img src="../images/global/back.gif" border = "0" align="right">';
		thisLink += '</a>';
	}
	return thisLink;
}

function copyright(){ 
	copyright ='<br><span class="smallfont">TransWestern&#174;Publishing. Confidential - for Internal Use Only</span>';
return copyright;
}

function footer(){
	foot = '<p align = "center">';
	foot += nextLink();
	if (nextLink() != '<img src="../images/global/spacer.gif" width = "60" align="right">' && backLink() != ""){
		foot += '<img src="../images/global/b-n_divider.gif" align="right">';
	}
	foot += backLink();
	foot += '<br clear="all"><br>';
	foot += copyright();
	foot +='<br><br></p>';
	return foot;
}
	
//--- Create Header Menus------

function makeMenu(whichMenu,currPath){
	
	if (thisSection == currPath && s.indexOf("shared") != -1){
		relPath = "";

	} 
	else {
		relPath= '../'+currPath+'/';
		document.getElementById(thisSection).parentNode.className = "curMenu";
	}
	myMenu ='<div id="'+whichMenu.name+'Menu" class="navMenu"';
	myMenu += 'onMouseOver = "mouseOnMenu = 1"';
	myMenu += 'onMouseOut = "mouseOnMenu = 0\; timeCloseMenu()"';
	
	if (ie4 && !ie5){
		//myMenu += ' style="width:25"';
	} 
	
	myMenu += '>';
	myMenu +='<table cellspacing = "1" cellpadding="2" border="0"><TR><TD>';
	myMenu +='<p  class="navCell">';
	for (m=0; m < whichMenu.menuItems.length; m++){
		indent="";
		styl = "";
		dirsUp ="";
		labelStr = whichMenu.menuItems[m].label;
		if (whichMenu.menuItems[m].heading == "1" || whichMenu.menuItems[m].heading == "0"){
		
			if (labelStr.indexOf("-")!=-1){
				indent='<span class="navItem">&nbsp; </span>';
			}
			
			if (labelStr.indexOf("*")!=-1){
				indent = '<span class="navItem">&nbsp;&nbsp;&middot;&nbsp;</span>';
			}
					
			link = whichMenu.menuItems[m].url;
			txt = whichMenu.menuItems[m].label;
			
			if (nestedPage!=0){
				for (p=0; p < nestedPage; p++){
					dirsUp += "../";
				}
			}
	
			if (link == "none"){
				fullLink = "javascript:void(0)";
			} 
			else if (link.indexOf("javascript")!=-1){
				fullLink = link;
			} 
			else {
					fullLink = dirsUp + relPath + link; 
			}
			
			
			if (thisSection == currPath &thisPage == txt ){ 
				styl = 'Class = "here"'; 
			} 
			else { 
				styl = 'Class = "navItem"'; 
			}
			
			//myMenu += '<TR><TD nowrap class="navCell">';
			//myMenu += '<p class="navCell">';
			myMenu += indent +'<a href="' + fullLink +' " '+ styl+ '>'+txt+'</a>&nbsp;';
			myMenu += '</br>';
		}
	}
	
	myMenu += '</p></td></tr>';
	myMenu +=  '</table>';
	myMenu +=  '</div>';
	return myMenu;
}

var menubar="";

function menuBars(){
	for (i=0;i<menus.length;i++){
		menubar += makeMenu(eval(menus[i]), menus[i].name);
	}
	return menubar;
}

var mouseOnMenu = 0;
var openMenuID = "";

function timeCloseMenu(){
	if (!docLoaded) return;
	openMenuID = selectedMenuID;
	toggle = setTimeout('closeMenu()',800);
}


function closeMenu(){
	if (!docLoaded) return;
	clearTimeout(toggle);
	if (openMenuID != "" && mouseOnMenu == 0){
		currMenu = document.getElementById(openMenuID);
		currMenu.style.visibility = "hidden";
	}
}


function openMenu(selectedMenuID,linkElem){
	if (!docLoaded) return;
	if (openMenuID != "" && selectedMenuID != openMenuID){ 
		closeMenu();
	}	
	currMenu = document.getElementById(selectedMenuID);
	currMenu.style.visibility = "visible";
	mouseOnMenu = 0;
}
