/*****************************************************************************
** Copyright (C) 2002, Stephen Gould
**
** FILENAME:	main.js
** AUTHOR:	Stephen Gould
** COMMENCED:	01 May 2002
** MODIFIED:	21 Jan 2003
** DESCRIPTION:	javascript for dymanic menus in web pages for CWC
**
*****************************************************************************/

/* Menu Structure Set Up Variables ******************************************/

var mainMenu = new Array(
	"About Us",
	"Products",
	"Search",
	"Downloads",
	"Contact Us",
	"Jobs@CWC",
	"Site Map"
);

var subMenu = new Array();

subMenu[0] = new Array(
	"1. Water Treatment Division", "aboutus/water.html",
	"2. EMEC Srl", "aboutus/emec.html",
	"3. Wedgewood Analytical (ISI Innovative Sensors Inc.)", "aboutus/wedgewood.html",
	"4. Rhomberg Electronics", "aboutus/electronics.html"
);

subMenu[1] = new Array(
	"1. &nbsp;Accessories & Other Equipment", "products/accessories.html",
	"2. &nbsp;Boiler Blowdown & Condensate Monitoring", "products/boiler_con.html",
	"3. &nbsp;Brominators (BCDMH Feeders)", "products/broms.html",
	"4. &nbsp;Cooling Tower Control & Dosing Systems", "products/ctc&d.html",
	"5. &nbsp;Controllers/Instruments (eg. pH, ORP, TDS, CL2)", "products/c&t.html",
	"6. &nbsp;Corrosion Monitoring & Coupon Holders", "products/ccr.html",
	"7. &nbsp;Data Logging & Remote Monitoring", "products/dl&rm.html",
	"8. &nbsp;DIGICHEM Plus+ Dosing Systems (Internet Based)", "products/ct_bl_i_orp_cl_ph.html",
	"9. &nbsp;Filters (In-line Strainers)","products/filters.html",
	"10. Flow & Level","products/flowlevel.html",
	"11. Handheld/Portable Meters","products/handheld.html",
	"12. Pumps - Air Operated Double Diaphragm Pumps","products/air_op_dd_pumps.html",
	"13. Pumps - EMEC Solenoid Driven Dosing Pumps", "products/cmps.html",
	"14. Pumps - SEKO Peristaltic Dosing Pumps", "products/cmpp.html",
	"15. Pumps - STENNER Peristaltic Dosing Pumps (6.9 bar)", "products/stenner_pumps.html",
	"16. Pumps - ONGA Circulation Pumps","products/ongapumps.html",
	"17. Sensors/Electrodes - pH, ORP & ISE", "products/sensors.html",
	"18. Spare Parts","products/spareparts.html",
	"19. Swimming Pool ORP/Chlorine & pH Control","products/mp_emec_wmphorp.html",
	"20. Water Meters - ARAD Pulse & Non-Pulse", "products/watermeters.html"
);

subMenu[2] = new Array(
	"1. by Keyword", "search/search.html",
	"2. by Product Code", "search/by_product.html"
);

subMenu[3] = new Array(
	"1. &nbsp;Application Notes", "downloads/download_appnotes.html",
	"2. &nbsp;Brochures", "downloads/download_brochures.html",
	"3. &nbsp;Chemical Compatibility Charts", "downloads/download_chemcharts.html",
	"4. &nbsp;Data Sheets", "downloads/download_ds.html",
	"5. &nbsp;Download Instructions", "downloads/download_instructions.html",
	"6. &nbsp;Forms & Certificates", "downloads/download_forms.html",
	"7. &nbsp;Installation Drawings","downloads/download_install.html",
	"8. &nbsp;Instruction Manuals - Current", "downloads/download_ug.html",
	"9. &nbsp;Instruction Manuals - Discontinued", "downloads/download_ug_old.html",
	"10. Price Lists", "downloads/download_pl.html",
	"11. Product Updates", "downloads/download_produpdates.html",
	"12. Software","downloads/download_sw.html",
	"13. Spare Parts","downloads/download_spareparts.html",
	"14. Tips & Troubleshooting","downloads/tips.html"
);

subMenu[4] = new Array(
	"1. Contact Details", "contactus/contactus.html",
	"2. Contact Form", "contactus/contactform.html",
	"3. Meet our Key People", "contactus/staff.html",
	"4. Request Price List","contactus/pricelistrequest.html"
);

subMenu[5] = new Array(
	"1. Positions Vacant", "jobs/jobs.html"
);

subMenu[6] = new Array(
	"1. Site Map", "sitemap/sitemap.html"
);

var subMenuIds = new Array();
k = 0;
for (i = 0; i < mainMenu.length; i++) {
	subMenuIds[i] = new Array();
	for (j = 0; j < subMenu[i].length / 2; j++) {
		subMenuIds[i][j] = k++;
	}
}

/* Display Variables *********************************************************/

/*var inactiveColour = "#c2def2";*/
/*var activeColour = "#ffffcc";*/
var inactiveColour = "#4F94CD";
var inactiveSubColour = "#dcdcdc";
/* active is dark blue */
var activeColour = "#003F87";
/*var menuTextColour="#191970";*/
var menuTextColour="#ffffff";
var SubmenuTextColour="#ffffff";

var menuTop = 55;
var subMenuTop = menuTop + 20;
var menuLeft = 166 + 16;
var menuWidths = 90;
var subMenuWidths = new Array(340, 345, 140, 240, 160, 140,120);
var activeMenu = -1;

/* System Variables **********************************************************/

var stdBrowser = (document.getElementById) ? true : false;

/* Style Sheet ***************************************************************/

var sytleSheet;
styleSheet = "<style type=\"text/css\">\n";

/* menu running along top */
styleSheet += ".menu {position:absolute; font:11px verdana,tahoma, arial, helvetica;" +
		"background-color:" + inactiveColour + "; " +
		"layer-background-color:" + inactiveColour + "; " +
		"border: 1px; border-color:#ffffff; border-style:solid; " +
		"border-left: 0px; cursor: hand; " +
		"top:" + menuTop + "px; padding:2px; font-weight:bold;color:"+menuTextColour+" }\n";

for (i = 0; i < mainMenu.length; i++) {
	styleSheet += "#menu" + i + " {left:" + (menuLeft + i * menuWidths) +
		"px; width:" + menuWidths + "px; ";
	if (i != 0) {
		styleSheet += "border-left: 0px; ";
	}
	styleSheet += "}\n";
}

styleSheet += ".sub {position:absolute; font:11px verdana,tahoma, arial, helvetica;"+
                "font-weight:normal;color:#ffffff;" +
                "background-color:#ffffff; " +
		"layer-background-color:#ffffff; " +
		"border: 1px; border-color:#4F94CD; border-style:solid; " +
		"padding:2px; z-index: 1; visibility:hidden}\n";

/* colour of text in drop down menus*/
styleSheet += ".sub a {color: #ffffff}\n";

for (i = 0; i < subMenuIds.length; i++) {
	for (j = 0; j < subMenuIds[i].length; j++) {
		styleSheet += "#sub" + subMenuIds[i][j] + " {left:" +
			(menuLeft + i * menuWidths - ((i > 0) ? 1 : 0)) +
			"px; width:" + subMenuWidths[i] + "px; " +
			"top:" + (subMenuTop + j * 19) + "px}\n";
	}
}
/* shortext is above 4 quick buttons on top rhs*/
styleSheet += ".shorttext {font:10pt tahoma, arial, helvetica; " +
	"color:\"#003F87\"; display:none };\n";

styleSheet += "</style>\n";

document.write(styleSheet);

/* Functions *****************************************************************/

function DisplayMenu(menuId) {
	var menuDiv;

	activeMenu = menuId;
	for (i = 0; i < mainMenu.length; i++) {

		menuDiv = "<div id=\"menu" + i + "\" class=\"menu\" " +
			"onMouseOver=\"ShowMenu('" + i + "')\" " +
			"onMouseOut=\"HideMenu('" + i + "')\">" +
			"<img src=\"images/transparent.gif\" width=\"5\" height=\"12\">" +
			mainMenu[i] + "<br>\n" +
			"</div>\n";
		for (j = 0; j < subMenu[i].length; j += 2) {
			menuDiv += "<div id=\"sub" + subMenuIds[i][j / 2] +
				"\" class=\"sub\"" +				
				"onMouseOver=\"ShowMenu('" + i + "', '" + j / 2 + "')\" " +				
				"onMouseOut=\"HideMenu('" + i + "')\">";				
			menuDiv += "<a href='" + subMenu[i][j + 1] + "'>" +
				"&nbsp; " + subMenu[i][j] + "</a><br>\n";
			menuDiv += "</div>\n";
		}
		document.writeln(menuDiv);
	}

	if (activeMenu >= 0) {
		Highlight(activeMenu);
	}
}

function ShowMenu(menuId, subId) {
	var subObj;

	Highlight(menuId);
	for (j = 0; j < subMenuIds[menuId].length; j++) {
		if (stdBrowser) {
			subObj = document.getElementById("sub" + subMenuIds[menuId][j]).style;
		} else if (document.all) {
			subObj = eval("document.all.sub" + subMenuIds[menuId][j] + ".style");
		} else {
			subObj = eval("document.sub" + subMenuIds[menuId][j]);
		}
		subObj.visibility = "visible";
		if (j == subId) {
			subObj.backgroundColor = activeColour;
		} else {
			subObj.backgroundColor = inactiveColour;
		}
	}
}

function HideMenu(menuId) {
	var menuObj, subObj;

	if (menuId != activeMenu) {
		if (stdBrowser) {
			menuObj = document.getElementById("menu" + menuId).style;
		} else if (document.all) {
			menuObj = eval("document.all.menu" + menuId + ".style");
		} else {
			menuObj = eval("document.menu" + menuId);
		}
		menuObj.backgroundColor = inactiveColour;
	}
	for (j = 0; j < subMenuIds[menuId].length; j++) {
		if (stdBrowser) {
			subObj = document.getElementById("sub" + subMenuIds[menuId][j]).style;
		} else if (document.all) {
			subObj = eval("document.all.sub" + subMenuIds[menuId][j] + ".style");
		} else {
			subObj = eval("document.sub" + subMenuIds[menuId][j]);
		}
		subObj.visibility = "hidden";
	}
}

function Highlight(menuId) {
	var menuObj;

	if (menuId < 0)
		return;
	if (stdBrowser) {
		menuObj = document.getElementById("menu" + menuId).style;
	} else if (document.all) {
		menuObj = eval("document.all.menu" + menuId + ".style");
	} else {
		menuObj = eval("document.menu" + menuId);
	}
	menuObj.backgroundColor = activeColour;
}

function SetShortcutText(id, bVisible) {
	var textObjl

	if (stdBrowser) {
		textObj = document.getElementById("shorttext" + id).style;
	} else if (document.all) {
		textObj = eval("document.all.shorttext" + id + ".style");
	} else {
		textObj = eval("document.shorttext" + id);
	}

	if (bVisible) {
		textObj.display = "block";
	} else {
		textObj.display = "none";
	}
}

/* Body Functions ***********************************************************/

function DataSheetActivate(id, bActive) {
	var activeObj;

	if (stdBrowser) {
		activeObj = document.getElementById("datasheet" + id).style;
	} else if (document.all) {
		activeObj = eval("document.all.datasheet" + id + ".style");
	} else {
		activeObj = eval("document.datasheet" + id);
	}
	if (bActive) {
		activeObj.visibility = "visible";
	} else {
		activeObj.visibility = "hidden";
	}
}

/*****************************************************************************
** END OF FILE:	main.js
*****************************************************************************/
