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

/* ----- register_function.js ----- */
/* Essential javascripts, used a lot. 
 * These should be placed inline
 * We have to be certain they are loaded before anything that uses them 
 */

// check for ie5 mac
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    &&
    navigator.userAgent.indexOf('Mac') != -1
)

// check for W3CDOM compatibility
var W3CDOM = (!bugRiddenCrashPronePieceOfJunk &&
               document.getElementsByTagName &&
               document.createElement);

// cross browser function for registering event handlers
function registerEventListener(elem, event, func) {
    if (elem.addEventListener) {
        elem.addEventListener(event, func, false);
        return true;
    } else if (elem.attachEvent) {
        var result = elem.attachEvent("on"+event, func);
        return result;
    }
    // maybe we could implement something with an array
    return false;
}

// cross browser function for unregistering event handlers
function unRegisterEventListener(elem, event, func) {
    if (elem.removeEventListener) {
        elem.removeEventListener(event, func, false);
        return true;
    } else if (elem.detachEvent) {
        var result = elem.detachEvent("on"+event, func);
        return result;
    }
    // maybe we could implement something with an array
    return false;
}

function registerPloneFunction(func) {
    // registers a function to fire onload.
    registerEventListener(window, "load", func);
}

function unRegisterPloneFunction(func) {
    // unregisters a function so it does not fire onload.
    unRegisterEventListener(window, "load", func);
}

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


/* ----- cssQuery.js ----- */
/*
	cssQuery, version 2.0 (2005/05/23)
	Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 z=5(){7 1M="2.0 (3e)";7 Z=M;7 C=/\\s*,\\s*/;7 z=5(s,D){3d{7 m=[];7 u=1C.3c.2j&&!D;7 b=(D)?(D.3b==26)?D:[D]:[1l];7 1N=1f(s).1o(C),i;h(i=0;i<1N.x;i++){s=1I(1N[i]);8(Z&&s.V(0,3).2i("")==" *#"){s=s.V(2);D=2e([],b,s[1])}1J D=b;7 j=0,t,f,a,c="";H(j<s.x){t=s[j++];f=s[j++];c+=t+f;a="";8(s[j]=="("){H(s[j++]!=")")a+=s[j];a=a.V(0,-1);c+="("+a+")"}D=(u&&12[c])?12[c]:2c(D,t,f,a);8(u)12[c]=D}m=m.3a(D)}1E z.2k;6 m}39(e){z.2k=e;6[]}};z.2a=5(){6"5 z() {\\n  [1M "+1M+"]\\n}"};7 12={};z.2j=P;z.38=5(s){8(s){s=1I(s).2i("");1E 12[s]}1J 12={}};7 1y={};7 1g=P;z.1c=5(n,s){8(1g)1a("s="+17(s));1y[n]=X s()};z.37=5(c){6 c?1a(c):y};7 F={};7 l={};7 Y=[];F[" "]=5(r,f,t,n){7 e,i,j;h(i=0;i<f.x;i++){7 s=13(f[i],t,n);h(j=0;(e=s[j]);j++){8(R(e)&&19(e,n))r.B(e)}}};F["#"]=5(r,f,i){7 e,j;h(j=0;(e=f[j]);j++)8(e.Q==i)r.B(e)};F["."]=5(r,f,c){c=X 1x("(^|\\\\s)"+c+"(\\\\s|$)");7 e,i;h(i=0;(e=f[i]);i++)8(c.q(e.23))r.B(e)};F[":"]=5(r,f,p,a){7 t=l[p],e,i;8(t)h(i=0;(e=f[i]);i++)8(t(e,a))r.B(e)};l["36"]=5(e){7 d=T(e);8(d.1L)h(7 i=0;i<d.1L.x;i++){8(d.1L[i]==e)6 M}};l["35"]=5(e){};7 R=5(e){6(e&&e.1i==1&&e.1k!="!")?e:2d};7 1d=5(e){H(e&&(e=e.34)&&!R(e))2h;6 e};7 J=5(e){H(e&&(e=e.33)&&!R(e))2h;6 e};7 1v=5(e){6 R(e.2g)||J(e.2g)};7 1X=5(e){6 R(e.2f)||1d(e.2f)};7 1r=5(e){7 c=[];e=1v(e);H(e){c.B(e);e=J(e)}6 c};7 1m=5(e){6 T(e).32=="31 30"};7 T=5(e){6 e.2Z||e.1l};7 13=5(e,t){6(t=="*"&&e.1K)?e.1K:e.13(t)};7 1e=5(e,t,n){8(t=="*")6 R(e);8(!19(e,n))6 P;8(!1m(e))t=t.2Y();6 e.1k==t};7 19=5(e,n){6!n||(n=="*")||(e.2X==n)};7 1j=5(e){6 e.1P};5 2e(r,f,Q){7 m,i,j;h(i=0;i<f.x;i++){8(m=f[i].1K.2W(Q)){8(m.x==2d)r.B(m);1J h(j=0;j<m.x;j++)r.B(m[j])}}6 r};7 N=/\\|/;5 2c(D,t,f,a){8(N.q(f)){f=f.1o(N);a=f[0];f=f[1]}7 r=[];8(F[t]){F[t](r,D,f,a)}6 r};7 S=/^[^\\s>+~]/;7 2b=/[\\s#.:>+~()@]|[^\\s#.:>+~()@]+/g;5 1I(s){8(S.q(s))s=" "+s;6 s.10(2b)||[]};7 W=/\\s*([\\s>+~(),]|^|$)\\s*/g;7 I=/([\\s>+~,]|[^(]\\+|^)([#.:@])/g;7 1f=5(s){6 s.G(W,"$1").G(I,"$1*$2")};7 1z={2a:5(){6"\'"},10:/^(\'[^\']*\')|("[^"]*")$/,q:5(s){6 y.10.q(s)},21:5(s){6 y.q(s)?s:y+s+y},29:5(s){6 y.q(s)?s.V(1,-1):s}};7 1w=5(t){6 1z.29(t)};7 E=/([\\/()[\\]?{}|*+-])/g;5 U(s){6 s.G(E,"\\\\$1")};X 5(){7 1G=5(f,o,a){f.1H(o,a)};8(\'\'.G(/^/,17)){7 27=17.1D.G;7 28=5(e,r){7 m,n="",s=y;H(s&&(m=e.2V(s))){n+=s.V(0,m.2U)+1G(r,y,m);s=s.V(m.2T)}6 n+s};17.1D.G=5(e,r){y.G=(2S r=="5")?28:27;6 y.G(e,r)}}8(!24.1H){7 L="1H-"+2R(X 2Q);1G=5(f,o,a){7 r;o[L]=f;18(a.x){A 0:r=o[L]();O;A 1:r=o[L](a[0]);O;A 2:r=o[L](a[0],a[1]);O;A 3:r=o[L](a[0],a[1],a[2]);O;A 4:r=o[L](a[0],a[1],a[2],a[3]);O;2P:7 1F=[],i=a.x-1;2O 1F[i]="a["+i+"]";H(i--);1a("r=o[L]("+1F+")")}1E o[L];6 r}}8(![].B)26.1D.B=5(){h(7 i=0;i<1C.x;i++){y[y.x]=1C[i]}6 y.x}};z.1c("1b-1Y",5(){F[">"]=5(r,f,t,n){7 e,i,j;h(i=0;i<f.x;i++){7 s=1r(f[i]);h(j=0;(e=s[j]);j++)8(1e(e,t,n))r.B(e)}};F["+"]=5(r,f,t,n){h(7 i=0;i<f.x;i++){7 e=J(f[i]);8(e&&1e(e,t,n))r.B(e)}};F["@"]=5(r,f,a){7 t=Y[a].q;7 e,i;h(i=0;(e=f[i]);i++)8(t(e))r.B(e)};l["2N-15"]=5(e){6!1d(e)};l["1B"]=5(e,c){c=X 1x("^"+c,"i");H(e&&!e.16("1B"))e=e.1q;6 e&&c.q(e.16("1B"))};7 9={};9.1A="@";9.K={};9.10=/\\[([\\w-]+)\\s*(\\W?=)?\\s*([^\\]]*)\\]/g;9.G=5(m,a,c,v){7 k=9.1A+m;8(!Y[k]){a=9.25(a,c||"",v||"");Y[k]=a;Y.B(a)}6 Y[k].Q};9.1Z=5(s){6 s.G(y.10,y.G)};9.25=5(p,t,v){7 a={};a.Q=9.1A+Y.x;a.2M=p;t=y.K[t];t=t?t(9.16(p),1w(v)):P;a.q=X 24("e","6 "+t);6 a};9.16=5(n){18(n.2L()){A"Q":6"e.Q";A"2K":6"e.23";A"h":6"e.2J";A"22":8(Z){6"17((e.2I.10(/22=\\"?([^\\\\s\\"]*)\\"?/)||[])[1]||\'\')"}}6"e.16(\'"+n+"\')"};y.9=9;9.K[""]=5(a){6 a};9.K["="]=5(a,v){6 a+"=="+1z.21(v)};9.K["~="]=5(a,v){6"/(^|\\\\s)"+U(v)+"(\\\\s|$)/.q("+a+")"};9.K["|="]=5(a,v){6"/^"+U(v)+"(-|$)/.q("+a+")"};7 20=1f;1f=5(s){6 20(9.1Z(s))}});z.1c("1b-2H",5(){7 1t=1y["1b-1Y"];8(!1t)6;F["~"]=5(r,f,t,n){7 e,i;h(i=0;(e=f[i]);i++){H(e=J(e)){8(1e(e,t,n))r.B(e)}}};l["2G"]=5(e,t){t=X 1x(U(1w(t)));6 t.q(1j(e))};l["2F"]=5(e){6 e==T(e).1Q};l["2E"]=5(e){7 n,i;h(i=0;(n=e.1O[i]);i++){8(R(n)||n.1i==3)6 P}6 M};l["1V-15"]=5(e){6!J(e)};l["2D-15"]=5(e){e=e.1q;6 1v(e)==1X(e)};l["2C"]=5(e,s){7 n=z(s,T(e));h(7 i=0;i<n.x;i++){8(n[i]==e)6 P}6 M};l["1W-15"]=5(e,a){6 1s(e,a,1d)};l["1W-1V-15"]=5(e,a){6 1s(e,a,J)};l["2B"]=5(e){6 e.Q==2A.2z.V(1)};l["1U"]=5(e){6 e.1U};l["2y"]=5(e){6 e.1u===P};l["1u"]=5(e){6 e.1u};l["1T"]=5(e){6 e.1T};7 9=1t.9;9.K["^="]=5(a,v){6"/^"+U(v)+"/.q("+a+")"};9.K["$="]=5(a,v){6"/"+U(v)+"$/.q("+a+")"};9.K["*="]=5(a,v){6"/"+U(v)+"/.q("+a+")"};5 1s(e,a,t){18(a){A"n":6 M;A"2x":a="2n";O;A"2w":a="2n+1"}7 1p=1r(e.1q);5 1n(i){7 i=(t==J)?1p.x-i:i-1;6 1p[i]==e};8(!14(a))6 1n(a);a=a.1o("n");7 m=1S(a[0]);7 s=1S(a[1]);8((14(m)||m==1)&&s==0)6 M;8(m==0&&!14(s))6 1n(s);8(14(s))s=0;7 c=1;H(e=t(e))c++;8(14(m)||m==1)6(t==J)?(c<=s):(s>=c);6(c%m)==s}});z.1c("1b-2v",5(){Z=1a("P;/*@2u@8(@\\2t)Z=M@2s@*/");8(!Z){13=5(e,t,n){6 n?e.2r("*",t):e.13(t)};19=5(e,n){6!n||(n=="*")||(e.2q==n)};1m=1l.1R?5(e){6/2p/i.q(T(e).1R)}:5(e){6 T(e).1Q.1k!="2o"};1j=5(e){6 e.2m||e.1P||1h(e)};5 1h(e){7 t="",n,i;h(i=0;(n=e.1O[i]);i++){18(n.1i){A 11:A 1:t+=1h(n);O;A 3:t+=n.2l;O}}6 t}}});1g=M;6 z}();',62,201,'|||||function|return|var|if|AttributeSelector||||||||for||||pseudoClasses|||||test|||||||length|this|cssQuery|case|push||fr||selectors|replace|while||nextElementSibling|tests|APPLY|true||break|false|id|thisElement||getDocument|regEscape|slice||new|attributeSelectors|isMSIE|match||cache|getElementsByTagName|isNaN|child|getAttribute|String|switch|compareNamespace|eval|css|addModule|previousElementSibling|compareTagName|parseSelector|loaded|_0|nodeType|getTextContent|tagName|document|isXML|_1|split|ch|parentNode|childElements|nthChild|css2|disabled|firstElementChild|getText|RegExp|modules|Quote|PREFIX|lang|arguments|prototype|delete|aa|ap|apply|_2|else|all|links|version|se|childNodes|innerText|documentElement|contentType|parseInt|indeterminate|checked|last|nth|lastElementChild|level2|parse|_3|add|href|className|Function|create|Array|_4|_5|remove|toString|ST|select|null|_6|lastChild|firstChild|continue|join|caching|error|nodeValue|textContent||HTML|xml|prefix|getElementsByTagNameNS|end|x5fwin32|cc_on|standard|odd|even|enabled|hash|location|target|not|only|empty|root|contains|level3|outerHTML|htmlFor|class|toLowerCase|name|first|do|default|Date|Number|typeof|lastIndex|index|exec|item|scopeName|toUpperCase|ownerDocument|Document|XML|mimeType|nextSibling|previousSibling|visited|link|valueOf|clearCache|catch|concat|constructor|callee|try|beta'.split('|'),0,{}))


/* ----- plone_javascript_variables.js ----- */

// Global Plone variables that need to be accessible to the Javascripts
var portal_url = 'http://moveon.qs-unisolution.com';
var form_modified_message = 'Your form has not been saved. All changes you have made will be lost.';
var form_resubmit_message = 'Your already clicked the submit button. Do you really want to submit this form again?';


/* ----- nodeutilities.js ----- */

function wrapNode(node, wrappertype, wrapperclass){
    /* utility function to wrap a node in an arbitrary element of type "wrappertype"
     * with a class of "wrapperclass" */
    var wrapper = document.createElement(wrappertype)
    wrapper.className = wrapperclass;
    var innerNode = node.parentNode.replaceChild(wrapper,node);
    wrapper.appendChild(innerNode);
};

function nodeContained(innernode, outernode){
    // check if innernode is contained in outernode
    var node = innernode.parentNode;
    while (node != document) {
        if (node == outernode) {
            return true; 
        }
        node=node.parentNode;
    }
    return false;
};

function findContainer(node, func) {
    // Starting with the given node, find the nearest containing element
    // for which the given function returns true.

    while (node != null) {
        if (func(node)) {
            return node;
        }
        node = node.parentNode;
    }
    return false;
};

function hasClassName(node, class_name) {
    return new RegExp('\\b'+class_name+'\\b').test(node.className);
};

function addClassName(node, class_name) {
    if (!node.className) {
        node.className = class_name;
    } else if (!hasClassName(node, class_name)) {
        var className = node.className+" "+class_name;
        // cleanup
        node.className = className.split(/\s+/).join(' ');
    }
};

function removeClassName(node, class_name) {
    var className = node.className;
    if (className) {
        // remove
        className = className.replace(new RegExp('\\b'+class_name+'\\b'), '');
        // cleanup
        className = className.replace(/\s+/g, ' ');
        node.className = className.replace(/\s+$/g, '');
    }
};

function replaceClassName(node, old_class, new_class, ignore_missing) {
    if (ignore_missing && !hasClassName(node, old_class)) {
        addClassName(node, new_class);
    } else {
        var className = node.className;
        if (className) {
            // replace
            className = className.replace(new RegExp('\\b'+old_class+'\\b'), new_class);
            // cleanup
            className = className.replace(/\s+/g, ' ');
            node.className = className.replace(/\s+$/g, '');
        }
    }
};

function walkTextNodes(node, func, data) {
    // traverse childnodes and call func when a textnode is found
    if (!node){return false}
    if (node.hasChildNodes) {
        // we can't use for (i in childNodes) here, because the number of
        // childNodes might change (higlightsearchterms)
        for (var i=0;i<node.childNodes.length;i++) {
            walkTextNodes(node.childNodes[i], func, data);
        }
        if (node.nodeType == 3) {
            // this is a text node
            func(node, data);
        }
    }
};

/* These are two functions, because getInnerTextFast doesn't always return the
 * the same results, as it depends on the implementation of node.innerText of
 * the browser. getInnerTextCompatible will always return the same values, but
 * is a bit slower. The difference is just in the whitespace, so if this
 * doesn't matter, you should always use getInnerTextFast.
 */

function getInnerTextCompatible(node) {
    var result = new Array();
    walkTextNodes(node,
                  function(n, d){d.push(n.nodeValue)},
                  result);
    return result.join("");
};

function getInnerTextFast(node) {
    if (node.innerText) {
        return node.innerText;
    } else {
        return getInnerTextCompatible(node);
    }
};

/* This function reorder nodes in the DOM.
 * fetch_func - the function which returns the value for comparison
 * cmp_func - the compare function, if not provided then the string of the
 * value returned by fetch_func is used.
 */
function sortNodes(nodes, fetch_func, cmp_func) {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM){return false};

    // wrapper for sorting
    var SortNodeWrapper = function(node) {
        this.value = fetch_func(node);
        this.cloned_node = node.cloneNode(true);
        this.toString = function() {
            if (this.value.toString) {
                return this.value.toString();
            } else {
                return this.value;
            }
        }
    }

    // wrap nodes
    var items = new Array();
    for (var i=0; i<nodes.length; i++) {
        items.push(new SortNodeWrapper(nodes[i]));
    }

    //sort
    if (cmp_func) {
        items.sort(cmp_func);
    } else {
        items.sort();
    }

    // reorder nodes
    for (var i=0; i<items.length; i++) {
        var dest = nodes[i];
        dest.parentNode.replaceChild(items[i].cloned_node, dest);
    }
};


/* ----- select_all.js ----- */
// Functions for selecting all checkboxes in folder_contents/search_form view
function selectAll(id, formName) {
    // Get the elements. if formName is provided, get the elements inside the form
    if (formName==null) {
        checkboxes = document.getElementsByName(id)
        for (i = 0; i < checkboxes.length; i++){
            checkboxes[i].checked = true ;
            }
    } else {
        for (i=0; i<document.forms[formName].elements.length;i++){
            if (document.forms[formName].elements[i].name==id){
                document.forms[formName].elements[i].checked=true; 
                }
            }
        }
    }
function deselectAll(id, formName) {
    if (formName==null) {
        checkboxes = document.getElementsByName(id)
        for (i = 0; i < checkboxes.length; i++){
            checkboxes[i].checked = false ;}
    } else {
        for (i=0; i<document.forms[formName].elements.length;i++){
            if (document.forms[formName].elements[i].name==id){
                document.forms[formName].elements[i].checked=false;
                }
            }
        }
    }
function toggleSelect(selectbutton, id, initialState, formName) {
    /* required selectbutton: you can pass any object that will function as a toggle
     * optional id: id of the the group of checkboxes that needs to be toggled (default=ids:list
     * optional initialState: initial state of the group. (default=false)
     * e.g. folder_contents is false, search_form=true because the item boxes
     * are checked initially.
     * optional formName: name of the form in which the boxes reside, use this if there are more
     * forms on the page with boxes with the same name
     */
    id=id || 'ids:list'  // defaults to ids:list, this is the most common usage

    if (selectbutton.isSelected==null){
        initialState=initialState || false;
        selectbutton.isSelected=initialState;
        }
    /* create and use a property on the button itself so you don't have to 
     * use a global variable and we can have as much groups on a page as we like.
     */
    if (selectbutton.isSelected == false) {
        selectbutton.setAttribute('src', portal_url + '/select_none_icon.gif');
        selectbutton.isSelected=true;
        return selectAll(id, formName);
    } else {
        selectbutton.setAttribute('src',portal_url + '/select_all_icon.gif');
        selectbutton.isSelected=false;
        return deselectAll(id, formName);
        }
    } 

/* ----- dropdown.js ----- */
/*
 * This is the code for the dropdown menus. It uses the following markup:
 *
 * <dl class="actionMenu" id="uniqueIdForThisMenu">
 *   <dt class="actionMenuHeader">
 *     <!-- The following a-tag needs to be clicked to dropdown the menu -->
 *     <a href="some_destination">A Title</a>
 *   </dt>
 *   <dd class="actionMenuContent">
 *     <!-- Here can be any content you want -->
 *   </dd>
 * </dl>
 *
 * When the menu is toggled, then the dl with the class actionMenu will get an
 * additional class which switches between 'activated' and 'deactivated'.
 * You can use this to style it accordingly, for example:
 *
 * .actionMenu.activated {
 *   display: block;
 * }
 *
 * .actionMenu.deactivated {
 *   display: none;
 * }
 *
 * When you click somewhere else than the menu, then all open menus will be
 * deactivated. When you move your mouse over the a-tag of another menu, then
 * that one will be activated and all others deactivated. When you click on a
 * link inside the actionMenuContent element, then the menu will be closed and
 * the link followed.
 *
 * This file uses functions from register_function.js, cssQuery.js and
 * nodeutils.js.
 *
 */

function isActionMenu(node) {
    if (hasClassName(node, 'actionMenu')) {
        return true;
    }
    return false;
};

function hideAllMenus() {
    var menus = cssQuery('dl.actionMenu');
    for (var i=0; i < menus.length; i++) {
        replaceClassName(menus[i], 'activated', 'deactivated', true);
    }
};

function toggleMenuHandler(event) {
    if (!event) var event = window.event; // IE compatibility

    // terminate if we hit a non-compliant DOM implementation
    // returning true, so the link is still followed
    if (!W3CDOM){return true;}

    var container = findContainer(this, isActionMenu);
    if (!container) {
        return true;
    }

    // check if the menu is visible
    if (hasClassName(container, 'activated')) {
        // it's visible - hide it
        replaceClassName(container, 'activated', 'deactivated', true);
    } else {
        // it's invisible - make it visible
        replaceClassName(container, 'deactivated', 'activated', true);
    }

    return false;
};

function hideMenusHandler(event) {
    if (!event) var event = window.event; // IE compatibility

    hideAllMenus();

    // we want to follow this link
    return true;
};

function actionMenuDocumentMouseDown(event) {
    if (!event) var event = window.event; // IE compatibility

    if (event.target)
        targ = event.target;
    else if (event.srcElement)
        targ = event.srcElement;

    var container = findContainer(targ, isActionMenu);
    if (container) {
        // targ is part of the menu, so just return and do the default
        return true;
    }

    hideAllMenus();

    return true;
};

function actionMenuMouseOver(event) {
    if (!event) var event = window.event; // IE compatibility

    if (!this.tagName && (this.tagName == 'A' || this.tagName == 'a')) {
        return true;
    }

    var container = findContainer(this, isActionMenu);
    if (!container) {
        return true;
    }
    var menu_id = container.id;

    var switch_menu = false;
    // hide all menus
    var menus = cssQuery('dl.actionMenu');
    for (var i=0; i < menus.length; i++) {
        var menu = menus[i]
        // check if the menu is visible
        if (hasClassName(menu, 'activated')) {
            switch_menu = true;
        }
        // turn off menu when it's not the current one
        if (menu.id != menu_id) {
            replaceClassName(menu, 'activated', 'deactivated', true);
        }
    }

    if (switch_menu) {
        var menu = cssQuery('#'+menu_id)[0];
        if (menu) {
            replaceClassName(menu, 'deactivated', 'activated', true);
        }
    }

    return true;
};

function initializeMenus() {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM) {return false;}

    document.onmousedown = actionMenuDocumentMouseDown;

    hideAllMenus();

    // add toggle function to header links
    var menu_headers = cssQuery('dl.actionMenu > dt.actionMenuHeader > a');
    for (var i=0; i < menu_headers.length; i++) {
        var menu_header = menu_headers[i];

        menu_header.onclick = toggleMenuHandler;
        menu_header.onmouseover = actionMenuMouseOver;
    }

    // add hide function to all links in the dropdown, so the dropdown closes
    // when any link is clicked
    var menu_contents = cssQuery('dl.actionMenu > dd.actionMenuContent');
    for (var i=0; i < menu_contents.length; i++) {
        menu_contents[i].onclick = hideMenusHandler;
    }

    // uncomment to enable sorting of elements
    //var nodes = cssQuery('#objectMenu > dd.actionMenuContent li');
    //sortNodes(nodes, getInnerTextFast);
};

registerPloneFunction(initializeMenus);


/* ----- mark_special_links.js ----- */
/* Scan all links in the document and set classes on them if
 * they point outside the site, or are special protocols
 * To disable this effect for links on a one-by-one-basis,
 * give them a class of 'link-plain'
 */

function scanforlinks() {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM) { return false; }

    contentarea = getContentArea();
    if (!contentarea) { return false; }

    links = contentarea.getElementsByTagName('a');
    for (i=0; i < links.length; i++) {
        if ( (links[i].getAttribute('href'))
             && (links[i].className.indexOf('link-plain')==-1) ) {
            var linkval = links[i].getAttribute('href');

            // check if the link href is a relative link, or an absolute link to
            // the current host.
            if (linkval.toLowerCase().indexOf(window.location.protocol
                                              + '//'
                                              + window.location.host)==0) {
                // absolute link internal to our host - do nothing
            } else if (linkval.indexOf('http:') != 0) {
                // not a http-link. Possibly an internal relative link, but also
                // possibly a mailto or other protocol add tests for relevant
                // protocols as you like.
                protocols = ['mailto', 'ftp', 'news', 'irc', 'h323', 'sip',
                             'callto', 'https', 'feed', 'webcal'];
                // h323, sip and callto are internet telephony VoIP protocols
                for (p=0; p < protocols.length; p++) {
                    if (linkval.indexOf(protocols[p]+':') == 0) {
                        // if the link matches one of the listed protocols, add
                        // className = link-protocol
                        wrapNode(links[i], 'span', 'link-'+protocols[p]);
                        break;
                    }
                }
            } else {
                // we are in here if the link points to somewhere else than our
                // site.
                if ( links[i].getElementsByTagName('img').length == 0 ) {
                    // we do not want to mess with those links that already have
                    // images in them
                    wrapNode(links[i], 'span', 'link-external');
                    // uncomment the next line if you want external links to be
                    // opened in a new window.
                    links[i].setAttribute('target', '_blank');
                }
            }
        }
    }
};

registerPloneFunction(scanforlinks);


/* ----- highlightsearchterms.js ----- */
function highlightTermInNode(node, word) {
    var contents = node.nodeValue;
    var index = contents.toLowerCase().indexOf(word.toLowerCase());
    if (index < 0){return false};

    var parent = node.parentNode;
    if (parent.className != "highlightedSearchTerm") {
        // make 3 shiny new nodes
        var hiword = document.createElement("span");
        hiword.className = "highlightedSearchTerm";
        hiword.appendChild(document.createTextNode(contents.substr(index, word.length)));
        parent.insertBefore(document.createTextNode(contents.substr(0, index)), node);
        parent.insertBefore(hiword, node);
        parent.insertBefore(document.createTextNode(contents.substr(index+word.length)), node);
        parent.removeChild(node);
    }
}

function highlightSearchTerms(terms, startnode) {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM){return false};
    if (!terms){return false};
    if (!startnode){return false};

    for (var term_index=0; term_index < terms.length; term_index++) {
        // don't highlight reserved catalog search terms
        var term = terms[term_index];
        var term_lower = term.toLowerCase();
        if (term_lower != 'not'
            && term_lower != 'and'
            && term_lower != 'or') {
            walkTextNodes(startnode, highlightTermInNode, term);
        }
    }
}

function getSearchTermsFromURI(uri) {
    var query;
    if (typeof decodeURI != 'undefined') {
        query = decodeURI(uri);
    } else if (typeof unescape != 'undefined') {
        // _robert_ ie 5 does not have decodeURI 
        query = unescape(uri);
    } else {
        // we just try to be lucky, for single words this will still work
    }
    var result = new Array();
    if (window.decodeReferrer) {
        var referrerSearch = decodeReferrer();
        if (null != referrerSearch && referrerSearch.length > 0) {
            result = referrerSearch;
        }
    }
    var qfinder = new RegExp("searchterm=([^&]*)", "gi");
    var qq = qfinder.exec(query);
    if (qq && qq[1]) {
        var terms = qq[1].replace(/\+/g,' ').split(/\s+/);
        for (var i=0; i < terms.length; i++) {
            if (terms[i] != '') {
                result.push(terms[i]);
            }
        }
        return result;
    }
    return result.length == 0 ? false : result;
}

function highlightSearchTermsFromURI() {
    // terminate if we hit a non-compliant DOM implementation
    if (!W3CDOM){return false};

    // search-term-highlighter function --  Geir Bækholt
    var terms = getSearchTermsFromURI(window.location.search);
    // make sure we start the right place so we don't higlight menuitems or breadcrumb
    var contentarea = getContentArea();
    highlightSearchTerms(terms, contentarea);
}

registerPloneFunction(highlightSearchTermsFromURI);


/* ----- se-highlight.js ----- */
/* List of search engine matchers and the referrer search
 * code where carefully borrowed from the
 * "Search Engine Keyword Highlight" by Scott Yang,
 * see http://fucoder.com/code/se-hilite/ for further
 * details.
 */
var searchEngines = [
    ['^http://(www)?\\.?google.*', 'q='],              // Google
    ['^http://search\\.yahoo.*', 'p='],                // Yahoo
    ['^http://search\\.msn.*', 'q='],                  // MSN
    ['^http://search\\.aol.*', 'userQuery='],          // AOL
    ['^http://(www\\.)?altavista.*', 'q='],            // AltaVista
    ['^http://(www\\.)?feedster.*', 'q='],             // Feedster
    ['^http://search\\.lycos.*', 'query='],            // Lycos
    ['^http://(www\\.)?alltheweb.*', 'q=']             // AllTheWeb
]

function decodeReferrer(ref) {
    // checks if we are beeing searched by a search engine
    if (null == ref && document.referrer) {
        ref = document.referrer;
    }
    if (!ref) return null;

    var match = new RegExp('');
    var seQuery = '';
    for (var i = 0; i < searchEngines.length; i ++) {
        match.compile(searchEngines[i][0], 'i');
        if (ref.match(match)) {
            match.compile('^.*'+searchEngines[i][1]+'([^&]+)&?.*$');
            seQuery = ref.replace(match, '$1');
            if (seQuery) {
                seQuery = decodeURIComponent(seQuery);
                seQuery = seQuery.replace(/\'|"/, '');
                return seQuery.split(/[\s,\+\.]+/);
            }

        }
    }
    return null;
}


