/*                  WebMenu Version 1.2                 */
/* (c) 2001, Hendrik Förster, Siemens Business Services */
/*           mailto:hendrik.foerster@siemens.com        */
/* **************************************************** */



/* Syntax:
	Menu Container: var menu = new WMCONTAINER("<PARAMETER>");
	Main Menu:      menu.create(new WMMAIN("<NAME>", "<PARAMETER>"));
	Sub Menu:       menu.create(new WMMENU("<NAME>", "<PARENT MENU>", "<PARAMETER>"));
	Menu Item:      menu.create(new WMITEM("<PARENT MENU>", "<PARAMETER>"));
	Seperator:      menu.create(new WMSEPA("<PARENT MENU>", "<PARAMETER>"));
	
	Note: 
		"menu" is a free chosen variable name. You can also take any other name you like.
		<PARAMETER> is a string which describes the properties like caption, action, visibility and
		further more depending on the object type (main, menu, item or separator)
*/

// Customizing:
var webmenu_images;                        // path to the images required for the webmenu
var def_status;                            // default statusbar text
var menu_indicator = true;                 // show the down and right arrow for menus

var auto_open = true;                      // open menus automatically on mouse over
var menu_delay = "400";                    // time after that a menu opens automatically

var screenx = 120;                         // default left
var screeny = 58;                          // default top
var submenu_top = 20;                      // distance to top/screeny
var line_height = 24;                      // height of a menu row
var menu_height = 15;
var def_target = "_self";                  // default target frame/window
var menu_background = 'none';              // background colour of the main menu line
var mainmenu_distance = 4;                 // distance between main menus/items [px]

var highlightMain = new Object;            // describes the style how the main menus/items should appear on mouse over
	highlightMain.backgroundColor = '#516D81';
	highlightMain.cursor = "default";
	highlightMain.borderLeftWidth = "1px";
	highlightMain.borderLeftStyle = "solid";
	highlightMain.borderLeftColor = "#8888FF";
	highlightMain.borderTopWidth = "1px";
	highlightMain.borderTopStyle = "solid";
	highlightMain.borderTopColor = "#8888FF";
	highlightMain.borderRightWidth = "1px";
	highlightMain.borderRightStyle = "solid";
	highlightMain.borderRightColor = "#5555FF";
	highlightMain.borderBottomWidth = "1px";
	highlightMain.borderBottomStyle = "solid";
	highlightMain.borderBottomColor = "#5555FF";

var highlightMainText = new Object;        // describes the style how the caption of main menus/items should appear on mouse over
	highlightMainText.color = '#FFFFFF';

var highlightMenu = new Object;            // describes the style how the submenus/items should appear on mouse over
	highlightMenu.backgroundColor = '#ADBDD6';
	highlightMenu.cursor = "default";

var highlightMenuText = new Object;        // describes the style how the caption of submenus/items should appear on mouse over
	highlightMenuText.color = '#FFFFFF';
	highlightMenuText.textIndent = '3px';

if(parent.logo) {
	if(parent.logo.document.info) {
		webmenu_images = '/ec_web/'+parent.myrelease+'/images/webmenu';
		def_status = parent.window.defaultStatus
	}
} else if(parent.parent.logo) {
	if(parent.parent.logo.document.info) {
		webmenu_images = '/ec_web/'+parent.parent.myrelease+'/images/webmenu';
		def_status = parent.parent.window.defaultStatus
	}
} else if(parent.parent.parent.logo) {
	if(parent.parent.parent.logo.document.info) {
		webmenu_images = '/ec_web/'+parent.parent.parent.myrelease+'/images/webmenu';
		def_status = parent.parent.parent.window.defaultStatus;
	}
} else {
	def_status = window.defaultStatus;
}










// -----------------------------------
// do not change anything from here on
var develop  = 0;
var showcode = 1;

var spacer_image        = webmenu_images + '/spacer.gif';                 // spacer image (transparent)
var menu_enabled_image  = webmenu_images + '/arrow_right_enabled.gif';    // menu indicator image
var menu_disabled_image = webmenu_images + '/arrow_right_disabled.gif';   // menu indicator image
var main_enabled_image  = webmenu_images + '/arrow_down_enabled.gif';     // menu indicator image
var main_disabled_image = webmenu_images + '/arrow_down_disabled.gif';    // menu indicator image
var separator_image     = webmenu_images + '/separator.gif';              // separator image on main level

var browser = new Object();
if(navigator.appName.match("Microsoft")) {
	browser.client = "IE";
	ver = navigator.appVersion;
	ver = ver.substring(ver.indexOf("MSIE ") + 5, ver.length);
	ver = ver.substring(0, ver.indexOf(";"));
} else if(navigator.appName.match("Netscape")) {
	browser.client = "NS";
	if(navigator.vendorSub) ver = navigator.vendorSub; // NS 6.X
	else {
		ver = navigator.userAgent;
		ver = ver.substring(ver.indexOf("/") + 1, ver.indexOf(" "));
	}
}
browser.ver = parseFloat(ver);

var layertag        = (browser.client == 'NS' && browser.ver < 5) ? 'layer' : 'div';
var zindex          = 9990;
var webmenu_array   = new Array();
var maxwidth        = 0;
var dontCloseAll    = false;
var actionPerformed = false;
var saveMain        = new Object;
var saveMenu        = new Object;
var saveMainText    = new Object;
var saveMenuText    = new Object;

window.onerror        = null;
self.document.onclick = closeAll;
self.onresize         = handleResize;

// Functions:
function handleResize() {
	maxwidth = getWindowWidth();
	closeAll();
	return false;
}

function getWindowWidth(){
	if(browser.client == "NS") return window.innerWidth;
	else return document.body.clientWidth;
}

function getWindowHeight(){
	if(browser.client == "NS") return window.innerHeight;
	else return document.body.clientHeight;
}

function styleOf(name){
	if(browser.ver >= 5){
		return document.getElementById(name).style;
	} else if(browser.client == "NS" && browser.ver >= 4){
		return eval("document." + name);
	} else if(browser.client == "IE" && browser.ver >= 4){
		return eval("document.all." + name).style;
	}
}

var WEBMENU_CODE;
function webmenu(menu, left, top) {
	maxwidth = getWindowWidth();
	
	if(typeof menu == 'undefined') {
		for(var i = 0; i < webmenu_array.length; i++) {
			webmenu(webmenu_array[i]);
		}
	} else {
		menu.left = (left!=null)?left:menu.left;
		menu.top = (top!=null)?top:menu.top;
		
		if(browser.client == 'NS') ++menu.top;
		
		var webmenu_code = '';
		webmenu_code += generateMenu(menu);
		document.writeln(webmenu_code);
		WEBMENU_CODE = webmenu_code;
		if(develop && showcode) {
			var win=window.open("/webmenu.htm", "wmcode", "resizable, width=850,height=400");
			win.focus();
//			win.document.displayText(webmenu_code);
//			win.document.open("text/html");
//			win.document.write(webmenu_code);
//			win.document.close();
		}
		return webmenu_code;
	}
	return '';
}

function generateMenu(menu) {
	var left = menu.left;
	var code = '';
	var code2 = '';
	var code_s = '';
	var width = 0;
	var icon = '';
	
	code = '\n<!-- MENU TITLE ' + menu.id + ' -->\n';
	if(browser.client!='NS' || browser.ver >= 5) { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" style="position:Absolute; left: ' + left + '; top: ' + menu.top + '; z-index: ' + zindex++ + ';">\n'; }
	else { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" left="' + left + '" top="' + menu.top + '" z-index="' + zindex++ + '">\n'; }
	code += '<p class="' + menu.cssprefix + 'title">' + menu.title + '</p></' + layertag + '>\n\n';
	
	if(menu.title) left += getTextWidth(menu.title);
	
	for(var i = 1; i <= menu.number; i++) {
		if(menu[i].parent_menu == '' && menu[i].visible) {
			width = (menu[i].caption) ? getTextWidth(menu[i].caption) : menu.icon_size;
			icon = (menu[i].icon) ? menu[i].icon : null;
			
			switch(menu[i].type) {
				case "main":
					if(!menu.indicator) {
						icon = '';
						width -= menu.icon_size;
					}
					
					menu[i].width = 0;
					menu[i].left = left;
					
					code2 = '\n<!-- MAIN MENU ' + menu[i].name + ' -->\n';
					if(browser.client!='NS' || browser.ver >= 5) { code2 += '<' + layertag + ' class="' + menu.cssprefix + 'layer" style="position:Absolute; left: ' + left + '; top: ' + menu.top + '; width: ' + width + '; z-index: ' + zindex++ + ';">\n'; }
					else { code2 += '<' + layertag + ' class="' + menu.cssprefix + 'layer" left="' + left + '" top="' + menu.top + '" z-index="' + zindex++ + '">\n'; }
					
					code2 += '<table cellspacing="0" cellpadding="0" border="0"><tr><td height="' + menu.height + 'px"';
					
					code2 += ' onmouseover="';
					code2 += (menu[i].enabled) ? ' saveMain = highlight(this, highlightMain);' : '';
					code2 += (menu[i].enabled && menu.auto_open) ? ' setTO(\'' + menu.id + '\', \'' + menu[i].name + '\');' : '';
					code2 += ' setStatus(\'' + menu[i].description + '\');';
					code2 += ' return true;"';
					
					code2 += ' onmouseout="';
					code2 += (menu[i].enabled) ? ' highlight(this, saveMain);' : '';
					code2 += (menu[i].enabled && menu.auto_open) ? ' clearTO(\'' + menu.id + '\');' : '';
					code2 += ' clearStatus();';
					code2 += ' return true;"';
					
					code2 += ' onclick="';
					code2 += (menu[i].enabled) ? ' dontCloseAll = true; openMenu(\'' + menu.id + '\', \'' + menu[i].name + '\');' : '';
					code2 += ' return true;"';
					
					code2 += '>\n';
					
					code2 += '<table cellspacing="0" cellpadding="0" border="0" width="' + width + '">\n';
					code2 += '<tr>\n<td valign="middle" id="' + menu.cssprefix + menu[i].style;
					code2 += ((menu[i].enabled) ? '" onmouseover="saveText = highlight(this, highlightMainText)" onmouseout="highlight(this, saveText)"' : 'disabled"') + '><nobr>&nbsp;\n';
					code2 += imgTag(icon, menu[i].description, menu.icon_size, menu.icon_size) + menu[i].caption;
					code2 += '</nobr></td>\n</tr>\n</table>\n';
					
					code2 += '</td></tr></table>\n';
					code2 += '</' + layertag + '>\n';
					
					code_s = generateSubmenu(menu, menu[i].name, left, menu.top + menu.submenu_top);
					if(code_s) {
						code += code2
						code += code_s;
						left += width + menu.distance;
					}
					break;
					
				case "item":
					if(!icon) width -= menu.icon_size;
					
					code += '\n<!-- MAIN ITEM -->\n';
					if(browser.client!='NS' || browser.ver >= 5) { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" style="position:Absolute; left: ' + left + '; top: ' + menu.top + '; width: ' + width + '; z-index: ' + zindex++ + ';">\n'; }
					else { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" left="' + left + '" top="' + menu.top + '" z-index="' + zindex++ + '">\n'; }
					
					code += '<table cellspacing="0" cellpadding="0" border="0" width="' + width + 'px"><tr><td height="' + menu.height + 'px"';
					
					code += ' onmouseover="';
					code += (menu[i].enabled) ? ' saveMain = highlight(this, highlightMain);' : '';
					code += (menu.auto_open) ? ' setTO(\'' + menu.id + '\', \'' + menu[i].parent_menu + '\');' : '';
					code += ' setStatus(\'' + menu[i].description + '\');';
					code += ' return true;"';
					
					code += ' onmouseout="';
					code += (menu[i].enabled) ? ' highlight(this, saveMain);' : '';
					code += (menu.auto_open) ? ' clearTO(\'' + menu.id + '\');' : '';
					code += ' clearStatus();';
					code += ' return true;"';
					
					code += ' onclick="';
					code += (menu[i].enabled) ? 'callURL(\'' + menu.id + '\', \'' + i + '\');' : '';
					code += ' return true;"';
					
					code += '>\n';
					
					code += '<table cellspacing="0" cellpadding="0" border="0">\n';
					code += '<tr>\n<td valign="middle" id="' + menu.cssprefix + menu[i].style;
					code += ((menu[i].enabled) ? '" onmouseover="saveText = highlight(this, highlightMainText)" onmouseout="highlight(this, saveText)"' : 'disabled"') + '><nobr>&nbsp;\n';
					code += imgTag(icon, menu[i].description, menu.icon_size, menu.icon_size) + menu[i].caption;
					code += '</nobr></td>\n</tr>\n</table>\n';
					
					code += '</td></tr></table>\n';
					code += '</' + layertag + '>\n';
					
					menu[i].width = width;
					menu[i].left = left;
					left += width + menu.distance;
					break;
					
				case 'sepa':
					code += '\n<!-- MAIN SEPA -->\n';
					if(browser.client!='NS' || browser.ver >= 5) { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" style="position:Absolute; left: ' + left + '; top: ' + menu.top + '; width: ' + width + '; z-index: ' + zindex++ + ';">\n'; }
					else { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" left="' + left + '" top="' + menu.top + '" z-index="' + zindex++ + '">\n'; }
					code += '<table cellspacing="0" cellpadding="0" border="0" width="'+width+'">\n';
					code += '<tr>\n<td valign="middle" id="' + menu.cssprefix + menu[i].style + '"><nobr>';
					code += imgTag(separator_image, '', menu.icon_size, menu.icon_size) + '</nobr>';
					code += '</td>\n</tr>\n</table>\n';
					code += '</' + layertag + '>\n';
					menu[i].width = width;
					menu[i].left = left;
					left += width;
					break;
					
				default:
					break;
			}
		}
	}
	
	width = left-menu.left + 20;
	left = menu.left - 10;
	var top = menu.top - (menu.height - menu.line_height) / 2;
	var menu_bar = '';
	if(typeof menu.background != 'undefined' && menu.background != 'none') {
		if(browser.client!='NS' || browser.ver >= 5) { menu_bar += '<' + layertag + ' class="' + menu.cssprefix + 'layer" style="position:Absolute; background-color:' + menu.background + '; left: ' + left + '; top: ' + top + '; width: ' + width + '; height: "' + menu.height + '"; z-index: 0;">\n'; }
		else { menu_bar += '<' + layertag + ' class="' + menu.cssprefix + 'layer" left="' + left + '" top="' + top + '" width="' + width + '" height="' + menu.height + '" z-index="0" bgcolor="' + menu.background +'">\n'; }
		menu_bar += imgTag(spacer_image, '', '1', menu.height);
		menu_bar += '</' + layertag + '>\n';
	}
	code += menu_bar;
	return code;
}

function generateSubmenu(menu, submenu, left, top, NoC) {
	left = 0;
	// NoC = Number of Cells (for blind table)
	if(typeof NoC == 'undefined') var NoC = 0;
	var code = '';
	var code2 = '';
	var code_t = '';
	var count = 0;
	var width = 0;
	var others = 0;
	var subm = new SUBWM();
	for(var i = 1; i <= menu.number; i++) { // rebuild of the part tree with all entries in 'submenu'
		menu[i].id = i;
		if(menu[i].parent_menu == submenu) {
			subm.create(menu[i]);
			var w = getTextWidth(menu[i].caption);
			if(w > width) width = w;
		}
	}
	
	width += menu.icon_size + 2;  // add here some [pixel] for highlight properties like borderLeft, borderRight, textIndent etc.
	code += '\n<!-- MENU ' + submenu + ' -->\n';
	if(browser.client!='NS' || browser.ver >= 5) { code += '<' + layertag + ' class="' + menu.cssprefix + 'layer" id="' + submenu + '" style="position:Absolute; left: ' + left + '; top: ' + (top + NoC * menu.line_height) + '; width: ' + width + '; visibility: hidden; z-index: ' + zindex++ + ';">\n'; }
	else { code += '<' + layertag + ' id="' +  submenu + '" name="' +  submenu + '" left="' + left + '" top="' + (top + NoC * menu.line_height) + '" visibility="hide" z-index="' + zindex++ + '">\n'; }
	code += '<table cellspacing="0" cellpadding="0" border="1" width="' + width + '">\n';
	code += '  <tr><td><table cellspacing="0" cellpadding="0" border="0" class="' + menu.cssprefix + 'menutable">\n';
	
	for(var i = 1; i <= subm.number; i++) {
		if(subm[i].visible) {
			icon = (subm[i].icon) ? subm[i].icon : spacer_image;
			
			switch(subm[i].type) {
				
				case "menu":
					code2 = '\n<!-- SUB MENU ' + subm[i].name + ' -->\n';
					code2 += '<tr>\n';
					code2 += '  <td valign="middle" height="' + menu.line_height + 'px"';
					
					code2 += ' onmouseover="';
					code2 += (subm[i].enabled) ? ' saveMenu = highlight(this, highlightMenu);' : '';
					code2 += (subm[i].enabled && menu.auto_open) ? ' setTO(\'' + menu.id + '\', \'' + subm[i].name + '\');' : '';
					code2 += ' setStatus(\'' + subm[i].description + '\');';
					code2 += ' return true;"';
					
					code2 += ' onmouseout="';
					code2 += (subm[i].enabled) ? ' highlight(this, saveMenu);' : '';
					code2 += (subm[i].enabled && menu.auto_open) ? ' clearTO(\'' + menu.id + '\');' : '';
					code2 += ' clearStatus();';
					code2 += ' return true;"';
					
					code2 += ' onclick="';
					code2 += (subm[i].enabled) ? ' dontCloseAll = true; openMenu(\'' + menu.id + '\', \'' + subm[i].name + '\');' : '';
					code2 += ' return true;"';
					
					code2 += '>\n';
					
					code2 += '  <table cellspacing="0" cellpadding="0" border="0"><tr>\n';
					code2 += '    <td width="1px">' + imgTag(spacer_image,"","1",menu.line_height) + '</td>\n';
					code2 += '    <td width="' + width + 'px" align="left" valign="middle" id="' + menu.cssprefix + subm[i].style;
					code2 += ((subm[i].enabled) ? '" onmouseover="saveText = highlight(this, highlightMenuText)" onmouseout="highlight(this, saveText)"' : 'disabled"') + '><nobr>';
					code2 += '&nbsp;' + imgTag(icon, subm[i].description, subm.icon_size, subm.icon_size) + subm[i].caption + '</nobr></td>\n';
					code2 += '  <td align="right" valign="middle">';
					code2 += ((menu.indicator) ? imgTag(((subm[i].enabled) ? menu_enabled_image : menu_disabled_image), subm[i].description) : '&nbsp;');
					code2 += '  </td>\n';
					code2 += '  </tr></table>\n';
					
					code2 += '  </td>\n';
					code2 += '</tr>\n';
					
					code_t += generateSubmenu(menu, subm[i].name, left + width - 1.5, top, (NoC + i - 1 - others));
					if(code_t) code += code2;
					break;
					
				case "item":
					code += '\n<!-- MENU ITEM -->\n';

					code += '<tr>\n';
					code += '  <td valign="middle" height="' + menu.line_height + 'px"';
					
					code += ' onmouseover="';
					code += (subm[i].enabled) ? ' saveItem = highlight(this, highlightMenu);' : '';
					code += (subm[i].enabled && menu.auto_open) ? ' setTO(\'' + menu.id + '\', \'' + subm[i].parent_menu + '\');' : '';
					code += ' setStatus(\'' + subm[i].description + '\');';
					code += ' return true;"';
					
					code += ' onmouseout="';
					code += (subm[i].enabled) ? ' highlight(this, saveItem);' : '';
					code += (subm[i].enabled && menu.auto_open) ? ' clearTO(\'' + menu.id + '\');' : '';
					code += ' clearStatus();';
					code += ' return true;"';
					
					code += ' onclick="';
					code += (subm[i].enabled) ? ' callURL(\'' + menu.id + '\', \'' + subm[i].id + '\');' : '';
					code += ' return true;"';
					
					code += '>\n';
					
					code += '  <table cellspacing="0" cellpadding="0" border="0"><tr>';
					code += '  <td width="1px">' + imgTag(spacer_image,"","1",menu.line_height) + '</td>\n';
					code += '  <td width="' + width + 'px" align="left" valign="middle" id="' + menu.cssprefix + subm[i].style;
					code += ((subm[i].enabled) ? '" onmouseover="saveText = highlight(this, highlightMenuText)" onmouseout="highlight(this, saveText)"' : 'disabled"') + '><nobr>\n';
					code += '&nbsp;' + imgTag(icon, subm[i].description, subm.icon_size, subm.icon_size) + subm[i].caption + '</nobr></td>\n';
					code += '    <td align="right" valign="middle">&nbsp;</td>\n';
					code += '  </tr></table>\n';
					
					code += '</td></tr>\n';

					count++;
					break;
					
				case "sepa":
					code += '\n<!-- MENU SEPA -->\n';
					var sepa_width = (width > 15) ? width - 15 : width;
					code += '<tr height="' + menu.line_height + 'px">\n';
//					code += '  <td width="1px">' + imgTag(spacer_image,"","1",menu.line_height) + '</td>\n';
					code += '  <td align="center" id="' + menu.cssprefix + menu[i].style + '">\n';
					code += '    <hr width="' + sepa_width + 'px" size="1px">\n';
					code += '  </td>\n';
					code += '</tr>\n';
					break;
					
				default:
					++others;
					break;
			}
			subm[i].width = width;
			subm[i].left = left;
		} else { ++others; }
		
	}
	code += '</table>\n';
	code += '  </td></tr>\n';
	code += '</table>\n';
	code += '</' + layertag + '>\n';
	code += code_t;
	return((count || code_t) ? code : '');
}

function highlight(LinkObject, HighObject) {
	var save = new Object;
	for(var prop in HighObject) {
		save[prop] = LinkObject.style[prop];
		LinkObject.style[prop] = HighObject[prop];
	}
	return save;
}

function callURL(id, element) {
	menu = webmenu_array[id];
	if(menu[element].type != "item" || actionPerformed) return;
	
	dontCloseAll = false;
	actionPerformed = true;
	setTimeout("actionPerformed = false", 5000);
	closeAll();
	
	if(menu[element].url.match(/javascript:/i)) eval(menu[element].url);
	else location.href = menu[element].url;
}

function openMenu(wm_id, name) {
	if(typeof name == 'undefined') { alert('openMenu: illegal function call (name is NULL)'); return false; }
	var menu = webmenu_array[wm_id];
	
	setClosed(wm_id);
	setOpened(wm_id, name);
	
	for(var i = 1; i <= menu.number; i++) {
		if((menu[i].type == 'main') || (menu[i].type == 'menu')) {
			var name = menu[i].name;
			if(menu[i].visible) {
				if(menu[i].opened == 0) {
					hideLayer(name);
				} else {
					var parentid = getParent(menu, i);
					var children = new Array();
					children = getChildren(menu, i);
					if(children.length) {
						var left;
						if(menu[i].type == "main") left = menu[i].left;
						else {
							left = menu[parentid].left + menu[i].width;
							if((left + menu[children[0]].width) > maxwidth) {
								left = menu[parentid].left - menu[children[0]].width;
							}
							menu[i].left = left;
						}
						styleOf(name).left = left;
					}
					showLayer(name);
				}
			}
		}
	}
}

function setOpened(id, name) {
	var menu = webmenu_array[id];
	for(var i = 1; i <= menu.number; i++) {
		if(((menu[i].type == 'main') || (menu[i].type == 'menu')) && (menu[i].name == name && menu[i].visible)) {
			menu[i].opened = 1;
			if(menu[i].type == 'menu') setOpened(id, menu[i].parent_menu);
		}
	}
}

function setClosed(id) {
	for(var i = 0; i < webmenu_array.length; i++) {
		if(i != id) closeAll(i);
	}
	
	var menu = webmenu_array[id];
	for(var i = 1; i <= menu.number; i++) {
		if(menu[i].type == 'main' || menu[i].type == 'menu') {
			if(menu[i].opened) {
				menu[i].opened = 0;
			}
		}
	}
}

function closeAll(id) {
	if(dontCloseAll) { dontCloseAll = false; return; }
	
	if(typeof id == 'undefined') {
		for(var i = 0; i < webmenu_array.length; i++) {
			closeAll(i);
		}
	} else {
		var menu = webmenu_array[id];
		if(typeof menu != 'undefined') for(var i = 1; i <= menu.number; i++) {
			if(menu[i].type == 'main' || menu[i].type == 'menu') {
				if(menu[i].opened && menu[i].visible) {
					hideLayer(menu[i].name);
					menu[i].opened = 0;
				}
			}
		}
	}
}

function setTO(id, name) {
	menu = webmenu_array[id];
	
	if(typeof name == 'undefined') return '';
	if(typeof menu.delay == 'undefined') return '';
	if(typeof menu.TO != 'undefined') { clearTimeout(menu); }
	menu.TO = setTimeout('openMenu(\'' + menu.id + '\',\'' + name + '\');', menu.delay);
}

function clearTO(id) {
	menu = webmenu_array[id];
	if(typeof menu.TO != 'undefined') clearTimeout(menu.TO);
}

function showLayer(name) {
	if(typeof name == 'undefined') return '';
	
	if(browser.ver >= 5){
		if(document.getElementById(name)) document.getElementById(name).style.visibility = "visible";
	} else if(browser.client == "NS" && browser.ver >= 4){
		if(eval("document." + name)) eval("document." + name).visibility = "show";
	} else if(browser.client == "IE" && browser.ver >= 4){
		if(eval("document.all." + name)) eval("document.all." + name).style.visibility = "visible";
	}
}

function hideLayer(name) {
	if(typeof name == 'undefined') return '';
	
	if(browser.ver >= 5){
		if(document.getElementById(name)) document.getElementById(name).style.visibility = "hidden";
	} else if(browser.client == "NS" && browser.ver >= 4){
		if(eval("document." + name)) eval("document." + name).visibility = "hide";
	} else if(browser.client == "IE" && browser.ver >= 4){
		if(eval("document.all." + name)) eval("document.all." + name).style.visibility = "hidden";
	}
}

function setStatus(text) {
	top.defaultStatus = text;
	top.status = text;
	return true;
}

function clearStatus() {
	top.defaultStatus = def_status;
	top.status = def_status;
	return true;
}

function getParent(menu, childid) {
	if(typeof menu == 'undefined' || typeof childid == 'undefined') return false;
	if(!(menu[childid].parent)) {
		for(var i = 1; i <= menu.number; i++) {
			if(menu[i].name == menu[childid].parent_menu)
				menu[childid].parent = i;
		}
	}
	return menu[childid].parent;
}

function getChildren(menu, parentid) {
	if(typeof menu == 'undefined' || typeof parentid == 'undefined') return false;
	if(!(menu[parentid].children)) {
		menu[parentid].children = new Array();
		for(var i = 1; i <= menu.number; i++) {
			if(menu[i].parent_menu == menu[parentid].name)
				menu[parentid].children[menu[parentid].children.length] = i;
		}
	}
	return menu[parentid].children;
}






function getTextWidth(caption) {
	if(typeof caption == 'undefined' || caption.length == 0) { return 0; } 
	caption = caption.replace(/&\w*;|&#\d{1,3};/g, " "); // replaces &auml;, &ouml;, &#123; etc. by blank
	
	var tmp = caption.match(/f|i|I|j|l|t|'/g);
	var narrow = (tmp) ? tmp.length : 0;
	
	tmp = caption.match(/A|B|C|D|E|F|G|H|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z/g);
	var wide = (tmp) ? tmp.length : 0;
	
	var medium = caption.length - narrow - wide;
	
//	font-size: 9/10pt
//	return ((wide * 11) + (middle * 7) + (narrow * 2) + 30);
//	font-size: 8pt
	return ((wide * 10) + (medium * 6) + (narrow * 2) + 30);
}

// Standard Tags
function imgTag(url, status, width, height, onmouseover, onmouseout) {
	if(url == null || url == '') { return ''; }
	if(status == null) { status = ""; }
	if(typeof width == 'undefined' || width <= 0) { width = 16; }
	if(typeof height == 'undefined' || height <= 0) { height = 16; }
	if(onmouseover == null) { onmouseover = ""; }
	if(onmouseout == null) { onmouseout = ""; }
	
	var ret_code = '<img src="'+url+'" alt="' + status + '"';
	ret_code += ' width="' + width + 'px" height="' + height + 'px" align="top" border="0"';
	ret_code += ' onMouseOver="setStatus(\'' + status + '\'); ' + onmouseover + '; return true;"';
	ret_code += ' onMouseOut="clearStatus(); ' + onmouseout + '; return true;"';
	ret_code += '>' + '&nbsp;';
	
	return ret_code;
}




// Objects:
function WMCONTAINER(p, no_id) {
	this.number = 0;
	this.create = NEW_OBJECT;
	if(no_id != "NO ID") {
		var obj = new PARAMETERS(p);
		if(obj) {
			this.left = obj.left;
			this.top = obj.top;
			this.icon_size = obj.icon_size;
			this.delay = obj.delay;
			this.auto_open = obj.auto_open;
			this.def_target = obj.def_target;
			this.height = obj.menu_height;
			this.line_height = obj.line_height;
			this.distance = obj.distance;
			this.indicator = obj.indicator;
			this.background = obj.background;
			this.submenu_top = obj.submenu_top;
			this.cssprefix = obj.cssprefix;
			this.title = obj.title;
			
			this.TO = null;
			this.id = (webmenu_array.length);
			webmenu_array[this.id] = this;
		}
	}
	return this;
}
function SUBWM() {
	return new WMCONTAINER(null, "NO ID");
}

function WMMAIN(name,p) {
	if(typeof name == 'undefined') return false;
	
	var obj = new PARAMETERS(p);
	if(obj) {
		this.type = "main";
		this.name = name;
		this.parent_menu = '';
		this.caption = obj.caption;
		this.icon = (obj.icon)?obj.icon:(obj.enabled)?main_enabled_image:main_disabled_image;
		this.description = (obj.description)?obj.description:obj.caption;
		this.opened = 0;
		this.visible = obj.visible;
		this.enabled = obj.enabled;
		this.style = (obj.style)?obj.style:"mainmenu";
		this.left = 0;
		this.width = 0;
		this.id = 0;
		this.parent = 0;
	//	this.children = new Array(); /**** will be generated during runtime ****/
		return this;
	} else {
		return false;
	}
}

function WMMENU(name,parent_menu,p) {
	if(typeof name == 'undefined') return false;
	if(typeof parent_menu == 'undefined') return false;
	
	var obj = new PARAMETERS(p);
	if(obj) {
		this.type = "menu";
		this.name = name;
		this.parent_menu = parent_menu;
		this.caption = obj.caption;
		this.icon = obj.icon;
		this.description = (obj.description)?obj.description:obj.caption;
		this.opened = 0;
		this.visible = obj.visible;
		this.enabled = obj.enabled;
		this.style = (obj.style)?obj.style:"menu";
		this.left = 0;
		this.width = 0;
		this.id = 0;
		this.parent = 0;
	//	this.children = new Array(); /**** will be generated during runtime ****/
		return this; 
	} else {
		return false;
	}
}

function WMITEM(parent_menu,p) {
	if(typeof parent_menu == 'undefined') parent_menu = '';
	
	var obj = new PARAMETERS(p);
	if(obj) {
		this.type = "item";
		this.name = '';
		this.parent_menu = parent_menu;
		this.caption = obj.caption;
		this.url = obj.url;
		this.target = obj.target;
		this.icon = obj.icon;
		this.description = (obj.description)?obj.description:obj.caption;
		this.visible = obj.visible;
		this.enabled = (obj.url == "#")?false:obj.enabled;
		this.style = (obj.style)?obj.style:(parent_menu)?"item":"mainitem";
		this.left = 0;
		this.width = 0;
		this.id = 0;
		this.parent = 0;
		return this;
	} else {
		return false;
	}
}

function WMSEPA(parent_menu,p) {
	if(typeof parent_menu == 'undefined') parent_menu = '';
	
	var obj = new PARAMETERS(p);
	if(obj) {
		this.type = "sepa";
		this.parent_menu = parent_menu;
		this.visible = obj.visible;
		this.style = (obj.style)?obj.style:(parent_menu)?"sepa":"mainsepa";
		this.left = 0;
		this.width = 0;
		this.id = 0;
		this.parent = 0;
		return this;
	} else {
		return false;
	}
}

/* Object functions */
function NEW_OBJECT(object) {
	this[++this.number]=object;
}

function PARAMETERS(p) {
	var pa = new Array();
	if(p) pa = splitString(p, ";");
	
	var obj = new Object;
	obj.caption = "";
	obj.description = "";
	obj.enabled = true;
	obj.visible = true;
	obj.style = "";
	obj.icon = "";
	obj.target = def_target;
	obj.url = "#";
	obj.left = screenx;
	obj.top = screeny;
	obj.icon_size = 16;
	obj.delay = menu_delay;
	obj.auto_open = auto_open;
	obj.def_target = def_target;
	obj.menu_height = menu_height;
	obj.line_height = line_height;
	obj.distance = mainmenu_distance;
	obj.indicator = menu_indicator;
	obj.background = menu_background;
	obj.submenu_top = submenu_top;
	obj.cssprefix = "wm";
	obj.title = "";
	
	if(p) for(var i=0; i<pa.length; i++) {
		var k = (pa[i].match(/=/))?pa[i].substring(0, pa[i].indexOf("=")):pa[i];             /* key */
		var v = (pa[i].match(/=/))?pa[i].substring(pa[i].indexOf("=") + 1, pa[i].length):""; /* value */
		k = k.replace(/^\s*/, ''); k = k.replace(/\s*$/, '');  /* delete leading and terminating whitespaces in k*/
		v = v.replace(/^\s*/, ''); v = v.replace(/\s*$/, '');  /* delete leading and terminating whitespaces in v*/
		v = v.replace(/^'/, ''); v = v.replace(/'$/, '');      /* delete leading and terminating single quotes in v */
		v = v.replace(/^"/, ''); v = v.replace(/"$/, '');      /* delete leading and terminating double quotes in v */
		if(k || v) switch(k.toUpperCase()) {
			case "CAPTION":
				v = v.replace(/'/g, '&#146;');
				obj.caption = v;
				break;
			case "STATUS":
			case "DESCRIPTION":
				v = v.replace(/'/g, '&#146;');
				obj.description = v;
				break;
			case "VISIBLE":
				obj.visible = (v==1 || v=='true' || v=='')?true:false;
				break;
			case "HIDDEN":
				obj.visible = (v==1 || v=='true' || v=='')?false:true;
				break;
			case "ENABLED":
				obj.enabled = (v==1 || v=='true' || v=='')?true:false;
				break;
			case "DISABLED":
				obj.enabled = (v==1 || v=='true' || v=='')?false:true;
				break;
			case "CSSID":
			case "STYLE":
				obj.style = v;
				break;
			case "URL":
			case "ACTION":
				v = v.replace(/^js:/gi, "javascript:");
				if(v) obj.url = v;
				break;
			case "TARGET":
				if(v) obj.target = v;
				break;
			case "ICON":
			case "IMAGE":
				obj.icon = v;
				break;
			case "LEFT":
				obj.left = parseInt(v);
				break;
			case "TOP":
				obj.top = parseInt(v);
				break;
			case "ICONSIZE":
				obj.icon_size = parseInt(v);
				break;
			case "DELAY":
				obj.delay = parseInt(v);
				break;
			case "AUTOOPEN":
				obj.auto_open = (v == 'true')?1:(v == 'false')?0:parseInt(v);
				break;
			case "HEIGHT":
				obj.menu_height = parseInt(v);
				break;
			case "LINEHEIGHT":
				obj.line_height = parseInt(v);
				break;
			case "MENUINDICATOR":
				obj.indicator = (v == 'true')?1:(v == 'false')?0:parseInt(v);
				break;
			case "BACKGROUND":
			case "BGCOLOR":
				obj.background = v;
				break;
			case "SUBMENUTOP":
				obj.submenu_top = parseInt(v);
				break;
			case "CSSPREFIX":
				obj.cssprefix = v;
				break;
			case "TITLE":
				obj.title = v;
				break;
			default:
				alert("WebMenu error: unknown parameter '" + k + "'.");
				return false;
				break;
		}
	}
	return obj;
}

function splitString(parameter, separator) {
	var aParam = new Array();
	var temp = "";
	var charAtI = "";
	var sepChar = separator.charAt(0);
	
	var i = 0;
	var ignoreNext = false;
	var ignoreQuotes = false;
	var ignoreDoubleQuotes = false;
	
	while(i < parameter.length) {
		charAtI = parameter.charAt(i);
		
		if(charAtI == "\\") {
			ignoreNext = true;
			
		} else if(charAtI == "\"" && !ignoreNext && !ignoreQuotes) {
			ignoreDoubleQuotes = !ignoreDoubleQuotes;
			
		} else if(charAtI == "\'" && !ignoreNext && !ignoreDoubleQuotes) {
			ignoreQuotes = !ignoreQuotes;
			
		} else if(charAtI == sepChar && !ignoreNext && !ignoreQuotes && !ignoreDoubleQuotes) {
			temp = temp.replace(/^\s*/, '');
			temp = temp.replace(/\s*$/, '');
			if(temp) aParam[aParam.length] = temp;
			temp = "";
			
		} else {
			temp += charAtI;
			ignoreNext = false;
		}
		i++;
	}
	temp = temp.replace(/^\s*/, '');
	temp = temp.replace(/\s*$/, '');
	if(temp) aParam[aParam.length] = temp;
	return aParam;
}
