<!--

/*********************************************************************************************************
** pop.js sets up each document with the "drop down" menus that correspond with the "master menu" in the menu frame.
** The 'mouseIn' variable is set to true if a mouseover event occurs in an open menu, and 'mouseIn2' is set to true if a
** mouseover event occurs in a submenu. Setting these to true traps the mouseup event in the trapEvent() function so the
** click does not close the menus when the pointer is inside them.
**
** The buildMenus() function is also invoked as each document loads to insert the menu code. All menu changes are done here
** in code, if any links need to be activated or updated.
**
** While no code is entirely proprietary since we all borrow ideas and snippets, the vast majority of this stuff
** is my own, and therefore copyrighted under Wacko D-Zyne Laboratories in 2002. Of course, if you wish to
** adapt any of it for your own use, there's no problem with that, just pass the favour on! You may contact me
** if you have any questions: Dr. Metropolis, wackolabs@telus.net, or wackolabs@hotmail.com.    ;-)
********************************************************************************************************/




//***** this little beaut checks for the frameset, and if none, finds the default.htm page, loads it, then the page
//***** served gets loaded into the frame! Just in case a page gets linked to directly (search engine) and the menu
//***** page doesn't get loaded. User gets the page they wanted and the navigation. The other half of this process
//***** is in the default page (frameset). The search page is exempt from this treatment.

if (self.window.name != 'main') {
	this.location = path + 'default.htm?' + page;
}


days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

today = new Date();
m = months[today.getMonth()];
dt = today.getDate();
d = days[today.getDay()];
y = today.getYear();
suff = 'xx';
if (dt < 4) suff = (dt == 1) ? 'st' : (dt == 2) ? 'nd' : 'rd';
else suff = (dt == 21 || dt == 31) ? 'st' : (dt == 22) ? 'nd' : (dt == 23) ? 'rd' : 'th';

function putDate() {

today = new Date();
h = today.getHours();
s = today.getSeconds()*1000;

x = 'pm';
if (h == 0) { h = 12; x = 'am';}
else if (h > 12) h = h - 12;
else x = 'am';

min = today.getMinutes();
if (min < 10) min = '0' + min;

str = d + ', ' + m + ' ' + dt + suff + ', ' + h + ':' + min + ' ' + x;

if (ie) document.all['time'].innerHTML = str;
else document.getElementById('time').childNodes[0].nodeValue = str;

setTimeout('putDate();', 60000-s);

} // end putDate


//***** clear the menu variables on page load

var openMenu = new Array('','');
openMenu[0] = '';
openMenu[1] = '';

//***** initialize the mouse 'sensors' and mouseup event handling
mouseIn = false;
mouseIn2 = false;
if (ns) document.captureEvents(Event.MOUSEUP);
document.onmouseup = trapEvent;

//***** initialize variables to be used by checkLoc() - the awesome scrolling doodad (see below)
if (ns) {
	v = ".top=";
	dS = "document.";
	sD = "";
	y = "window.pageYOffset";
	x = "window.pageXOffset";
	w = "window.innerWidth";
}
else if (ns6) {
	v = ".top=";
	dS = "document.getElementById('";
	sD = "').style";
	y = "window.pageYOffset";
	x = "window.pageXOffset";
	w = "window.innerWidth";
}
else if (ie) {
	v = ".pixelTop=";
	dS = "";
	sD = ".style";
	y = "document.body.scrollTop";
	x = "document.body.scrollLeft";
	w = "document.body.clientWidth";
}

//***** doesn't work in NS4, but then so what
top.document.title = document.title;

/************
** shwMenu() is used only to display (make visible) the submenus for menu items with subsections (arrows indicate a subsection).
** The openMenu[] array holds the currently open menu (array 0) and submenu (array 1) ID names. Also used from
** the menu frame is 'xpos', and contains the clientX (pageX) value for the open menu. The ypos variable is a combination of the
** current mouse position, and how far the page has scrolled, so the submenus appear in the same relative place to the menus.
** new edition of the 'edge' variable to display menus going off the edge of the screen to move left accordingly. Oh boy!
************/

function shwMenu(e, m) {

if (!e) e = window.event;
xpos = parent.menu.xpos + ((ns) ? 160 : 155);
if (ie) edge = eval(w) + eval(x);
else edge = eval(w);
if (xpos + 130 > edge) xpos = xpos - ((ns) ? 320:310);
if (ie) ypos = document.body.scrollTop + e.clientY - 12;
else ypos = e.pageY - 12;

if (ie) {
	//***** check first if a submenu is already open, and close it
	if (openMenu[1] != '') document.all(openMenu[1]).style.visibility = 'hidden';

	//***** set the open submenu to the one being opened here
	openMenu[1] = m;

	//***** position the submenu before making it visible
	document.all(m).style.left = xpos;
	document.all(m).style.top = ypos;
	document.all(m).style.visibility = 'visible';
}

else if (ns6) {
	//***** check first if a submenu is already open, and close it
	if (openMenu[1] != '') document.getElementById(openMenu[1]).style.visibility = 'hidden';

	//***** set the open submenu to the one being opened here
	openMenu[1] = m;

	//***** position the submenu before making it visible
	document.getElementById(m).style.left = xpos;
	document.getElementById(m).style.top = ypos;
	document.getElementById(m).style.visibility = 'visible';
}

else if (ns) {
	//***** check first if a submenu is already open, and close it
	if (openMenu[1] != '') document.layers[openMenu[1]].visibility = 'hide';

	//***** set the open submenu to the one being opened here
	openMenu[1] = m;

	//***** position the submenu before making it visible
	document.layers[m].left = xpos;
	document.layers[m].top = ypos;
	document.layers[m].visibility = 'show';
}

} // end



/************
** clsMenu() can be used to close just the submenu (openMenu[1]), just the menu (openMenu[0]) or both.
** The 's' variable is 0 to close both, and 1 to close the submenu. The 'numMenus' variable determines
** whether it has to close both menu and submenu, or just the menu.
************/

function clsMenu(s) {

numMenus = (openMenu[0] == '') ? 0 : (openMenu[1] == '') ? 0 : 1;
for (i = numMenus; i >= s; i--) {
	if (ie) document.all(openMenu[i]).style.visibility = 'hidden';
	else if (ns6) document.getElementById(openMenu[i]).style.visibility = 'hidden';
	else if (ns) document.layers[openMenu[i]].visibility = 'hide';
	openMenu[i] = '';
}

} // end



/************
** trapEvent() checks the mouse 'sensors' to find out if the pointer is still in either the menu or submenu.
** If the pointer is in the menu then 'mouseIn' is true; if the pointer is in the submenu then 'mouseIn2' is
** true. The two conditions check what menu the pointer might be in, and only goes to clsMenu() if the
** openMenu[] array has an ID name, meaning a menu or submenu is open. The 'sensors' work with
** the following startEvent() and stopEvent() functions, that get attached to the pop up menus for mouseovers
** and mouseouts (see the bottom of buildMenus() where the mouse event is attached).
************/

function trapEvent(e) {

if (!mouseIn && !mouseIn2 && openMenu[0] != '') clsMenu(0);
else if (mouseIn && !mouseIn2 && openMenu[1] != '') clsMenu(1);

} // end


// **********
// **********
// **********
// **********
// **********

function startEvent() {

mouseIn = false;

} // end


// **********
// **********
// **********
// **********
// **********

function stopEvent() {

mouseIn = true;

} // end


// **********
// **********
// **********
// **********
// **********

function startEvent2() {

mouseIn2 = false;

} // end


// **********
// **********
// **********
// **********
// **********

function stopEvent2() {

mouseIn2 = true;

} // end




/************
** checkLoc() is on the looking for any scrolling (parts of this were borrowed - thanks!) and resets the
** top position and width the the "cover" div element. The only reason for all this is to provide a band
** of colour at the top of the page so the main content doesn't run into the menu buttons, while still
** allowing the pop up menus to be flush with the menu buttons. A trivial cosmetic effect, but what the heck.
************/



function checkLoc() {


	if (ie) parent.menu.document.body.scrollLeft = document.body.scrollLeft;	//***** scroll the menu frame to match the main frame (x only)
	else parent.menu.window.scrollTo(window.pageXOffset, 0);


	setTimeout("checkLoc()",10);


} // end checkLoc function



/************
** buildMenus() creates all da stuff for the menus. The 'menu' variable has all the info, from titles to links to sublinks
** and the menu names. The properties of 'menu' go like this:
**		name: 	name of the menu
**		child: 	an array of how many children are in the menu; 0=href, 1=sublink, 2=title (titles are simply separators)
**		text:		an array of strings that appear as the href text; sublinks contain their 'title', plus an array of the sublink href text
**		href:		an array of the actual href link from the root of the site; an 'X' at the first position means the link is disabled
** The function variable 'path' is sent from the page in question and allows the menu to properly link through the site
** directory structure, and is in the form of '../../' or however deep the page is in the site.
************/


function buildMenus() {

//***** start initializing the menu object:

var menu = [
	{	//***** Services Menu
		name: 'services',
		child: [0,0,0,1,0,0,0],
		text: [
			"Why Use Us?",
			"Quality Assurance/ Control Programs",
			"Ship Inspection",
			["Non-Destructive Testing", ["General", "Ultrasonic Inspection", "Ultrasonic Thickness Inspection", "Magnetic Particle Inspection", "Liquid Penetrant Inspection", "Eddy Current Inspection"]],
			"Eddy Current and Remote Field Tube Inspection",
			"Air Monitoring",
			"Crane Certification"
		],
		href: [
			"services/why.htm",
			"services/quality_assurance.htm",
			"services/ship_inspection.htm",
			["services/non_destructive.htm", "services/ultrasonic_inspection.htm", "services/ultrasonic_thickness.htm", "services/magnetic_particle.htm", "services/liquid_penetrant.htm", "services/eddy_current.htm"],
			"services/eddy_current.htm",
			"services/air_monitoring.htm",
			"services/crane_certification.htm"
		]
	}

];

//***** finished initializing the menu object

//***** now that we've got all the data, let's initialize the HTML construction variables

var divt = '<div class=dStyle id="';
var divc = '<\/div>';
var table = '<table width=160 border=0 cellspacing=0 cellpadding=4 class=menubox>';
var tablec = '<\/table>';
var NStable = '<table border=2 cellspacing=0 cellpadding=0 bordercolor=#990000><tr><td>';
var NStablec = '<\/td><\/tr><\/table>';
var tr = '<tr>';
var trc = '<\/tr>';
var td_title = '<td class=mnu>';
var td = '<td>';
var tdb = '<td>&nbsp;<\/td>';
var tdc = '<\/td>';
var arrow = '<td width=13 align=right><img id=arrow src="' + path + 'img/arrow.gif" width=5 height=7><\/td>';
var href = new Object;
	href.tag = '<a href="';
	href.subtag = '<a href="#" onclick="shwMenu(event, \'';
	href.end = '">';
	href.c = '<\/a>';
var outputStr = new Array;

//***** construction time
//***** make the first level of menus first

for (divs = 0; divs < menu.length; divs++) {

	childExists = false;													//***** initialize this on the assumption the menu has no children
	outputStr[divs] = divt + menu[divs].name + '">';   						//***** open the div element
	if (ns) outputStr[divs] += NStable;										//***** add single-cell table for border effect in NS4
	outputStr[divs] += table;												//***** start the regular table

	for (cells = 0; cells < menu[divs].child.length; cells++) {	//***** make the first tier of links for this menu

		if (menu[divs].child[cells] == 0) {
			if (menu[divs].href[cells].charAt(0) != 'X')					//***** check if link is disabled by the 'X'
				outputStr[divs] += tr + td + href.tag + path + menu[divs].href[cells] + href.end + menu[divs].text[cells] + href.c + tdc + tdb + trc;
			else
				outputStr[divs] += tr + td + '<span class="mnumem">' + menu[divs].text[cells] + '<\/span>' + tdc + tdb + trc;
		}
		else if (menu[divs].child[cells] == 1) {
			outputStr[divs] += tr + td + href.subtag + menu[divs].name + cells + "')" + href.end + menu[divs].text[cells][0] + href.c + tdc + arrow + trc;
			childExists = true;
		}
		else if (menu[divs].child[cells] == 2)
			outputStr[divs] += tr + td_title + '<b>' + menu[divs].text[cells] + '<\/b>' + tdc + tdb + trc;

	} // end 'cells' for loop

	outputStr[divs] += tablec;													//***** close the regular table
	if (ns) outputStr[divs] += NStablec;										//***** close single-cell table for border effect in NS4
	outputStr[divs] += divc;													//***** close the div element

	//***** any child menus to make?

	if (childExists) {

		for (i = 0; i < menu[divs].child.length; i++) {

			if (menu[divs].child[i] == 1) {

				outputStr[divs] += divt + menu[divs].name + i + '">'; 			//***** open the div element and name it a subset of parent div
				if (ns) outputStr[divs] += NStable;								//***** add single-cell table for border effect in NS4
				outputStr[divs] += table;										//***** start the regular table

				for (cells = 0; cells < menu[divs].text[i][1].length; cells++) {	//***** limit is array length of subtext

					if (menu[divs].href[i][cells].charAt(0) != 'X')					//***** check if link is disabled by the 'X'
						outputStr[divs] += tr + td + href.tag + path + menu[divs].href[i][cells] + href.end + menu[divs].text[i][1][cells] + href.c + tdc + trc;
					else
						outputStr[divs] += tr + td + '<span class="mnumem">' + menu[divs].text[i][1][cells] + '<\/span>' + tdc + trc;

				} // end 'cells' for loop

				outputStr[divs] += tablec;								//***** close the regular table
				if (ns) outputStr[divs] += NStablec;					//***** close single-cell table for border effect in NS4
				outputStr[divs] += divc;								//***** close the div element

			} // end if

		} // end 'i' for loop

	} // end if 'childExists'

	//***** done making the children of current parent menu, spit it all out on the page

	document.write(outputStr[divs]);
//alert(outputStr[divs]);
} // end 'divs' for loop


//***** here's where we attach the mouse events to the 2 kinds of menu; first one is for the child menus (Event2)
//***** and the other the parent menus

if (ie) lyrs = document.all.tags('div');
else if (ns) lyrs = document.layers;
else if (ns6) lyrs = document.getElementsByTagName('div');

for (i = 0; i < lyrs.length; i++) {
	if (parseInt(lyrs[i].id.substr(lyrs[i].id.length - 1)) >= 0) {
		lyrs[i].onmouseover = stopEvent2;
		lyrs[i].onmouseout = startEvent2;
	}
	else if (lyrs[i].id.substr(0, 1) != 'X') {		//***** the 'X' in this case is to exclude any other div elements in the page
		lyrs[i].onmouseover = stopEvent;
		lyrs[i].onmouseout = startEvent;
	}
} // end 'i' for loop



//***** pop in the footer text with emergency "home" link and sitemap link
document.write('<div id="footer" align=center class="mnu"><p><a href="' + path + 'default.htm" target="_top">Home</a>&nbsp;|&nbsp;<a href="' + path + 'sitemap.htm">Sitemap</a>&nbsp;|&nbsp;<a href="' + path + 'contact.htm">Contact Us</a>&nbsp;|&nbsp;<a href="javascript:window.print()">Print this Page</a>&nbsp;|&nbsp;&copy; Copyright 2002 Elander Inspection Ltd.<p></div>');


document.close();		//***** clean up and flush out the cache


} // end buildMenus function







/**********
**
**********/

function pdfWin(f) {

window.open(f, 'PDF', 'width=600,height=450,scrollbars,resizable,menubar=no,status=no,toolbar=no');

} // end pdfWin() function


//*******************************



//-->