
/* 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 -
 */

/* - input-label.js - */
// http://www.rad.washington.edu/portal_javascripts/input-label.js?original=1
var ploneInputLabel={focus: function(e){var t=jq(e.target);if(t.hasClass('inputLabelActive')&&t.val()==t.attr('title'))
t.val('').removeClass('inputLabelActive')},blur: function(e){var t=jq(e.target);if(!t.val())
t.addClass('inputLabelActive').val(t.attr('title'))},submit: function(e){jq('input[title].inputLabelActive').filter(function(){return jq(this).val()==this.title}).val('').removeClass('inputLabelActive')}};jq(function(){jq('form:has(input[title].inputLabel)').submit(ploneInputLabel.submit);jq('input[title].inputLabel').each(function(){jq(this).focus(ploneInputLabel.focus).blur(ploneInputLabel.blur);if(!jq(this).val())
jq(this).val(this.title).removeClass('inputLabel').addClass('inputLabelActive')})});

/* - metanavwidgets.js - */
var nav_xmlhttp;

function getSubFolders(dropdown) {
    //var dropdown = document.getElementById('form.navigation_location_top_level');
    var folder_uid = dropdown.options[dropdown.selectedIndex].value;
    nav_xmlhttp = new XMLHttpRequest();
    nav_xmlhttp.open('GET', location + '../../@@getSubNavigationFoldersXML?topLevelFolderUID=' + folder_uid);
    nav_xmlhttp.onreadystatechange = getSubFolderXML;
    nav_xmlhttp.send(null);
}

function getSubFolderXML() {
   if (nav_xmlhttp.readyState == 4) {
       var xmlDoc = nav_xmlhttp.responseXML;
       var results = xmlDoc.getElementsByTagName("result");
       var title_list = new Array(results.length);
       var id_list = new Array(results.length);
   
       /* Clear out the current options, if there are any */
       var secondarySelect = document.getElementById('form.navigation_location_top_level_secondary_level');
       if (secondarySelect.length > 0) {secondarySelect.length = 0;}
       
       /* Populate the dropdown with the right data */
       for (var i = 0; i < results.length; i++) {
           title = results[i].getAttribute("title");
           id = results[i].getAttribute("id");
           secondarySelect.options[i] = new Option(title, id);
           }
       }
}

/* - metanav.js - */
/*
	metaNav.js
  controls display of metaNav navigation levels and descriptions
*/

/* THIS IS A PATCH MEANT TO DEAL WITH PROBLEMS WITH IE6 FOR NON-LOGGED-IN USERS
   FOR SOME REASON, THE NEW J-QUERY BASED VERSION OF REGISTERPLONEFUNCTION BELOW
   DOES NOT WORK UNDER THOSE CIRCUMSTANCES.  THEREFORE, WE ARE GOING TO INCLUDE THE
   OLD VERSION OF REGISTERPLONEFUNCTION AS IT STOOD BEFORE J-QUERY, AND USE THAT IN
   THIS FILE ONLY.  
*/

// check for ie5 mac
// var bugRiddenCrashPronePieceOfJunk = (
//     navigator.userAgent.indexOf('MSIE 5') != -1
//     &&
//     navigator.userAgent.indexOf('Mac') != -1
// )
// 
// // check for W3CDOM compatibility
// var W3CDOM = (!bugRiddenCrashPronePieceOfJunk &&
//                typeof document.getElementsByTagName != 'undefined' &&
//                typeof document.createElement != 'undefined' );

// cross browser function for registering event handlers
var myRegisterEventListener = undefined;

if (typeof addEvent != 'undefined') {
    // use Dean Edwards' function if available
    myRegisterEventListener = function (elem, event, func) {
        addEvent(elem, event, func);
        return true;
    }
} else if (window.addEventListener) {
    myRegisterEventListener = function (elem, event, func) {
        elem.addEventListener(event, func, false);
        return true;
    }
} else if (window.attachEvent) {
    myRegisterEventListener = function (elem, event, func) {
        var result = elem.attachEvent("on"+event, func);
        return result;
    }
} else {
    myRegisterEventListener = function (elem, event, func) {
        // maybe we could implement something with an array
        return false;
    }
}

// cross browser function for unregistering event handlers
var myUnRegisterEventListener = undefined;

if (typeof removeEvent != 'undefined') {
    // use Dean Edwards' function if available
    myUnRegisterEventListener = function (elem, event, func) {
        removeEvent(element, event, func);
        return true;
    }
} else if (window.removeEventListener) {
    myUnRegisterEventListener = function (elem, event, func) {
        elem.removeEventListener(event, func, false);
        return true;
    }
} else if (window.detachEvent) {
    myUnRegisterEventListener = function (elem, event, func) {
        var result = elem.detachEvent("on"+event, func);
        return result;
    }
} else {
    myUnRegisterEventListener = function (elem, event, func) {
        // maybe we could implement something with an array
        return false;
    }
}

var myRegisterPloneFunction = undefined;

if (typeof addDOMLoadEvent != 'undefined') {
    myRegisterPloneFunction = function (func) {
        // registers a function to fire ondomload.
        addDOMLoadEvent(func);
    }
} else {
    myRegisterPloneFunction = function (func) {
        // registers a function to fire onload.
        myRegisterEventListener(window, "load", func);
    }
}

function myGetContentArea() {
    // returns our content area element
    if (W3CDOM) {
        var node = document.getElementById('content');
        if (!node) {
            node = document.getElementById('region-content');
        }
        return node;
    }
} 

/* END SANDBOX FOR STUPID IE FIX
*/

/* if javascript is enabled, move the metanav well (div#navSubLevels)
   from the node at the bottom of the page, where it is written, to the
   node at the top of the page, where it belongs.
*/
function moveMetaNavContainer() {
    metanavBottom = cssQuery('#metanavBelowContent')[0];
    metanavTop = cssQuery('#metanavAboveContent')[0];
    metanavWell = cssQuery('#navSubLevels')[0];
    metanavBottom.removeChild(metanavWell);
    metanavTop.appendChild(metanavWell);
}

/* add stylesheet which creates hide/show and other classes on the
   metaNav elements.  Users without Javascript will still be able 
   to see all style choices.  The no-javascript CSS file will be
   overridden by this new CSS file
*/
function setMetaNavStyle() {
  //sets metaNav stylesheet to the one used for javascript version
  metaNavStyle = cssQuery('#metanavStyleLink')[0];
  metaNavStyle.setAttribute('href','metanav.css');
}

/* register a suckerfish-like function to handle the metanav dropdown style
   in IE
*/
function metanavSuckerfish() {
    if (document.all&&document.getElementById) {
      navportlets = document.getElementById('metanavPortletWrapper');
      for (i=0; i<navportlets.childNodes.length; i++) {
          node = navportlets.childNodes[i];
          if (node.nodeName=='DL') {
            node.onmouseover=function() {
              this.className+=" over";
            }
            node.onmouseout=function() {
              this.className=this.className.replace(" over", "");
            }
          }
      }
    }
}

/* call the functions required to set up a page for javascript-enabled
   viewing
*/
function metanavSetup() {
    setMetaNavStyle();
    moveMetaNavContainer();
    metanavSuckerfish();
}

//register function to fire on window onload
//registerPloneFunction(metanavSetup);
registerPloneFunction(metanavSetup);

function showNavLevel(level, id) {

  //display specified node at the specified level,
  //hide other nodes at that level.  levels defined by CSS classes

  selectedNode = cssQuery('#'+id)[0];
  allNodesAtLevel = cssQuery('.navLevel-'+level);
  for (node in allNodesAtLevel) {
    thisNode = allNodesAtLevel[node];
    if (thisNode == selectedNode) replaceClassName(thisNode, 'hide', 'show');
    else replaceClassName(thisNode  , 'show', 'hide');    
   }

   //hide all sublevels of the selected node
   subLevels = cssQuery('.navLevel-'+(level+1),selectedNode);
   for (node in subLevels) {
     thisNode = subLevels[node];
     replaceClassName(thisNode, 'show', 'hide');
   }
  
}

function showNavDescription(el) {
  var topLevelDescription = cssQuery('#topLevelDescription')[0];
  topLevelDescription.innerHTML = el.title;
}

function clearNavDescription(el) {
  var topLevelDescription = cssQuery('#topLevelDescription')[0];
  topLevelDescription.innerHTML = '';  
}

function clearNavLevel(id) {
  //hide specified nav level
  selectedNode = cssQuery('#'+id)[0];
  replaceClassName(selectedNode, 'show', 'hide');

  //hide all lower levels  
  allNodesAtLevel = cssQuery('.navLevel-3');
  for (node in allNodesAtLevel) {
    thisNode = allNodesAtLevel[node];
    replaceClassName(thisNode, 'show', 'hide');
   }
  
}
