// Code to determine the browser and version. function CBrowser() { var ua, s, i; this.isIE = false; // Internet Explorer this.isNS = false; // Netscape this.isOP = false; // Opera this.version = null; ua = navigator.userAgent; s = "Opera"; if ((i = ua.indexOf(s)) >= 0) { this.isOP = true; this.version = 7; return; } s = "MSIE"; if ((i = ua.indexOf(s)) >= 0) { this.isIE = true; this.version = parseFloat(ua.substr(i + s.length)); return; } s = "Netscape6/"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = parseFloat(ua.substr(i + s.length)); return; } // Treat any other "Gecko" browser as NS 6.1. s = "Gecko"; if ((i = ua.indexOf(s)) >= 0) { this.isNS = true; this.version = 6.1; return; } } CBrowser = new CBrowser(); function CEvent() { this.init = init; this.initEvent = initEvent; this.removeListener = removeListener; this.eventTypes = new Array("abort", "blur", "change", "click", "dblclick", "error", "focus", "keydown", "keypress", "keyup", "load", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "reset", "submit", "unload") function init(obj) { // Add member vars obj.handledEvents = new Array(); // Add methods obj.addListener = addListener; obj.removeListenerFromId = removeListenerFromId; obj.removeListenersFromType = removeListenersFromType; obj.removeAllListeners = removeAllListeners; // Get defined events for (var i in this.eventTypes) { var event_type = this.eventTypes[i]; var full_event = "on" + event_type; var event_func = obj[full_event]; if (event_func) { obj.addListener(event_type, event_type, event_func); } } } function initEvent(event) { var mEvent = event; if (CBrowser.isIE) { mEvent = window.event; mEvent.layerX = mEvent.offsetX; mEvent.layerY = mEvent.offsetY; mEvent.currentTarget = mEvent.srcElement; } return mEvent; } function removeListener(obj, event_type) { var full_event = "on" + event_type; if (CBrowser.isIE) { obj[full_event] = null; } else { delete(obj[full_event]); } } function evalEvent(event) { event = CEvent.initEvent(event); var event_type = event.type; for (var event_id in this.handledEvents) { if (this.handledEvents[event_id]["type"] == event_type) { this.handledEvents[event_id]["func"](event); } } } // CEvent methods function addListener(event_id, event_type, event_func) { var event = new Array(); var full_event = "on" + event_type; this[full_event] = evalEvent; event["type"] = event_type; event["func"] = event_func; this.handledEvents[event_id] = event; } function removeListenerFromId(event_id) { var event_type = this.handledEvents[event_id]["type"]; var bExists = 0; // Delete event delete(this.handledEvents[event_id]); // Search if exists an event with the same type for (var event_id in this.handledEvents) { if (this.handledEvents[event_id]["type"] == event_type) { bExists = 1; } } // If not delete listener if (!bExists) { CEvent.removeListener(this, event_type); } } function removeListenersFromType(event_type) { var full_event = "on" + event_type; // Delete events from specified type for (var event_id in this.handledEvents) { if (this.handledEvents[event_id]["type"] == event_type) { delete(this.handledEvents[event_id]); } } // Delete listener if (this[full_event]) { CEvent.removeListener(this, event_type); } } function removeAllListeners() { // Delete all events for (var event_id in this.handledEvents) { delete(this.handledEvents[event_id]); } // Delete all listeners for (var i in CEvent.eventTypes) { var event_type = CEvent.eventTypes[i]; CEvent.removeListener(this, event_type); } } } CEvent = new CEvent(); // CMFBoard code var cmfboard_browser = CBrowser; // Code for handling the menu bar and active button. var cmfboard_activeButton = null; var cmfboard_eventInit = 0; function cmfboard_initEvent() { if (!cmfboard_eventInit) { CEvent.init(document); document.addListener("cmfboard_mousedown", "mousedown", cmfboard_pageMousedown); cmfboard_eventInit = 1; } } function cmfboard_pageMousedown(event) { var el; // If there is no active button, exit. if (cmfboard_activeButton == null) { return; } // Find the element that was clicked on. if (CBrowser.isIE) { el = window.event.srcElement; } else { el = (event.target.tagName ? event.target : event.target.parentNode); } // If the active button was clicked on, exit. if (el == cmfboard_activeButton) { return; } // If the element is not part of a menu, reset and clear the active // button. if (cmfboard_getContainerWith(el, "UL", "menuAction") == null) { cmfboard_resetButton(cmfboard_activeButton); cmfboard_activeButton = null; } } function cmfboard_buttonClick(event, menuId) { var button; cmfboard_initEvent(); event = CEvent.initEvent(event); // Get the target button element. button = event.currentTarget; // Blur focus from the link to remove that annoying outline. button.blur(); // Associate the named menu to this button if not already done. // Additionally, initialize menu display. if (button) { button.menu = document.getElementById(menuId); button.menu.style.display = "block"; /*dropdown_menu = cmfboard_getContainerWith(button.menu, 'LI', 'dropdownMenu'); dropdown_menu.style.padding = "0 0 30em 0";*/ } // Reset the currently active button, if any. if (cmfboard_activeButton != null) { cmfboard_resetButton(cmfboard_activeButton); } // Activate this button, unless it was the currently active one. if (button != cmfboard_activeButton) { cmfboard_depressButton(button); cmfboard_activeButton = button; } else { cmfboard_activeButton = null; } return false; } function cmfboard_buttonMouseover(event, menuId) { var button; event = CEvent.initEvent(event); // Get the target button element. button = event.currentTarget; // If any other button menu is active, make this one active instead. if (cmfboard_activeButton != null && cmfboard_activeButton != button) { cmfboard_buttonClick(event, menuId); } } function cmfboard_depressButton(button) { var x, y; // Update the button's style class to make it look like it's // depressed. button.className += " menuButtonActive"; // Make the associated drop down menu visible display = button.menu.style.display; button.menu.style.display = (display == "none" || display == '') ? "none" : "block"; } function cmfboard_resetButton(button) { // Restore the button's style class. cmfboard_removeClassName(button, "menuButtonActive"); // Hide the button's menu, first closing any sub menus. if (button.menu != null) { cmfboard_closeSubMenu(button.menu); button.menu.style.display = "none"; } } function cmfboard_closeSubMenu(menu) { if (menu == null || menu.activeItem == null) return; // Recursively close any sub menus. if (menu.activeItem.subMenu != null) { cmfboard_closeSubMenu(menu.activeItem.subMenu); menu.activeItem.subMenu.style.display = "none"; menu.activeItem.subMenu = null; } cmfboard_removeClassName(menu.activeItem, "menuItemHighlight"); menu.activeItem = null; } // General utility functions. function cmfboard_getContainerWith(node, tagName, className) { // Starting with the given node, find the nearest containing element // with the specified tag name and style class. while (node != null) { if (node.tagName != null && node.tagName == tagName && cmfboard_hasClassName(node, className)) { return node; } node = node.parentNode; } return node; } function cmfboard_hasClassName(el, name) { var i, list; // Return true if the given element currently has the given class // name. list = el.className.split(" "); for (i = 0; i < list.length; i++) if (list[i] == name) { return true; } return false; } function cmfboard_removeClassName(el, name) { var i, curList, newList; if (el.className == null) { return; } // Remove the given class name from the element's className property. newList = new Array(); curList = el.className.split(" "); for (i = 0; i < curList.length; i++) { if (curList[i] != name) { newList.push(curList[i]); el.className = newList.join(" "); } } } function cmfboard_getPageOffsetLeft(el) { var x; // Return the x coordinate of an element relative to the page. x = el.offsetLeft; if (el.offsetParent != null) x += cmfboard_getPageOffsetLeft(el.offsetParent); return x; } function cmfboard_getPageOffsetTop(el) { var y; // Return the x coordinate of an element relative to the page. y = el.offsetTop; if (el.offsetParent != null) { y += cmfboard_getPageOffsetTop(el.offsetParent); } return y; }