
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by ----- filename.js -----
 */

/* ----- formsubmithelpers.js ----- */
function inputSubmitOnClick(event) {
    if (!event) var event = window.event; // IE compatibility

    if (hasClassName(this, 'submitting')) {
        return confirm(window.form_resubmit_message);
    } else {
        addClassName(this, 'submitting');
    }
    return true;
}

function registerSubmitHandler() {
    var nodes = cssQuery('input[type=submit]');
    for (var i=0; i<nodes.length; i++) {
        var node = nodes[i];
        if (!node.onclick) {
            node.onclick = inputSubmitOnClick;
        }
    }
}
registerPloneFunction(registerSubmitHandler);


/* ----- floating_menus.js ----- */
up_pageMousedown = function (event) {
  var el; 
  var sfEls = document.getElementById("nav").getElementsByTagName("LI");

  if (!event) el = window.event.srcElement;
  else el = (event.target.tagName ? event.target : event.target.parentNode);

  if (up_inMenu(el)) return; 
  if (!up_inMenu(el)) up_hide_items(sfEls);
}

up_getEventRelatedTarget = function (event) {
  if (!event) { // IE
    if (window.event.type=="mouseover") { 
      return window.event.fromElement; } else {
      return window.event.toElement; }
  };
  return event.relatedTarget; // Moz
}

up_getEventCurrentTarget = function (event) {
    if (!event) return window.event.toElement; // IE
    return event.currentTarget; // Moz
}

up_hasClassName = function (el, name) {
  // Return true if the given element currently has the given class name.
  if (el.className.indexOf(name) != -1) return true;
  return false;
}

up_getContainerWith = function (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 &&
        up_hasClassName(node, className))
      return node;
    node = node.parentNode;
  }
  return node;
}

up_getContainer = function (node, tagName) {
  // 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)
      return node;
    node = node.parentNode;
  }
  return node;
}

up_inMenu = function (el) { return up_getContainerWith(el, "UL", "menu") != null }

up_strip_sfhover = function (ss) { 
    if (ss) return ss.replace(/\s*sfhover\s*/g, ' '); 
}

up_hide_items = function (items) {
    for (var i=0; i<items.length; i++) { 
        items[i].className=up_strip_sfhover(items[i].className); 
    }
}

up_sfHover = function () {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    // Decorate all the LI elements in the menu with "sfhover" class.
    document.onmousedown = up_pageMousedown;
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover = function (event) {
            current_target = up_getContainer(up_getEventCurrentTarget(event), "LI");
            parent_list = up_getContainer(current_target, "UL");
            siblings = parent_list.childNodes;
            for (var j=0; j<siblings.length; j++) {
                if (siblings[j] != current_target) {
                    node = siblings[j];
                    if (node.tagName == "LI") {
                        if (node.className.indexOf("sfhover") != -1) {
                            nodes = node.getElementsByTagName("LI");
                            node.className=up_strip_sfhover(node.className);
                            up_hide_items(nodes); 
                        }
                    }
                }
            }
            if (this.className.indexOf("sfhover") == -1) {
                this.className+=" sfhover"; 
            }
        };
        sfEls[i].onmouseout = function (event) { 
            related_target = up_getEventRelatedTarget(event);
            if ( up_inMenu(related_target)) {
                node.className=up_strip_sfhover(node.className); 
            }
        }
    }
}

if (window.attachEvent) window.attachEvent("onload", up_sfHover);
if (window.addEventListener) window.addEventListener("load", up_sfHover, true);

