//
// Javascript by Mark Theyer for RevSoft Pty Ltd
//
// (borrowed this code from www.3dkitbuilder.com)
//


// draw the background box with a menu
function init_menu() {

	// menu
	draw_products_menu( "", 30, 30, 158 );
	draw_publications_menu( "", 158, 30, 158 );
	draw_downloads_menu( "", 487, 30, 158 );
}


// draw the background box with a menu
function init_submenu() {

	// menu
	draw_products_menu( "../", 30, 30, 158 );
	draw_publications_menu( "../", 158, 30, 158 );
	draw_downloads_menu( "../", 487, 30, 158 );
}


// show the menu
function show_menu(name,e) {

	var		menu;
	var		left;

	hide_menu();
	//highlight(e);
	//mye  = e;
	left = e.offsetLeft;
	menu = document.all.item(name);
	if ( menu != null ) {
		menu.style.left = left;
		if ( name == "downloads" )
			menu.style.left = left + 490;
		if ( name == "publications" )
			menu.style.left = left + 160;
		menu.style.top  = 132;
		menu.style.display = "block";
	}
}


// hide the menu
function hide_menu() {

	var		menu;

	//if ( mye != null )
	//	normal(mye);
	//mye = null;
	menu = document.all.item("downloads");
	if ( menu != null ) {
		menu.style.display = "none";
	}

	menu = document.all.item("publications");
	if ( menu != null ) {
		menu.style.display = "none";
	}

	menu = document.all.item("products");
	if ( menu != null ) {
		menu.style.display = "none";
	}
}


// draw the menu
function draw_products_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#4284DE";
	hcolor = "#FF0000";

	// menu code
	html = menu_start( "products", x, y, width ) + 
		   menu_title( "Enterprise Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DATAFLOW",		path, "products.php?product=revflw", height, color, hcolor ) +
		   menu_item(  "REV GUARDIAN",		path, "products.php?product=revgrd", height, color, hcolor ) +
		   menu_item(  "REV MESSAGE",		path, "products.php?product=revmsg", height, color, hcolor ) +
		   menu_item(  "REV SCHEDULER",		path, "products.php?product=revsch", height, color, hcolor ) +
		   menu_item(  "REV VIEW",			path, "products.php?product=revvew", height, color, hcolor ) +
		   menu_title( "iSeries Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DISK",			path, "products.php?product=revdsk", height, color, hcolor ) +
		   menu_item(  "REV ZIP",			path, "products.php?product=revzip", height, color, hcolor ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// draw the menu
function draw_publications_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#4284DE";
	hcolor = "#FF0000";

	// menu code
	html = menu_start( "publications", x, y, width ) + 
		   menu_title( "Enterprise Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DATAFLOW",		path, "publications.php?product=flw", height, color, hcolor ) +
		   menu_item(  "REV GUARDIAN",		path, "publications.php?product=grd", height, color, hcolor ) +
		   menu_item(  "REV MESSAGE",		path, "publications.php?product=msg", height, color, hcolor ) +
		   menu_item(  "REV SCHEDULER",		path, "publications.php?product=sch", height, color, hcolor ) +
		   menu_item(  "REV VIEW",			path, "publications.php?product=vew", height, color, hcolor ) +
		   menu_title( "iSeries Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DISK",			path, "publications.php?product=dsk", height, color, hcolor ) +
		   menu_item(  "REV ZIP",			path, "publications.php?product=zip", height, color, hcolor ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// draw the menu
function draw_downloads_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#4284DE";
	hcolor = "#FF0000";

	// menu code
	html = menu_start( "downloads", x, y, width ) + 
		   menu_title( "Enterprise Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DATAFLOW",		path, "downloads.php?product=revflw", height, color, hcolor ) +
		   menu_item(  "REV GUARDIAN",		path, "downloads.php?product=revgrd", height, color, hcolor ) +
		   menu_item(  "REV MESSAGE",		path, "downloads.php?product=revmsg", height, color, hcolor ) +
		   menu_item(  "REV SCHEDULER",		path, "downloads.php?product=revsch", height, color, hcolor ) +
		   menu_item(  "REV VIEW",			path, "downloads.php?product=revvew", height, color, hcolor ) +
		   menu_title( "iSeries Solutions", height, "#216BBD" ) +
		   menu_item(  "REV DISK",			path, "downloads.php?product=revdsk", height, color, hcolor ) +
		   menu_item(  "REV ZIP",			path, "downloads.php?product=revzip", height, color, hcolor ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// draw the menu
function draw_help_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#4284DE";
	hcolor = "#216BBD";

	// menu code
	html = menu_start( "help", x, y, width ) + 
		   menu_title( "About",	height, "#4284DE" ) +
		   menu_item(  "3D Kit Builder",		path, "aboutkit",	height, color, hcolor ) +
		   menu_item(  "System Requirements",	path, "system",		height, color, hcolor ) +
		   menu_item(  "Developer",				path, "aboutus",	height, color, hcolor ) +
		   menu_title( "Retail and Distribution", height, "#216BBD" ) +
		   menu_item(  "Buy from a Retailer",	path, "instore",	height, color, hcolor ) +
		   menu_item(  "Opportunities",			path, "retail",		height, color, hcolor ) +
		   menu_item(  "Register",				path, "register",	height, color, hcolor ) +
		   menu_item(  "Place an Order",		path, "order",		height, color, hcolor ) +
		   menu_item(  "Contact Us",			path, "contact",	height, color, hcolor ) +
		   menu_title( "Help", height, "#216BBD" ) +
		   menu_item(  "Installation Help",		path, "install",	height, color, hcolor ) +
		   menu_item(  "Help and Support",		path, "support",	height, color, hcolor ) +
		   menu_item(  "Site Map",				path, "map",		height, color, hcolor ) +
		   menu_item(  "Links",					path, "links",		height, color, hcolor ) +
		   menu_title( "Exit", height, "#216BBD" ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// start of a menu
function menu_start( name, x, y, width ) {

	var opt;

	opt = "<TABLE id=\"" + name + "\" style=\"display: none; position: absolute; left: " + x + "; top: " + y + 
	"; width: " + width + ";\" cellPadding=0 cellSpacing=0 border=0>" +
	menu_line_x(2);

	return( opt );
}


// end of a menu
function menu_end() {

	var opt = menu_line_x(2) +
		"</TABLE>";

	return( opt );
}


// menu line x
function menu_line_x( size ) {

	var opt = "<TR height=" + size + "><TD bgcolor=216BBD></TD><TD bgcolor=216BBD></TD><TD bgcolor=216BBD></TD></TR>";
	return( opt );
}


// menu line y
function menu_line_y( size ) {

	var opt = "<TD bgcolor=216BBD width=" + size + ">";
	return( opt );
}


// draw a menu item
function menu_item( title, path, name, height, color, hcolor ) {
	
	var opt;

	opt = "<TR height=" + height + "><A HREF=" + path + name + ">" + menu_line_y(2) +
	"<TD style=\"cursor: hand\" bgcolor=\"" + color + "\" onmouseover=menu_highlight(\"" + hcolor + "\") onmouseout=menu_normal(\"" + color + "\")>" +
	"<FONT face=Arial size=2 color=FFFFFF style=\"textDecoration: none; font-weight: bold;\" onmouseover=menu_highlight(\"" + hcolor + "\") onmouseout=menu_normal(\"" + color + "\")>&nbsp" + 
	title +
	"</TD></A>" +  menu_line_y(2) + "</TR>";
	
	//alert( opt );
	return( opt );
}


// draw a menu title
function menu_title( title, height, color ) {
	
	var opt;

	opt = "<TR height=" + height + ">" + menu_line_y(2) +
		"<TD align=center bgcolor=\"" + color + "\">" +
		"<FONT face=Arial size=2 color=FFFFFF style=\"font-weight: bold;\">" + 
		title + 
		"</TD>" +  menu_line_y(2) + "</TR>";
		// + 
		//menu_line_x(2);
	
	return( opt );
}


// swap to the highlighted version of the menu
function menu_highlight( color ) {

	var	element;

	if ( window.event.srcElement.tagName == "TD" ) {
		window.event.srcElement.bgColor = color;
	} else {
		element = window.event.srcElement.parentElement;
		while( element != null && element.tagName != "TD" ) {
			element = element.parentElement;
		}	
		element.bgColor = color;
	}
}


// swap to the normal version of the menu
function menu_normal( color ) {

	var	element;

	if ( window.event.srcElement.tagName == "TD" ) {
		window.event.srcElement.bgColor = color;
	} else {
		element = window.event.srcElement.parentElement;
		while( element != null && element.tagName != "TD" ) {
			element = element.parentElement;
		}	
		element.bgColor = color;
	}
}

