<!--
/******************************************************************************************************

	GALMENU Version 1.2

How to use galmenu

Files:
    galmenu.js        This file contains javascript code which is not normally customised
                      and is normally included in the target page with a "src" statement.
                
    galmenustyle.js   This file contains the javascript to build the style objects. This file
                      is customised to suit the styles desired.  Any number of style objects
                      can be created.  This file can either be 'inline' in the header section of
                      a page or included with a "src" statement.
                      
    galmenucustom.js  This file contains the javascript to build the menu objects.  This file is 
                      customised to suit the menus required.    Any number of menu objects
                      can be created.  This file can either be 'inline' in the header section of
                      a page or included with a "src" statement.
                      
******************************************************************************************************
	Change History
	Version 1.0		Inital Release
	Version 1.1		Added referenced URL option 'ref:'
	Version 1.2     Added rollover_text_decoration, rollover_font_color, cell_width

******************************************************************************************************/                      
                      
// Check that the browser supports DHTML
var DHTML = (document.getElementById || document.all || document.layers);
if (!DHTML) alert("Sorry, this browser does not support DHTML, menu system will not work");

// Global variables
var galmenu_register = new Array();			// Register of all defined menu and submenu names
var galmenu_build_register = new Array(); 	// Register of all used menu and submenu names
var gal_loaded_menu_register = new Array();	// Lists all loaded menus
var gal_zindex_base = 90;					// Menu z-index, submenus are +1

window.onresize = gal_window_resize; // required for a bug in IE

// create HTML for tooltip
document.write("<div id='galtt' style='position:absolute;visibility:hidden;z-index:99'></div>");

//-----------------------------------------------------------------------------
// Loads a menu into the innerHTML of 'div'
function galLoadMenu(menu, div){
	// menu is the menu object name as a string
	// div is object name as a string.
	if (typeof(menu) != "string"){
		try{
			menu = menu.name;
		}catch(e){
			alert("galmenu ERROR: menu name incorrect");
		}
	}
	gal_register_menu(menu);
	var html = galBuildMenu(menu);

//	dbwin = window.open("about:blank","dbwin");
//	dbwin.document.write(html);

	var elem = new galGetObj(div);
	elem.obj.innerHTML=html;
}

//-----------------------------------------------------------------------------
// write out the html for the menu directly into the document
function galInsertMenu(menu){
	// menu is the menu object name as a string
	if (typeof(menu) != "string"){
		try{
			menu = menu.name;
		}catch(e){
			alert("galmenu ERROR: menu name incorrect");
		}
	}
	gal_register_menu(menu);
	var html = galBuildMenu(menu);
	document.write(html);
	
//	dbwin = window.open("about:blank");
//	dbwin.document.write(html);	
}

//-----------------------------------------------------------------------------
// Prototype for DHTML Micro API
//It's called like this:
//var x = new galGetObj('layername');
function galGetObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

//-----------------------------------------------------------------------------
// Sets background and status message on mousein
// 'which' is object representing table cell
// 'obj' is the menu object
// 'item' is the menu item index
function galin(which,obj,item,e){
    which.style.background=eval(obj.cellstyle).rollover_background_color;
    which.style.textDecoration=eval(obj.cellstyle).rollover_text_decoration;
    which.style.color=eval(obj.cellstyle).rollover_font_color;
    if (obj.submenu[item].length >0) {
    	var div = new galGetObj("gal_" + obj.submenu[item]);
    	var cell = new galGetObj("gal_" + obj.submenu[item] + "_cell");
    	div.style.left = cell.obj.offsetLeft + cell.obj.offsetWidth;    	
    	div.style.top = cell.obj.offsetTop;
    	div.style.visibility = "visible";
    	div.style.display = "block"; // This is required because of a bug in IE
    } else if (!obj.isSubMenu){
    	var tt = new galGetObj('galtt');
    	tt.obj.innerHTML='<div id="galtooltipstyle">'+ obj.tooltip[item] +'</div>';
    	tt.style.left=e.clientX+10;
        tt.style.top=e.clientY+10;
        tt.style.visibility="visible";
    }
    return true;
}

//-----------------------------------------------------------------------------
// Resets background and status message on mouseout
function galout(which,obj,item,e){
    which.style.background=eval(obj.cellstyle).background_color;
    which.style.textDecoration=eval(obj.cellstyle).text_decoration;
    which.style.color=eval(obj.cellstyle).font_color;
	if (obj.submenu[item].length >0) {
    	var div = new galGetObj("gal_" + obj.submenu[item]);
      	div.style.visibility = "hidden";     	
	}
	var tt = new galGetObj('galtt');
    tt.style.visibility="hidden";
    return true;
}

//-----------------------------------------------------------------------------
// Register a loaded menu name
function gal_register_menu(menu){
	for (var i in gal_loaded_menu_register)	{
		if (menu == gal_loaded_menu_register[i]){
			alert("ERROR: galmenu menu '" + menu + "' is loaded more than once");
			return;
		}
	}
	gal_loaded_menu_register.push(menu);
}

//-----------------------------------------------------------------------------
// This function toggles the display of each menu when the window is resized
// This is required because of a bug in IE where tables get screwed up when
//  the window is resized
function gal_window_resize(){
	for (var i in gal_loaded_menu_register)	{
		var elem = new galGetObj("gal_"+gal_loaded_menu_register[i]);
		var disp = elem.style.display;
		elem.style.display="none";
		elem.style.display=disp;
	}
}

//-----------------------------------------------------------------------------
// Constructs and returns the HTML for a menu 
// This is called recusively via galgetMenuCell()
function galBuildMenu(menuObj){
// menuObj is the menu object name as a string

	if (galmenu_HasError(menuObj)) return "";
	
	// make sure we haven't built this menu before
	for (var i in galmenu_build_register)	{
		if (menuObj == galmenu_build_register[i]){
			alert("ERROR: galmenu menu object '" + menuObj + "' is used more than once");
			return "";
		}
	} // end for	
	galmenu_build_register.push(menuObj);	
	
	var style, html, i;
	var obj = eval(menuObj);
	
	with (eval(obj.cellstyle)){
		style = "style=\"" 
				+ "border-width: " + border_width + "; "
				+ "border-style: " + border_style + "; "
				+ "border-color: " + border_color + "; "
				+ "border-collapse: " + border_collapse + "; "
				+ "position:relative;z-index: " + obj.zindex + "; "
				+ "\"";
	} // end with
	
	with (obj){
		html = "<div style=\"position:relative;z-index: " + zindex + "; \"><table " + style + " cellspacing='0' id=\"gal_" + menuObj + "\">";	
    	for (i=0; i<count; i++){
    		html += "<tr>";
    		html += galgetMenuCell(obj,i);
    		html += "</tr>";
    	} // end for
		html += "</table></div>";
	} //end with

	return html;
}

//-----------------------------------------------------------------------------
// Returns the html for a menu cell
function galgetMenuCell(menuObj, item){ 
// menuObj is the actual object not a string
	var style, a_style, html, submenuobj, submenuhtml, cellwidth;
	
    with (eval(menuObj.cellstyle)){
		style = "style=\"" 
				+ "border-width: " + border_width + "; "
				+ "border-style: " + border_style + "; "
				+ "border-color: " + border_color + "; "
				+ "border-collapse: " + border_collapse + "; "
				+ "padding: " + padding + "; "
				+ "background-color: " + background_color + "; "
				+ "cursor: " + cursor + "; "
				+ "font-family: " + font_family + "; "
				+ "font-weight: " + font_weight + "; "
				+ "font-size: " + font_size + "; "
				+ "color: " + font_color + "; "
				+ "text-decoration: " + text_decoration + "; "
				+ "text-align: " + text_align + "; "
				+ "\"";
		cellwidth = cell_width;		
	} //end with
	
	with (menuObj){
		html = "<td nowrap width='"+cellwidth+"' " + style;
		html += " onclick=\"event.cancelBubble=true;gal_onclick('" + name + "',"+ item +")\"";
		//html += " onclick=\"" + url[item] + "\"";
		html += " id=\"gal_" + name + "["+ item +"]" + "_test\"";
		html += " onMouseOver='return galin(this,"
				+ name + ","
				+ item
				+ ",event);' onMouseOut='galout(this,"
				+ name + ","
				+ item
				+ ",event)'";
		html += "><span style=\"position:relative;z-index="+zindex+"\"";

		// put an id on the span if has a submenu
		if (submenu[item].length > 0) 
			html += " id=\"gal_" + submenu[item] + "_cell\"";
			
		html += ">" 

		html += text[item];
		html += "</span>"
		
		// include the submenu if one
		if (submenu[item].length > 0){
			submenuhtml = galBuildMenu(submenu[item]);
			html += "<div style=\"z-index:"+eval(submenu[item]).zindex+"; display: none; position: absolute; visibility: hidden;\""
			         + " id=\"gal_" + submenu[item] + "\">" + submenuhtml + "</div>";
		} // end if submenu
		
		html += "</td>"	;
	} // end with
	return html;
}

//-----------------------------------------------------------------------------
// Function to handle clicks
// If the action is a script function the "url" must start with "javascript:"
function gal_onclick(menu,item){
	var url = eval(menu).url[item];
	if (url.length == 0) return;
	if (url.substr(0,4) == 'ref:'){
    	try{
			var a = new galGetObj(url.substr(4));
    		url = document.getElementById(url.substr(4)).href;
    	}catch(e){
    		alert("galmenu ERROR: '"+url+"' referenced url not found");
    		return;
    	}
	} 
	if (url.substr(0,11) == 'javascript:'){
		eval(url.substr(11));
	} else {
		location.href = url;
	}
}

//-----------------------------------------------------------------------------
// function to check a menu object for errors in the defintions
//  specifically looks for duplicated submenu usage
//  Also defines z-index for submenus first time thru
//   and set the isSubMenu flag
// 'name' is menu object name passed as a string
function galmenu_HasError(name){
	var list = new Array();
	var zindex = gal_zindex_base; 
	return galmenu_CheckObj(list, name, zindex);	
}
// Recursive function
function galmenu_CheckObj(list,name,zindex){
	var item, i;
	var obj = eval(name);
	if (obj.zindex == 0) obj.zindex = zindex; else zindex = obj.zindex;
	// if obj is a submenu
	if (obj.zindex > gal_zindex_base) obj.isSubMenu = true;
	for (item in obj.submenu){
		if (obj.submenu[item].length == 0) continue;
		for (i in list)	{
			if (obj.submenu[item] == list[i]){
				alert("ERROR: galmenu submenu object '" + obj.submenu[item] + "' is referenced more than once");
				return true;
			}
		}
		list.push(obj.submenu[item]);
		if (galmenu_CheckObj(list, obj.submenu[item], zindex+1)) return true;
	}
	return false;
}

//-----------------------------------------------------------------------------
// prototype for menu object
function galmenu(itemcount){
	this.registerName = galmenu_registerName;
	this.count = itemcount;
	this.name = "not defined";
	this.menustyle = "";
	this.cellstyle = "";
	this.zindex = 0;
	this.isSubMenu = false;
	this.url = new Array(itemcount);
	this.text = new Array(itemcount);
	this.tooltip = new Array(itemcount);
	this.submenu = new Array(itemcount);
	for (var i=0;i<itemcount;i++){
    	this.url[i]="";
    	this.text[i]="";
    	this.tooltip[i]="";
    	this.submenu[i]="";
	}
}
function galmenu_registerName(name){
	for (reg in galmenu_register){
		if (galmenu_register[reg] == name) 
			alert("ERROR: galmenu object '" + name + "' is defined more than once");
	}
	this.name = name;
	try{
		objname = eval(name).name;
	}catch (e){
		objname = "";
	}
	if (objname != name) 
			alert("ERROR: galmenu object with name '" + name + "' does not exist");
			
	galmenu_register.push(name);
}

//-----------------------------------------------------------------------------
// Menu style object prototype
function galmenustyle(){
	this.border_width = "1";
	this.border_style = "solid";
	this.border_color = "black";
	this.border_collapse = "collapse";
}

//-----------------------------------------------------------------------------
// Cell style object prototype
function galmenucellstyle(){
	this.border_width = "1";
	this.border_style = "solid";
	this.border_color = "red";
	this.border_collapse = "collapse";
	this.padding = "2px 2px 2px 2px";
	this.background_color = "bisque"; 
	this.cursor = "hand";
	this.font_family = "Arial"; 
	this.font_weight = "bold"; 
	this.font_size = "8pt"; 
	this.font_color = "black"; 
	this.text_decoration = "none";
	this.text_align = "left";
	this.rollover_background_color = "coral";
	this.rollover_text_decoration = "none";
	this.rollover_font_color = "black";
	this.cell_width = "auto";
}

-->