//\//////////////////////////////////////////////////////////////////////////////////
//\  SideManu 
//\  Copyright TAI Engineering 2003. All rights reserved.
//\
//\//////////////////////////////////////////////////////////////////////////////////

// START OF CHANGEABLE VARIABLES
//--------------------------------------------------------
// These variables may be changed to the user's liking

// collapseSideMenu - 0 means don't collapse the side menus, 1 means collapse them
var collapseSideMenu = 0;

// htmlExtension - should be "htm" or "html" depending on the actual files
var htmlExtension = "html";

// sideHeadingClass - css class used for the headings in the side menu
var sideHeadingClass = "SideMenuHeading";

// sideHeadingBgColor - background color for the headings in the side menu
var sideHeadingBgColor = "#31659C";

// sideMenuClass - css class used for the side menu links
var sideMenuClass = "SideMenu";

// sideMenuCurrentClass - css class used to highlight the side link of the html page currently
// being viewed.
var sideMenuCurrentClass = "SideMenuCurrent";

//---------------------------------------------------------
// END OF CHANGEABLE VARIABLES

// Decide browser version
var ns4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4) var docRoot = 'document.body';
var ie5 = false;
if (ns4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function () {if (oW!=window.innerWidth||oH!=window.innerHeight) location.reload();}
}


// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') docRoot = 'document.documentElement';
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

//-----------------------------------------------------
// constructors for handy classes

function menuList(menuText, path, page) {
	this.menuText = menuText;
	this.path = path;
	this.page = page;
}

function menuRecord(menuList, heading) {
	this.menuList = menuList;
	this.heading = heading;
}

////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


//-----------------------------------------------
// dispSideMenu generates the html for the entire side menu of all engineering services
// and industries

function dispSideMenu() {

	
	// This array  holds all the pages that exist at the root directory level, and also show
	// the side menu.  We need to differentiate because the path for the links on the side
	// will be different.
	
	var upOneLevel = new Array;
	var pathPrefix = "../";
	
	// Fill up the array with the filenames
	
	index = 0;
	upOneLevel[index++] = "AboutUs";
	upOneLevel[index++] = "ContactUs";
	upOneLevel[index++] = "Opportunities";
	
	// Get the filename of the html page
	
	href = location.href;
	fileName = href.slice((href.lastIndexOf("/") + 1));

	// Check to see if the html page is at the root directory level.  If it is
	// change the path for the links on the side
	
	for (i = 0; i < upOneLevel.length ; i = i + 1) {
		if ((upOneLevel[i] + "." + htmlExtension) == fileName) {
			pathPrefix = "./";
		}
	}

	//
	// Set up all the information for the engineering services links
	//
	
	var engMenuList = new Array;
	var engServDir = "engServ/";
	var engServHead = "Engineering Services";

	index = 0;
	engMenuList[index++] = new menuList("Process/Chemical Engineering", pathPrefix + engServDir, "ProcessChemEng2");
	engMenuList[index++] = new menuList("Electrical Engineering", pathPrefix + engServDir, "ElectricalEng");
	engMenuList[index++] = new menuList("Civil/Structural Engineering", pathPrefix + engServDir, "CivilStructuralEng");
	engMenuList[index++] = new menuList("Mechanical Engineering", pathPrefix + engServDir, "MechanicalEng");
	engMenuList[index++] = new menuList("Instrumentation & Controls Engineering",pathPrefix + engServDir, "ProcessControl");
	engMenuList[index++] = new menuList("Telecommunications Engineering", pathPrefix + engServDir, "TelecomEng");
	engServices = new menuRecord(engMenuList, engServHead);

	//
	// Set up all the information for the management services links
	//
		
	var mgmtMenuList = new Array;
	var mgmtServDir = "mgmtServ/";
	var mgmtServHead = "Management Services";
	
	index = 0;
	mgmtMenuList[index++] = new menuList("Project Management", pathPrefix + mgmtServDir, "ProjMgmt");
	mgmtMenuList[index++] = new menuList("Construction Management", pathPrefix + mgmtServDir, "ConstructMgmt");
	mgmtMenuList[index++] = new menuList("On-Site Services", pathPrefix + mgmtServDir, "OnSite");
	mgmtMenuList[index++] = new menuList("Design/Build & Turnkey Systems", pathPrefix + mgmtServDir, "DesignBuild");
	mgmtServices = new menuRecord(mgmtMenuList, mgmtServHead);

	//
	// Set up all the information for the technical services links
	//
		
	var techMenuList = new Array;
	var techServDir = "techServ/";
	var techServHead = "Technical Services";
	
	index = 0;
	techMenuList[index++] = new menuList("Inspection & Test Services", pathPrefix + techServDir, "InspectTest");
	techMenuList[index++] = new menuList("Industrial Risk Management", pathPrefix + techServDir, "IndustRisk");
	techMenuList[index++] = new menuList("Instrument Technician Services", pathPrefix + techServDir, "InstrTech");
	techServices = new menuRecord(techMenuList, techServHead);

	//
	// Set up all the information for the industries links
	//
	
	// Generate the html
	//
	
	// First put in a row with two columns, first one 10 pixels wide, second one 141 pixels wide.
	// Both columns are 3 pixels high
	
	tableHtml = "<tr>\n";
	tableHtml += "<td width=\"10\" height=\"3\"></td>\n";
	tableHtml += "<td width=\"141\"></td>\n";
	tableHtml += "</tr>\n";
	
	// Now add the side menus, one at a time
	
	tableHtml += sideMenu(engServices);
	tableHtml += sideMenu(mgmtServices);
	tableHtml += sideMenu(techServices);
	
	return(tableHtml);
}

//-----------------------------------------------
// sideMenu generates the html for one of the services
// or industries

function sideMenu(myMenuRecord) {
	var tableHtml;

	myMenuList = myMenuRecord.menuList;

	inSubMenu = 0;
	href = location.href;
	fileName = href.slice((href.lastIndexOf("/") + 1));
	//fileName = "New.html"
	tableHtml = "<tr> ";
	tableHtml += "<td width=\"10\"></td>\n";
	tableHtml += "<td valign=\"top\" class=\"" + sideMenuClass + "\"><p><br>\n";
	
	for (i = 0; i < myMenuList.length ; i = i + 1) {
		sideFileName = myMenuList[i].page + "." + htmlExtension;
		if (sideFileName == fileName) {
			tableHtml += "<a class=\"" + sideMenuCurrentClass + "\" ";
			tableHtml += "href=\"" + myMenuList[i].path + sideFileName + "\">";
			tableHtml += myMenuList[i].menuText + "</a><br><br>\n" ;
			inSubMenu = 1;
		} else {
			tableHtml +=  "<a class=\"" + sideMenuClass + "\" ";
			tableHtml += "href=\"" + myMenuList[i].path + sideFileName + "\">" + myMenuList[i].menuText + "</a><br><br>\n" ;
		}
	}
	tableHtml += "<br><br><br>";
	tableHtml += "</p></td></tr>\n";
	if (!inSubMenu && collapseSideMenu)
		tableHtml = "<tr><td><br>&nbsp</td></tr>";
		
	link = myMenuList[0].path + myMenuList[0].page + "." + htmlExtension;	
	return(sideHeading(myMenuRecord.heading, link, inSubMenu) + tableHtml);
}

//-----------------------------------------------
// sideHeading generates the html for the heading of one  of the services

function sideHeading(headingText, link, inSubMenu) {
	var tableHtml;
	
	//tableHtml = "<tr valign=\"middle\" bgcolor=\"#31659C\" class=\"SideMenuHeading\"> \n";
	tableHtml = "<tr valign=\"middle\" bgcolor=\"" + sideHeadingBgColor + "\" class=";
	tableHtml += "\"" + sideHeadingClass + "\"> \n";
	tableHtml += "<td height=\"18\" colspan=\"2\">";
	if (!inSubMenu && collapseSideMenu) {
		tableHtml += "<a class=\"" + sideHeadingClass + "\" ";
		tableHtml += "href=\"" + link + "\">";
		tableHtml += headingText + "</a>" ;
	} else {
		tableHtml += "<span class=\"" + sideHeadingClass + "\">";
		tableHtml += headingText;
		tableHtml += "</span>";
	}
	tableHtml += "</td></tr>";
	return(tableHtml);
}


