//alert(3)

var g_knflags_autoHiliteIDField = false;


/****

Omnibus file incorporating all the plone and kn javascript not needed during pageflow rendering

plone_formtooltip.js
plone_menu.js
plone_javascript.js

****/


/*** plone_formtooltip.js ***/

// Tooltip-like help pop-ups used in forms

var ie=0 
if (navigator.appVersion.indexOf("MSIE")!=-1) { 
  ie=1; 
} 

// Tooltip-like help pop-ups used in forms 
  function formtooltip(el,flag){ 
    elem = document.getElementById(el); 
    if (flag) {  
      if (ie) { 
        elem.parentNode.parentNode.style.zIndex=1000; 
        elem.parentNode.parentNode.style.borderRight='0px solid #000'; 
        // ugly , yes .. but neccesary to avoid a small but very annoying bug in IE6 
      } 
      elem.style.visibility='visible'; 
    } 
    else { 
      if (ie) { 
        elem.parentNode.parentNode.style.zIndex=1; 
        elem.parentNode.parentNode.style.border='none'; 
      } 
      elem.style.visibility='hidden' }; 
  }


/****  plone_menu.js *****/

// Do *NOT* depend on this menu code, it *will* be rewritten in later versions
// of Plone. This is a quick fix that will be replaced with something more
// elegant later.

/*

/***  Mike Malloch hack for msie/5.0 push ***/

function hackPush(el){
	this[this.length] = el;
}

function hackPop(){
	var N = this.length - 1, el = this[N];
	this.length = N
	return el;
}

function hackShift(){
	var one = this[0], N = this.length;
	for (var i = 1; i < N; i++){
		this[i-1] = this[i];
	}
	this.length = N-1
	return one;
}

var testPushPop = new Array();

if (testPushPop.push){
}else{
	Array.prototype.push = hackPush
	Array.prototype.pop = hackPop
	Array.prototype.shift =hackShift;
}

// Code to determine the browser and version.

function Browser() {
    var ua, s, i;
    
    this.isIE = false; // Internet Explorer
    this.isNS = false; // Netscape
    this.version = null;
    
    ua = navigator.userAgent;
    
    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;
    }
}
var browser = new Browser();

// Code for handling the menu bar and active button.
var activeButton = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (browser.isIE){
    document.onmousedown = pageMousedown;
}else{
    document.addEventListener("mousedown", pageMousedown, true);
}

function pageMousedown(event) {
    
    var el;
    
    // If there is no active button, exit.
    
    if (activeButton == null){
        return;
        }
    
    // Find the element that was clicked on.
    
    if (browser.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 == activeButton){
        return
        };
    
    // If the element is not part of a menu, reset and clear the active
    // button.
    
    if (getContainerWith(el, "UL", "actionMenu") == null) {
        resetButton(activeButton);
        activeButton = null;
    }
}

function buttonClick(event, menuId) {
    
    var button;
    
    // Get the target button element.
    
    if (browser.isIE){
        button = window.event.srcElement;
    }else{
        if (event)
          button = event.currentTarget;
        else
          return false;
    }
    // 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.menu == null) {
        button.menu = document.getElementById(menuId);
        if (button.menu.isInitialized == null) {
            menuInit(button.menu);
        }
    }
    
    // Reset the currently active button, if any.
    
    if (activeButton != null){
        resetButton(activeButton);
        }
    // Activate this button, unless it was the currently active one.
    
    if (button != activeButton) {
        depressButton(button);
        activeButton = button;
    }else{
        activeButton = null;
    }
    return false;
}

function buttonMouseover(event, menuId) {

    var button;
    
    // Find the target button element.
    
    if (browser.isIE){
        button = window.event.srcElement;
    }else{
        button = event.currentTarget;
    }
    // If any other button menu is active, make this one active instead.
    
    if (activeButton != null && activeButton != button){
        buttonClick(event, menuId);
        }
}

function depressButton(button) {

    var x, y;
    
    // Update the button's style class to make it look like it's
    // depressed.
    
    button.className += " menuButtonActive";
    
    // Position the associated drop down menu under the button and
    // show it.
    
    x = getPageOffsetLeft(button);
    y = getPageOffsetTop(button) + button.offsetHeight;
    
    // For IE, adjust position.
    
    if (browser.isIE) {
        x += button.offsetParent.clientLeft;
        y += button.offsetParent.clientTop;
    }
    
    button.menu.style.left = x + "px";
    button.menu.style.top = y + "px";
    button.menu.style.visibility = "visible";
}

function resetButton(button) {

    // Restore the button's style class.
    
    removeClassName(button, "menuButtonActive");
    
    // Hide the button's menu, first closing any sub menus.
    
    if (button.menu != null) {
        closeSubMenu(button.menu);
        button.menu.style.visibility = "hidden";
    }
}

// Code to handle the menus and sub menus.

function menuMouseover(event) {
    
    var menu;
    
    // Find the target menu element.
    
    if (browser.isIE){
        menu = getContainerWith(window.event.srcElement, "UL", "actionMenu");
    }else{
        menu = event.currentTarget;
    }
    
    // Close any active sub menu.
    
    if (menu.activeItem != null){
        closeSubMenu(menu);
        }
}

function menuItemMouseover(event, menuId) {

    var item, menu, x, y;
    
    // Find the target item element and its parent menu element.
    
    if (browser.isIE){
        item = getContainerWith(window.event.srcElement, "LI", "menuItem");
    }else{
        item = event.currentTarget;
        menu = getContainerWith(item, "UL", "menu");
    }
    // Close any active sub menu and mark this one as active.
    
    if (menu.activeItem != null){
        closeSubMenu(menu);
        menu.activeItem = item;
    }
    
    // Highlight the item element.
    
    item.className += " menuItemHighlight";
    
    // Initialize the sub menu, if not already done.
    
    if (item.subMenu == null) {
        item.subMenu = document.getElementById(menuId);
        if (item.subMenu.isInitialized == null){
            menuInit(item.subMenu);
            }
    }
    
    // Get position for submenu based on the menu item.
    
    x = getPageOffsetLeft(item) + item.offsetWidth;
    y = getPageOffsetTop(item);
    
    // Adjust position to fit in view.
    
    var maxX, maxY;
    
    if (browser.isNS) {
        maxX = window.scrollX + window.innerWidth;
        maxY = window.scrollY + window.innerHeight;
    }
    else if (browser.isIE) {
        maxX = (document.documentElement.scrollLeft != 0 ? document.documentElement.scrollLeft : document.body.scrollLeft)
        + (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
        maxY = (document.documentElement.scrollTop != 0 ? document.documentElement.scrollTop : document.body.scrollTop)
        + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
    }
    maxX -= item.subMenu.offsetWidth;
    maxY -= item.subMenu.offsetHeight;
    
    if (x > maxX){
        x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth  + (menu.offsetWidth - item.offsetWidth));
        y = Math.max(0, Math.min(y, maxY));
    }
    // Position and show it.
    
    item.subMenu.style.left = x + "px";
    item.subMenu.style.top = y + "px";
    item.subMenu.style.visibility = "visible";
    
    // Stop the event from bubbling.
    
    if (browser.isIE){
        window.event.cancelBubble = true;
    }else{
        event.stopPropagation();
    }
}

function closeSubMenu(menu) {
    
    if (menu == null || menu.activeItem == null)
    return;
    
    // Recursively close any sub menus.
    
    if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
    }
    removeClassName(menu.activeItem, "menuItemHighlight");
    menu.activeItem = null;
}

// Code to initialize menus.

function menuInit(menu) {
    
    var itemList, spanList;
    var textEl, arrowEl;
    var itemWidth;
    var w, dw;
    var i, j;
    
    // For IE, replace arrow characters.
    
    if (browser.isIE) {
        menu.style.lineHeight = "2.5ex";
        spanList = menu.getElementsByTagName("SPAN");
        for (i = 0; i < spanList.length; i++)
        if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
    }
}

// Find the width of a menu item.

itemList = menu.getElementsByTagName("A");
if (itemList.length > 0){
    itemWidth = itemList[0].offsetWidth;
}else{
    return;
}
// For items with arrows, add padding to item text to make the
// arrows flush right.

for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("A");
    textEl = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
    if (hasClassName(spanList[j], "menuItemText")){
        textEl = spanList[j];
        }
    if (hasClassName(spanList[j], "menuItemArrow")){
        arrowEl = spanList[j];
        }
    }
    if (textEl != null && arrowEl != null){
    textEl.style.paddingRight = (itemWidth - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
    }
}

// Fix IE hover problem by setting an explicit width on first item of
// the menu.

if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
}

// Mark menu as initialized.

menu.isInitialized = true;
}

// General utility functions.

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

    function 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 removeClassName(el, name) {
    
    var i, curList, newList;
    
    if (el.className == null){
        return;
        }
    // Remove the given class name from the elements 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 getPageOffsetLeft(el) {

var x;

// Return the x coordinate of an element relative to the page.

x = el.offsetLeft;
if (el.offsetParent != null)
x += getPageOffsetLeft(el.offsetParent);

return x;
}

function getPageOffsetTop(el) {
    
    var y;
    
    // Return the x coordinate of an element relative to the page.
    
    y = el.offsetTop;
    if (el.offsetParent != null){
        y += getPageOffsetTop(el.offsetParent);
    }
    return y;
}

/**** plone_javascript.js ****/

// Heads up! August 2003  - Geir B�kholt
// This file now requires the javascript variable portal_url to be set 
// in the plone_javascript_variables.js file. Any other variables from Plone
// that you want to pass into these scripts should be placed there.


// The calendar popup show/hide:

    function showDay(date) {
        document.getElementById('day' + date).style.visibility = 'visible';
        return true;
    }    
    function hideDay(date) {
        document.getElementById('day' + date).style.visibility = 'hidden';
        return true;
    }

// Focus on error or tabindex=1

if (g_knflags_autoHiliteIDField){
    if (window.addEventListener) window.addEventListener("load",setFocus,false);
    else if (window.attachEvent) window.attachEvent("onload",setFocus);
}

function setFocus() {
    var xre = new RegExp(/\berror\b/);
    // Search only forms to avoid spending time on regular text
    for (var f = 0; (formnode = document.getElementsByTagName('form').item(f)); f++) {
        // Search for errors first, focus on first error if found
        for (var i = 0; (node = formnode.getElementsByTagName('div').item(i)); i++) {
            if (xre.exec(node.className)) {
                for (var j = 0; (inputnode = node.getElementsByTagName('input').item(j)); j++) {
                    inputnode.focus();
                    return;   
                }
            }
        }
        // If no error, focus on input element with tabindex 1
        for (var i = 0; (node = formnode.getElementsByTagName('input').item(i)); i++) {
            if (node.getAttribute('tabindex') == 1) {
                 node.focus();
                 return;   
            }
        }
    }
}

/********* Table sorter script *************/
// Table sorter script, thanks to Geir B�kholt for this.
// DOM table sorter originally made by Paul Sowden 

function compare(a,b)
{
    au = new String(a);
    bu = new String(b);

    if (au.charAt(4) != '-' && au.charAt(7) != '-')
    {
    var an = parseFloat(au)
    var bn = parseFloat(bu)
    }
    if (isNaN(an) || isNaN(bn))
        {as = au.toLowerCase()
         bs = bu.toLowerCase()
        if (as > bs)
            {return 1;}
        else
            {return -1;}
        }
    else {
    return an - bn;
    }
}



function getConcatenedTextContent(node) {
    var _result = "";
	  if (node == null) {
		    return _result;
	  }
    var childrens = node.childNodes;
    var i = 0;
    while (i < childrens.length) {
        var child = childrens.item(i);
        switch (child.nodeType) {
            case 1: // ELEMENT_NODE
            case 5: // ENTITY_REFERENCE_NODE
                _result += getConcatenedTextContent(child);
                break;
            case 3: // TEXT_NODE
            case 2: // ATTRIBUTE_NODE
            case 4: // CDATA_SECTION_NODE
                _result += child.nodeValue;
                break;
            case 6: // ENTITY_NODE
            case 7: // PROCESSING_INSTRUCTION_NODE
            case 8: // COMMENT_NODE
            case 9: // DOCUMENT_NODE
            case 10: // DOCUMENT_TYPE_NODE
            case 11: // DOCUMENT_FRAGMENT_NODE
            case 12: // NOTATION_NODE
                // skip
                break;
        }
        i ++;
    }
  	return _result;
}



function sort(e) {
    var el = window.event ? window.event.srcElement : e.currentTarget;

    // a pretty ugly sort function, but it works nonetheless
    var a = new Array();
    // check if the image or the th is clicked. Proceed to parent id it is the image
    // NOTE THAT nodeName IS UPPERCASE
    if (el.nodeName == 'IMG') el = el.parentNode;
    //var name = el.firstChild.nodeValue;
    // This is not very robust, it assumes there is an image as first node then text
    var name = el.childNodes.item(1).nodeValue;
    var dad = el.parentNode;
    var node;
    
    // kill all arrows
    for (var im = 0; (node = dad.getElementsByTagName("th").item(im)); im++) {
        // NOTE THAT nodeName IS IN UPPERCASE
        if (node.lastChild.nodeName == 'IMG')
        {
            lastindex = node.getElementsByTagName('img').length - 1;
            node.getElementsByTagName('img').item(lastindex).setAttribute('src',portal_url + '/arrowBlank.gif');
        }
    }
    
    for (var i = 0; (node = dad.getElementsByTagName("th").item(i)); i++) {
        var xre = new RegExp(/\bnosort\b/);
        // Make sure we are not messing with nosortable columns, then check second node.
        if (!xre.exec(node.className) && node.childNodes.item(1).nodeValue == name) 
        {
            //window.alert(node.childNodes.item(1).nodeValue;
            lastindex = node.getElementsByTagName('img').length -1;
            node.getElementsByTagName('img').item(lastindex).setAttribute('src',portal_url + '/arrowUp.gif');
            break;
        }
    }

    var tbody = dad.parentNode.parentNode.getElementsByTagName("tbody").item(0);
    for (var j = 0; (node = tbody.getElementsByTagName("tr").item(j)); j++) {

        // crude way to sort by surname and name after first choice
        a[j] = new Array();
        a[j][0] = getConcatenedTextContent(node.getElementsByTagName("td").item(i));
        a[j][1] = getConcatenedTextContent(node.getElementsByTagName("td").item(1));
        a[j][2] = getConcatenedTextContent(node.getElementsByTagName("td").item(0));		
        a[j][3] = node;
    }

    if (a.length > 1) {
	
        a.sort(compare);

        // not a perfect way to check, but hell, it suits me fine
        if (a[0][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(0).getElementsByTagName("td").item(i))
	       && a[1][0] == getConcatenedTextContent(tbody.getElementsByTagName("tr").item(1).getElementsByTagName("td").item(i))) 
        {
            a.reverse();
            lastindex = el.getElementsByTagName('img').length - 1;
            el.getElementsByTagName('img').item(lastindex).setAttribute('src', portal_url + '/arrowDown.gif');
        }

    }
	
    for (var j = 0; j < a.length; j++) {
        tbody.appendChild(a[j][3]);
    }
}
    
function init(e) {
    var tbls = document.getElementsByTagName('table');
    for (var t = 0; t < tbls.length; t++)
        {
        // elements of class="listing" can be sorted
        var re = new RegExp(/\blisting\b/)
        // elements of class="nosort" should not be sorted
        var xre = new RegExp(/\bnosort\b/)
        if (re.exec(tbls[t].className) && !xre.exec(tbls[t].className))
        {
            try {
                var tablename = tbls[t].getAttribute('id');
                var thead = document.getElementById(tablename).getElementsByTagName("thead").item(0);
                var node;
                // set up blank spaceholder gifs
                blankarrow = document.createElement('img');
                blankarrow.setAttribute('src', portal_url + '/arrowBlank.gif');
                blankarrow.setAttribute('height',6);
                blankarrow.setAttribute('width',9);
                // the first sortable column should get an arrow initially.
                initialsort = false;
                for (var i = 0; (node = thead.getElementsByTagName("th").item(i)); i++) {
                    // check that the columns does not have class="nosort"
                    if (!xre.exec(node.className)) {
                        node.insertBefore(blankarrow.cloneNode(1), node.firstChild);
                        if (!initialsort) {
                            initialsort = true;
                            uparrow = document.createElement('img');
                            uparrow.setAttribute('src', portal_url + '/arrowUp.gif');
                            uparrow.setAttribute('height',6);
                            uparrow.setAttribute('width',9);
                            node.appendChild(uparrow);
                        } else {
                            node.appendChild(blankarrow.cloneNode(1));
                        }
    
                        if (node.addEventListener) node.addEventListener("click",sort,false);
                        else if (node.attachEvent) node.attachEvent("onclick",sort);
                    }
                }
            } catch(er) {}
        }
    }
}

// initialize the sorter functions 
// add stuff to secure it from broken DOM-implanetations or missing objects.
   
    
    	
//    p.appendChild(document.createTextNode("Change sorting by clicking on each individual heading."));
//    document.getElementById(tablename).parentNode.insertBefore(p,document.getElementById(tablename));
    

if (window.addEventListener) window.addEventListener("load",init,false);
else if (window.attachEvent) window.attachEvent("onload",init);

       
// **** End table sort script ***



// Actions used in the folder_contents view

function submitFolderAction(folderAction) {
    document.folderContentsForm.action = document.folderContentsForm.action+'/'+folderAction;
    document.folderContentsForm.submit();
}

function submitFilterAction() {
    document.folderContentsForm.action = document.folderContentsForm.action+'/folder_contents';
    filter_selection=document.getElementById('filter_selection');
    for (var i =0; i < filter_selection.length; i++){
        if (filter_selection.options[i].selected) {
            if (filter_selection.options[i].value=='#') {
                document.folderContentsForm.filter_state.value='clear_view_filter';
            }
            else {
                document.folderContentsForm.filter_state.value='set_view_filter';
            }
        }						
    }
    document.folderContentsForm.submit();
}
    

// Functions for selecting all checkboxes in folder_contents/search_form view

function selectAll(id, formName) {
  // get the elements. if formName is p rovided, 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 donot 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);
  }
}


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

// script for detecting external links.
// sets their target-attribute to _blank , and adds a class external

function scanforlinks(){
    // securing against really old DOMs 
    
    if (! document.getElementsByTagName){return false};
    if (! document.getElementById){return false};
    // Quick utility function by Geir B�kholt
    // Scan all links in the document and set classes on them dependant on 
    // whether they point to the current site or are external links
    
    contentarea = document.getElementById('content')
    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.indexOf(window.location.protocol+'//'+window.location.host)==0){
                // we are here because the link is an absolute pointer 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 ot other snacks
                // add tests for all relevant protocols as you like.
                
                protocols = ['mailto', 'ftp', 'news', 'irc', 'h323', 'sip', 'callto', 'https']
                // h323, sip and callto are internet telephony VoIP protocols
                
                for (p=0; p < protocols.length; p++){  
                     if (linkval.indexOf(protocols[p]+':') == 0){
                    // this link matches the protocol . add a classname protocol+link
                    //links[i].className = 'link-'+protocols[p]
                    wrapNode(links[i], 'span', 'link-'+protocols[p])
                    }
                }
            }else{
                // we are in here if the link points to somewhere else than our site.
                if ( links[i].getElementsByTagName('img').length == 0 ){
                    //links[i].className = 'link-external'
                    wrapNode(links[i], 'span', 'link-external')
                    links[i].setAttribute('target','_blank')
                    }
                
                
                
                
            }
        }
    }
}

if (g_pref_scan_links){
    if (window.addEventListener) window.addEventListener("load",scanforlinks,false);
    else if (window.attachEvent) window.attachEvent("onload",scanforlinks);
}

function climb(node, word){
	 // traverse childnodes
    if (node.hasChildNodes) {
		var i;
		for (i=0;i<node.childNodes.length;i++) {
            climb(node.childNodes[i],word);
		}
        if (node.nodeType == 3){
            checkforhighlight(node, word);
           // check all textnodes. Feels inefficient, but works
        }
}
function checkforhighlight(node,word) {
        ind = node.nodeValue.toLowerCase().indexOf(word.toLowerCase())
		if (ind != -1) {
            if (node.parentNode.className != "highlightedSearchTerm"){
                par = node.parentNode;
                contents = node.nodeValue;
			
                // make 3 shiny new nodes
                hiword = document.createElement("span");
				hiword.className = "highlightedSearchTerm";
				hiword.appendChild(document.createTextNode(contents.substr(ind,word.length)));
				
                par.insertBefore(document.createTextNode(contents.substr(0,ind)),node);
				par.insertBefore(hiword,node);
				par.insertBefore(document.createTextNode(contents.substr(ind+word.length)),node);

                par.removeChild(node);
		        }
        	} 
		}
  
}


function correctPREformatting(){
        // small utility thing to correct formatting for PRE-elements and some others
        // thanks to Michael Zeltner for CSS-guruness and research ;) 
        contentarea = document.getElementById('content')
        if (! contentarea){return false}
        
        pres = contentarea.getElementsByTagName('pre');
        for (i=0;i<pres.length;i++){
           wrapNode(pres[i],'div','visualOverflow')
		}
               
        tables = contentarea.getElementsByTagName('table');
        for (i=0;i<tables.length;i++){
           if (tables[i].className=="listing"){
           wrapNode(tables[i],'div','visualOverflow')
		   }
        }
        
}
// if (window.addEventListener) window.addEventListener("load",correctPREformatting,false);
// else if (window.attachEvent) window.attachEvent("onload",correctPREformatting);



function highlightSearchTerm() {
        // search-term-highlighter function --  Geir B�kholt
        query = window.location.search
        // _robert_ ie 5 does not have decodeURI 
        if (typeof decodeURI != 'undefined'){
            query = decodeURI(query)
        }
        else {
            return false
        }
        if (query){
            var qfinder = new RegExp()
            qfinder.compile("searchterm=(.*)","gi")
            qq = qfinder.exec(query)
            if (qq && qq[1]){
                query = qq[1]
                
                // the cleaner bit is not needed anymore, now that we travese textnodes. 
                //cleaner = new RegExp
                //cleaner.compile("[\\?\\+\\\\\.\\*]",'gi')
                //query = query.replace(cleaner,'')
                
                if (!query){return false}
                queries = query.replace(/\+/g,' ').split(/\s+/)
                
                // make sure we start the right place and not higlight menuitems or breadcrumb
                theContents = document.getElementById('bodyContent');
                if (theContents){
                    for (q=0;q<queries.length;q++) {
                        climb(theContents,queries[q]);
                    }
                }
            }
        }
}


if (window.addEventListener) window.addEventListener("load",highlightSearchTerm,false);
else if (window.attachEvent) window.attachEvent("onload",highlightSearchTerm);


// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
// ----------------------------------------------

function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
var style = readCookie("wstyle");
if (style != null) {
setActiveStyleSheet(style, 0);
}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/;";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

if (window.addEventListener) window.addEventListener("load",setStyle,false);
else if (window.attachEvent) window.attachEvent("onload",setStyle);





// jscalendar glue -- Leonard Norrg�rd <vinsci@*>
// This function gets called when the user clicks on some date.
function onJsCalendarDateUpdate(cal) {
    var year   = cal.params.input_id_year;
    var month  = cal.params.input_id_month;
    var day    = cal.params.input_id_day;
    // var hour   = cal.params.input_id_hour;
    // var minute = cal.params.input_id_minute;

    // cal.params.inputField.value = cal.date.print('%Y/%m/%d %H:%M'); // doesnot work in Opera, do not use time now
    //cal.params.inputField.value = cal.date.print('%Y/%m/%d'); // doesnot work in Opera
    var daystr = '' + cal.date.getDate();
    if (daystr.length == 1)
    	daystr = '0' + daystr;
    var monthstr = '' + (cal.date.getMonth()+1);
    if (monthstr.length == 1)
	monthstr = '0' + monthstr;
    cal.params.inputField.value = '' + cal.date.getFullYear() + '/' + monthstr + '/' + daystr

    year.value  = cal.params.inputField.value.substring(0,4);
    month.value = cal.params.inputField.value.substring(5,7);
    day.value   = cal.params.inputField.value.substring(8,10);
    // hour.value  = cal.params.inputField.value.substring(11,13);
    // minute.value= cal.params.inputField.value.substring(14,16);
}

// this funtion updates a hidden date filed with the current values of the widgets
function update_date_field(field,year,month,day,hour,minute) {
    var field  = document.getElementById(field);
    var date   = document.getElementById(date);
    var year   = document.getElementById(year);
    var month  = document.getElementById(month);
    var day    = document.getElementById(day);
    var hour   = document.getElementById(hour);
    var minute = document.getElementById(minute);
    if (year.value > 0) {
	field.value = year.value + "-" + month.value + "-" + day.value + " " + hour.options[hour.selectedIndex].value + ":" + minute.options[minute.selectedIndex].value;
    } else {
	field.value = '';
    }
}

function showJsCalendar(input_id_anchor, input_id, input_id_year, input_id_month, input_id_day, input_id_hour, input_id_minute, yearStart, yearEnd) {
    // do what jscalendar-x.y.z/calendar-setup.js:Calendar.setup would do
    var input_id_anchor = document.getElementById(input_id_anchor);
    var input_id = document.getElementById(input_id);
    var input_id_year = document.getElementById(input_id_year);
    var input_id_month = document.getElementById(input_id_month);
    var input_id_day = document.getElementById(input_id_day);
    // var input_id_hour = document.getElementById(input_id_hour);
    // var input_id_minute = document.getElementById(input_id_minute);
    var format = 'y/mm/dd';

    var dateEl = input_id;
    var mustCreate = false;
    var cal = window.calendar;

    var params = {
	'range' : [yearStart, yearEnd],
	inputField : input_id,
        input_id_year : input_id_year,
	input_id_month: input_id_month,
	input_id_day  : input_id_day
	// input_id_hour : input_id_hour,
	// input_id_minute: input_id_minute
    };

    function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };

    param_default("inputField",     null);
    param_default("displayArea",    null);
    param_default("button",         null);
    param_default("eventName",      "click");
    param_default("ifFormat",       "%Y/%m/%d");
    param_default("daFormat",       "%Y/%m/%d");
    param_default("singleClick",    true);
    param_default("disableFunc",    null);
    param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
    param_default("mondayFirst",    true);
    param_default("align",          "Bl");
    param_default("range",          [1900, 2999]);
    param_default("weekNumbers",    true);
    param_default("flat",           null);
    param_default("flatCallback",   null);
    param_default("onSelect",       null);
    param_default("onClose",        null);
    param_default("onUpdate",       null);
    param_default("date",           null);
    param_default("showsTime",      false);
    param_default("timeFormat",     "24");

    if (!window.calendar) {
	window.calendar = cal = new Calendar(true, //params.mondayFirst,
	     null,
	     onJsCalendarDateUpdate,
	     function(cal) { cal.hide(); });
	cal.time24 = true;
	cal.weekNumbers = true;
	mustCreate = true;
    } else {
	cal.hide();
    }
    cal.setRange(yearStart,yearEnd);
    cal.params = params;
    cal.setDateStatusHandler(null);
    cal.setDateFormat(format);
    if (mustCreate)
	cal.create();
    cal.parseDate(dateEl.value || dateEl.innerHTML);
    cal.refresh();
    cal.showAtElement(input_id_anchor, null);
    return false;
}

/******** KN pseudo-window script objects **********/




/**************************************************
 * drag script based on dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/
 
/*******  adapted by Mike Malloch ( theknownet.com ) to deal with resizing and other requirements of plone speedy sitemap/editing ****/

var psWin_i = 1;
var cur_RSWIN_obj = null, cur_winGrowBox = null;
var pendingPSWinObj = null;
var highest_z = 1100;



var pswin_html =  '<div id="panelBGtop" class="panelBGtop"><div id="panelBanner" class="panelBanner" style="width:649px;text-align:center;"></div><img src="pseudoWin_Images/top_left.png" width="50" height="40" /> '
    + '<img src="pseudoWin_Images/top_center.png" id="topmid_panelIMG" class="topmid_panelIMG"  width="569" height="40" /> '
    + '<img src="pseudoWin_Images/top_right.png" width="50" height="40" /></div><div id="panelBGmid" class="panelBGmid"> '
    + '<img src="pseudoWin_Images/left_center.png" id="midleft_panelIMG" class="midleft_panelIMG" width="50" height="320" /> '
    + '<img src="pseudoWin_Images/mid_center.png" id="midmid_panelIMG" class="midmid_panelIMG" width="569" height="320" /> '
    + '<img src="pseudoWin_Images/right_center.png" id="midright_panelIMG" class="midright_panelIMG" width="50" height="320" /></div>'
    + '<div id="panelBGbottom" class="panelBGbottom"> <img src="pseudoWin_Images/bottom_left.png" width="50" height="35" /> '
    + '<img src="pseudoWin_Images/bottom_center.png" id="botmid_panelIMG" class="botmid_panelIMG" width="569" height="35" /> '
    + '<img src="pseudoWin_Images/bottom_right.png" width="50" height="35" /></div>'
    + '<div id="panel_growbox" class="panel_growbox" style="left:8px;top:7px;width:649px;height:370px;">.</div>'
    + '<img src="pseudoWin_Images/grow_widget.png" id="panel_growWidget" class="panel_growWidget" style="top:363px;left:640px;" width="17" height="16" />'
    + '<iframe id="editFrame"  class="editFrame" style="border:none;padding:0;position:absolute;background:white;left:8px;top:41px;width:'
    + ( document.all? '655' : '649') + 'px;height:320px;" src="/empty.html"></iframe>'


if (portal_url) { // anchor images to the site root
    pswin_html = pswin_html.split('src="').join('src="' + portal_url + '/')
}


if (document.all){ // use ms proprietary filters for png alpha trans
    pswin_html = pswin_html.split('<img src="').join('<img src="pseudoWin_Images/single_pixel.gif" style="margin:0 -4px -4px 0;padding:0;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'')
    pswin_html = pswin_html.split('.png').join('.png\',sizingMethod=\'scale\');" ')
}

var staticWinHTML = '<div id="panelBGWrapper" class="panelBGWrapper" style="position:'
    + ( document.all? 'absolute' : 'fixed') + ';display:block;top:100px;left:100px;visibility:hidden;">' + pswin_html + '</div>'
var editorHTML = staticWinHTML.split('id="').join('id="psedit_')
var browseHTML = staticWinHTML.split('id="').join('id="sitemap_')


function ResizablePseudoWindow(left, top, useExisting, title, buttons, URL){ // useExisting arg doubles as prefix for distinguishing which instance
    left = left ? left : 100;
    top = top ? top : 100;
    
    this.prefix = useExisting ? useExisting : 'win_' + psWin_i++ + '_';
    this.title = title ? title : 'Untitled ' + psWin_i;
    this.buttons = buttons ? buttons : '';
    this.URL = URL ? URL : '/iframe_nocontent?nowrap=true';
    this.useExisting = useExisting ? 1 : 0;
	this.obj = null;
	this.objResizer = null;
	
	this.myVar = 'hello world';

    this.init = initPseudoWindow
    this.writeHTML = writePSwinHTML
    this.reUseWin = initReUseWindow; /// deprecated / obsolete ???
    this.refreshIFrame = refreshIFrameOO;
    this.placePanel = placePanelOO
    this.hide = hidePSWin
    
	this.initDrag = initDrag
	this.startDrag = startDrag;
	this.drag = drag;
	this.endDrag = endDrag;
	
	this.initResize = initResize
	this.startResize = startResize;
	this.resize = resize;
	this.endResize = endResize;
    
    if ( useExisting ) {
        this.init()
    }else {
        this.writeHTML(left, top, this.prefix)
    }
    
    return this;
}

function writePSwinHTML(left, top, prefix){

    var s = pswin_html.split('id="').join('id="' + prefix)
/*    var components = s.split('|'), k=0;
    var html = components[k++]
    html += left + components[k++]
    html += top + components[k++]
*/

//    document.test.htmltest.value = html

    var panelObj = document.createElement('div');
    
 //   panelObj.setAttribute('id',prefix + 'panelBGWrapper');
//    panelObj.id = prefix + 'panelBGWrapper'
    
    document.getElementById('content').appendChild(panelObj);
    
    panelObj.className = 'panelBGWrapper'
    panelObj.innerHTML = s;
    
    
    panelObj.style.position = document.all ? 'absolute' : 'fixed';
    panelObj.style.left = left + 'px';
    panelObj.style.top = top + 'px';
    
    this.panelObj = panelObj;
    pendingPSWinObj = this;
    
    var evalStr = "pendingPSWinObj.init();"
    
    setTimeout(evalStr,50);
   
}

function initPseudoWindow(){
    
    var p = this.prefix;

	this.panelBGWrapper = this.panelObj ? this.panelObj : document.getElementById(p + "panelBGWrapper")
	this.panelObj = this.panelBGWrapper;
	
    this.placePanel()
    
	this.topmid_panelIMG = document.getElementById(p + "topmid_panelIMG")
	this.panel_growWidget = document.getElementById(p + "panel_growWidget")
	this.panelBGtop = document.getElementById(p + "panelBGtop")
	this.midleft_panelIMG = document.getElementById(p + "midleft_panelIMG")
	this.midmid_panelIMG = document.getElementById(p + "midmid_panelIMG")
	this.midright_panelIMG = document.getElementById(p + "midright_panelIMG")
	this.botmid_panelIMG = document.getElementById(p + "botmid_panelIMG")
	this.panel_growbox = document.getElementById(p + "panel_growbox")
	this.editFrame = document.getElementById(p + "editFrame")
	this.panelBanner = document.getElementById(p + "panelBanner")
	this.panelBGWrapper.style.display='block';
	this.panelBGWrapper.style.visibility='visible';
	
	var s = '<i>' + this.title + '</i> ' + this.buttons

	this.panelBanner.innerHTML = s;

	this.initDrag(this.panelBGtop, this.panelBGWrapper, null, null, null, null, false, false);
    this.initResize(this.panel_growWidget, this.panelBGWrapper, null, null, null, null, false, false);

    
    this.refreshIFrame (this.URL)
    
}

function initReUseWindow(title, buttons, URL){

    
    var p = this.prefix;

    this.title = title ? title : 'Untitled ' + psWin_i;
    this.buttons = buttons ? buttons : '';
    this.URL = URL ? URL : '/iframe_nocontent?nowrap=true';
    	
	var s = '<i>' + this.title + '</i> ' + this.buttons

	this.panelBanner.innerHTML = s;

    this.refreshIFrame (this.URL)
    
}

function initDrag (o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper) {

	
		o.onmousedown	= this.startDrag;
		
		o.jsObj = this;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

/*
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
*/

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
}

function drag (e) {
	
		e = fixE(e);
		var o = cur_RSWIN_obj.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		o.root.style[o.hmode ? "left" : "right"] = nx + "px";
		o.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		o.lastMouseX	= ex;
		o.lastMouseY	= ey;

		o.root.onDrag(nx, ny);
		return false;
}


function startDrag (e) {
	
	
		var o = this.jsObj.obj = this;
		
		e = fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= this.jsObj.drag;
		document.onmouseup		= this.jsObj.endDrag;

        cur_RSWIN_obj = this.jsObj;
        
 /////       o.root.style.zindex = ++highest_z;
        
		return false;
}

function endDrag () {

	
		document.onmousemove = null;
		document.onmouseup   = null;
		cur_RSWIN_obj.obj.root.onDragEnd(	parseInt(cur_RSWIN_obj.obj.root.style[cur_RSWIN_obj.obj.hmode ? "left" : "right"]), 
									parseInt(cur_RSWIN_obj.obj.root.style[cur_RSWIN_obj.obj.vmode ? "top" : "bottom"]));
		cur_RSWIN_obj.obj = null;
		cur_RSWIN_obj = null
}



function initResize (o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
	    
		o.jsObj = this;
		
		setTimeout(";",1000);
		
		o.onmousedown	= this.startResize;
		
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onResizeStart	= new Function();
		o.root.onResizeEnd	= new Function();
		o.root.onResize		= new Function();
		
	}

function startResize (e) {

	window.status = 'start'
	/***** below are from the old beginDrag function *****/
	e= fixE(e)
	if(e.preventDefault) e.preventDefault();


	// Stores the current mouse position for further use.
	//
	window.lastX=e.clientX;
	window.lastY=e.clientY;

    cur_winGrowBox = this.jsObj.panel_growbox;
    
	window.lastLeftBeforeResize = parseInt(cur_winGrowBox.style.left);
	window.lastTopBeforeResize = parseInt(cur_winGrowBox.style.top);

	/***** above are from the old beginDrag function *****/
	

		var o = this.jsObj.objResizer = this;		
		e = fixE(e);
		
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onResizeStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= this.jsObj.resize;
		document.onmouseup	= this.jsObj.endResize;

        cur_winGrowBox.style.display = 'block';
        
        cur_RSWIN_obj = this.jsObj;
        
		return false;
}

function resize (e) {
	
	window.status = 'resize'
	
		e = fixE(e);
		var o = cur_RSWIN_obj.objResizer;

		var ey	= e.clientY;
		var ex	= e.clientX;
		
	        var difX=ex-o.lastMouseX;
	        var difY=ey-o.lastMouseY;	
	        
	        var lastLeftBeforeResize = parseInt(cur_winGrowBox.style.left);
	        var lastTopBeforeResize = parseInt(cur_winGrowBox.style.top);
		
		var newX1 = parseInt(o.style.left)+difX;
		var newY1 = parseInt(o.style.top)+difY;

		// Sets the new position 
		o.style.left=newX1+"px";
		o.style.top=newY1+"px";
		var newW = window.lastLeftBeforeResize + newX1
		var newH = window.lastTopBeforeResize + newY1
		cur_winGrowBox.style.width=newW+"px"
		cur_winGrowBox.style.height=newH+"px"
		
		
		
		o.lastMouseX	= ex;
		o.lastMouseY	= ey;

		o.root.onResize(ex, ey);
		return false;
}

function endResize () {
	
	window.status = 'end'

		document.onmousemove = null;
		document.onmouseup   = null;
		var o = cur_RSWIN_obj.objResizer;
		
		var ddx = parseInt(o.style.left) - window.lastLeftBeforeResize;
		var ddy = parseInt(o.style.top) - window.lastTopBeforeResize;

		var newW = ddx - 66
		var newH = ddy - 36

		var newIframeW = ddx+13;

		//editFrame

		newW = ""+newW+""
		newH = ""+newH+""

		// Dynamicallty set the width and height attributes of the component images - this spaces out the  panel

		cur_RSWIN_obj.topmid_panelIMG.setAttribute("width",newW);
		cur_RSWIN_obj.midmid_panelIMG.setAttribute("width",newW);
		cur_RSWIN_obj.botmid_panelIMG.setAttribute("width",newW);
		cur_RSWIN_obj.midleft_panelIMG.setAttribute("height",newH);
		cur_RSWIN_obj.midmid_panelIMG.setAttribute("height",newH);
		cur_RSWIN_obj.midright_panelIMG.setAttribute("height",newH);
		cur_RSWIN_obj.editFrame.style.width=newIframeW+"px"
		cur_RSWIN_obj.editFrame.style.height=newH+"px"
		
		cur_RSWIN_obj.panelBanner.style.width=newIframeW+"px"
		
            	
            	//hide the growbox after resize
        cur_winGrowBox.style.display='none';
            	
		o.root.onResizeEnd(	parseInt(o.root.style[o.hmode ? "left" : "right"]), 
									parseInt(o.root.style[o.vmode ? "top" : "bottom"]));
		cur_RSWIN_obj.objResizer = null;
		cur_RSWIN_obj = null;
		cur_winGrowBox = null;

}

function fixE (e) {

    if (typeof e == 'undefined') e = window.event;
    if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
    if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
    return e;
}


function refreshIFrameOO(URL){

    var IFrameObj = this.editFrame, IFrameDoc;

    if (IFrameObj.contentDocument) {
        // For NS6
        IFrameDoc = IFrameObj.contentDocument; 
    } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
        IFrameDoc = IFrameObj.contentWindow.document;
    } else if (IFrameObj.document) {
    // For IE5
        IFrameDoc = IFrameObj.document;
    } else {
        IFrameObj.src = URL
        return true;
    }
    
  IFrameDoc.location.replace(URL);
  
}

function hidePSWin() {
    this.panelObj.style.display='none'
}

function placePanelOO(showMe) {  // need to adapt to resizing when window is very small

   var availW, availH, scrollX = 0, scrollY = 0
   var obj = this.panelObj

   if(document.all){    /// ignoring this for now but may well want to shrink the editor to fit into avail w and h
      var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
      availW = iebody.clientWidth;
      availH = iebody.clientHeight;
      scrollX = iebody.scrollLeft;
      scrollY = iebody.scrollTop
      
   }else{
      availW = innerWidth;
      availH = innerHeight;
      scrollX = 0;  //  ignore because pos:fixed // document.documentElement.scrollLeft;
      scrollY = 0;  //  document.documentElement.scrollTop
   }
   
   
   obj.style.top = (scrollY + 10) + 'px'
   obj.style.left = (scrollX + 40) + 'px'
   
   
   if ( showMe )   obj.style.display='block';
   
}

var wininstances = new Array();
var userHasRequested = true;    //  false;


function addWin(){
    if (userHasRequested) { // the auto-created window is in use
        wininstances[wininstances.length] = new ResizablePseudoWindow(200,200, 0);
    }else{
        wininstances[0].usePSWin()
    }
    userHasRequested = true;
}

var siteMapWin = null

function invokeWinTest(prefix) {

        siteMapWin = new ResizablePseudoWindow(200,200, prefix,
            'a title for the thing'
            , '<a href="javascript:void(saveSearch())">Save</a>'
            , 'http://217.34.108.133:8080/ngrf/search_form?nowrap=true');
            

}

function reuseTest(title, URL) {

    siteMapWin.reUseWin(title,'<a href="javascript:void(saveSearch())">Close</a>', URL);

}

/******* from kn_editing.js - for panesFolderediting, with some out of date code for taking over edit links in general
    NB - needs upgrading to make comprehensively OO
*****/


var editPaneForm, editPaneSubmit, editPaneCancel, editPaneObj=null

var isEditingPanelsPage = false;
var isContentsPanelsPage = false;
var isWaitingForParentFreshContent = false;
var hasJustCancelled = false;
var isPropertyEditing = false;

window.hasEditInterface = true;




function editorTalkback(editForm, docRef, specialData){

    
    if (specialData && specialData.dataType && (specialData.dataType == 'panelsArrays' )) {
        panelLinkFileIDs = specialData.panelLinkFileIDs
        panelRowIDs = specialData.panelRowIDs
        panelColIDs = specialData.panelColIDs
    }
    
    if (hasJustCancelled){
        hasJustCancelled = false;
        return false;
    }
    if (isWaitingForParentFreshContent){
        var docNode = filterForClass('documentContent', docRef.getElementsByTagName('div'), 1)



/// pos remove dom node for status message <div class="portalMessage">   ????????


        var freshHTML = docNode.innerHTML;
        
        var parentDocNode = filterForClass('documentContent', document.getElementsByTagName('div'), 1)
        
        parentDocNode.innerHTML = freshHTML;
    
        dismissIFrame()
        
        window.setTimeout('toggleObjectEditing(0)', 200)
        
 //       document.getElementById('content').removeChild(editPaneObj); //// try to re-use this instead!!!
        isWaitingForParentFreshContent = false;
        return false;
    }
    
    if (editForm) {
    
        var newEl=docRef.createElement('input');
        newEl.setAttribute('type','text');
        newEl.setAttribute('name','nowrap');
        newEl.setAttribute('value','true');
        editForm.appendChild(newEl);
        editForm.action = editForm.action + '?nowrap=true'
        editPaneForm = editForm
        if (editForm['form.button.Save']) editPaneSubmit = editForm['form.button.Save']
        if (editForm['form.button.Cancel']) editPaneCancel = editForm['form.button.Cancel']
        editPane = docRef
        document.getElementById('knpanelSave').style.display='inline'
    }else if (isEditingPanelsPage) { // if no edit form, then save must have worked... get rid of iframe and refresh parent
        if (isContentsPanelsPage ) {
            document.getElementById('knpanelSave').style.display='none'
        } else {
           //////////////// **8 DEBUGGING **** 
           closeFrameRemote()
        }
    }else if (isEditingPSWin){
        closeFrameRemote()
    }
    

}


function getURLForPane( templateURL, rowId, pane_type ) {   // from JC
    var url = templateURL + '/addPane?rowId=' + rowId + '&pane_type=' + pane_type
    
//    alert( rowId )
    
    return url
}

function addRow( linkURL ) { 

    var idsInThisFldr = panelRowIDs, N = idsInThisFldr.length, i = (N+1), newID = 'row-' + i
    
    while ( isInArray(newID , idsInThisFldr)) newID = 'row-' + ++i
    
 //   idsInThisFldr[idsInThisFldr.length] = newID;    // update it
    
    var linkURL = linkURL + '&uId=' + newID + '&colId=col-1';
    openEditForPanel(linkURL)
}

function addPanel( templateURL, rowId, pane_type ) {   // from JC
    var linkURL = templateURL + '/addPane?rowId=' + rowId + '&pane_type=' + pane_type
    
    var idsInThisFldr = panelColIDs[rowId], N = idsInThisFldr.length, i = (N+1), newID = 'col-' + i
    
    while ( isInArray(newID , idsInThisFldr) ) newID = 'col-' + ++i
    
 //   idsInThisFldr[idsInThisFldr.length] = newID;    // update it
    
    var linkURL = linkURL + '&uId=' + newID;
    openEditForPanel(linkURL)
}


function dismissIFrame(){


////alert('Alan - this is just here to delay the closing of the sub-window');

    editPaneObj.hide()
    togglePanelEditing(true) // switch these to hide form elements under the iframe
}


var prevHilited = null, editTab = null;
var edit_ids = ['contentview-edit','contentview-metadata','contentview-local_roles'];
var edit_links = new Array(), edit_domTabs = new Array();
var stashedHTML = ''
var iframeWrapper = '<div id="editPanelWrap"><div id="editPanelBanner"><a href="javascript:void(closeFrame())">'
+ 'Close</a><a href="javascript:void(saveFrame())">'
+ 'Save</a><a href="javascript:void(cancelFrame())">Cancel</a>'
+ '</div><iframe id="editPanelEditor" src="'
+ '|?nowrap=true"/></div>';

iframeWrapper = iframeWrapper.split('|')

function takeOverEditLinks() {
    var j=0;
    for (var i=0; i< edit_ids.length; i++){
        var id = edit_ids[i];
        if (document.getElementById(id)){
            var a = filterForType('a', document.getElementById(id).childNodes, 1)
            edit_links[j] = a.href
            edit_domTabs[j] = document.getElementById(id);
            a.href = 'javascript:void(openEdit(' + j++ + '))'
        }
    }
}
/*
function openEdit(i){
    var contentBody = filterForClass( 'documentContent', document.getElementsByTagName('*'), 1)
    stashedHTML = contentBody.innerHTML;
    var s = iframeWrapper[0] + edit_links[i] + iframeWrapper[1]
    
    
    contentBody.innerHTML = s;
// try to hilite the tab
    editTab = edit_domTabs[i]
    var curHilite = filterForClass( 'selected', editTab.parentNode.childNodes, 1)
    if (curHilite){
      curHilite.className = 'plain'
      prevHilited = curHilite
    }
    editTab.className = 'selected'
}
*/
var psUtilWin = null, closeButton = '<a href="javascript:void(psUtilWin.hide())">Close</a>'


function openInPSWin(linkTitle, SRClink){

    var searchArgSep = (SRClink.indexOf('?') > -1) ? '&' : '?'
    SRClink += searchArgSep;
    
    if (psUtilWin) {
        psUtilWin.reUseWin(linkTitle,closeButton,SRClink + 'nowrap=true')
        psUtilWin.placePanel(true)
    }else{
        psUtilWin = new ResizablePseudoWindow(200,200, 'sitemap_', linkTitle
            , closeButton, SRClink + 'nowrap=true');
        
    }
}

function toggleObjectEditing(display){
    var newState = display ? 'block' : 'none';
    document.getElementById('mainObjectEdit').style.display = newState
    document.getElementById('hide-editing-main').style.display = newState
    document.getElementById('show-editing-main').style.display = display ? 'none' : 'block';

}

function togglePanelEditing(display){
    var newState = display ? 'block' : 'none';
    var newBorder = display ? '1px dotted gray' : 'none';
    var newBorderBottom = display ? '2px solid gray' : 'none';
    
    if (document.getElementById('hide-editing')){}
    else{
        return false;
    }
   
    document.getElementById('hide-editing').style.display = newState
    
    if ( ! display ) document.getElementById('mainObjectEdit').style.display = 'none'
    
    document.getElementById('show-editing').style.display = display ? 'none' : 'block';
    
    var allEls = document.all ? document.all : document.getElementsByTagName('*')
        
    var editLinks = filterForClass( 'panelEditLink', allEls)
    var toolbars = filterForClass( 'panelEditTools', document.getElementsByTagName('div'))
    var rows = filterForClass( 'panelRow', document.getElementsByTagName('div'))
    var linksEditing = filterForClass( 'panelEditItemTB', document.getElementsByTagName('span'))
    
    if (editLinks){
        for (var N=editLinks.length,i=N-1; i >=0; i--){
            editLinks[i].style.display = newState
        }
    }
    if (toolbars){
        for (var N=toolbars.length,i=0; i < N; i++){
            toolbars[i].style.display = newState
        }
    }
    if (linksEditing){
        for (var N=linksEditing.length,i=0; i < N; i++){
            linksEditing[i].style.display = (newState == 'block') ? 'inline' : newState
        }
    }
    
    if (rows){
        for (var N=rows.length,i=0; i < N; i++){
            rows[i].style.border = newBorder
            rows[i].style.borderBottom = newBorderBottom
        }
    }
}

function g_API_methodReturned(linkURL, errorStr){  /// ***** ONLY HERE UNTIL .PY FILE UPDATES !!!!

    g_API_methodReturned_object(linkURL, errorStr)
    
}

function g_API_methodReturned_object(linkURL, errorStr){   // called when method has created something

    if (errorStr){
        dismissIFrame()
        alert(errorStr)
    }else{
        openEditForPanel(linkURL)
    }
}

function g_API_methodReturned_deleted(statusStr, errorStr){     // called when method has deleted something

    if (errorStr){
        dismissIFrame()
        alert(errorStr)
    }else{
        closeFrameRemote()
    }
}

function deleteLinkFile(row, col, objID){

    if (confirm('Really delete this item?')){
        var linkURL = panelsBaseURL + '/deleteLinkOrFile?rowId=' + row + '&colId=' + col  + '&objid=' + objID;
        openEditForPanel(linkURL, 1)
    }
}


function isInArray(item, array){
    for (var i=0, N=array.length; i < N; i++){
//////        alert(item + ' ?= ' + array[i])
        if (array[i] == item) return true
    }
    return false;
}


function addLinkOrFile( row, col, obj_type ) { /// rowId, colId, obj_type
    
    var idsInThisFldr = panelLinkFileIDs[row][col], N = idsInThisFldr.length, i = (N+1), newID = obj_type + i
    
    while ( isInArray(newID , idsInThisFldr)) newID = obj_type + ++i
    
//    idsInThisFldr[idsInThisFldr.length] = newID;    // update it
    
    var linkURL = panelsBaseURL + '/addLinkOrFile?rowId=' + row + '&colId=' + col  + '&obj_type=' + obj_type + '&uId=' + newID;
    openEditForPanel(linkURL)
    
}

var commonPanelsButtons = '<a href="javascript:void(closeFrameRemote())">Close</a><a id="knpanelSave"  style="display:none;" href="javascript:void(saveFrameRemote())">Save</a>'
+ '<a href="javascript:void(cancelFrameRemote())">Cancel</a>'


function openEditForPanel(linkURL, noDisplay){  /**** WARNING CAN BE CALLED BY IFRAME-LOADED NEW PANES ******/


    if (linkURL.indexOf('deletePane?rowId=') > -1){
        if (! confirm('Really delete this pane?')){
            return false;
        }
    }
    if (linkURL.indexOf('deleteRow?rowId=') > -1){
        if (! confirm('Really delete this row?')){
            return false;
        }
    }

    var searchArgSep = (linkURL.indexOf('?') > -1) ? '&' : '?'

    var linkPath = linkURL.split('/'), linkTitle = linkPath[linkPath.length-2] + ' / ' + linkPath[linkPath.length-1]
    isContentsPanelsPage = false;
    var newSRClink
    
    if (linkURL.indexOf('createObject?type_name') > -1) {
        var baseLink = linkURL.split('createObject?type_name')[0]
        
        var redirLink = baseLink + 'redirectCreateRequest?url=' + escape(linkURL)
        
        newSRClink = redirLink + '&'
    }else{
        newSRClink = linkURL + searchArgSep
    }
    
    togglePanelEditing(false)
    if (editPaneObj) {
        editPaneObj.reUseWin(linkTitle,commonPanelsButtons,newSRClink + 'nowrap=true')
        if ((! noDisplay) && (newSRClink.indexOf('deletePane?rowId=') == -1)){
            editPaneObj.placePanel(true)
        }else{
            togglePanelEditing(1)
        }
    }else{
        editPaneObj = new ResizablePseudoWindow(200,200, 'psedit_', linkTitle
            , commonPanelsButtons, newSRClink + 'nowrap=true');
        
        isEditingPanelsPage = true;
    }
}

var isEditingPSWin = false


function editIndexFolderSubcontent(linkURL, title, type){
    var editForm = g_editFormsByType[type] ? g_editFormsByType[type] : 'base_edit';
    
    linkURL += '/' + editForm
    openEdit(linkURL, 'Edit ' + title)
}



function openEdit(linkURL, title){  /**** WARNING CAN BE CALLED BY IFRAME-LOADED NEW PANES ******/

    var searchArgSep = (linkURL.indexOf('?') > -1) ? '&' : '?'

    var linkPath = linkURL.split('/'), linkTitle = title ? title : (linkPath[linkPath.length-2] + ' / ' + linkPath[linkPath.length-1])
    isContentsPanelsPage = false;
    var newSRClink
    
    if (linkURL.indexOf('createObject?type_name') > -1) {
        var baseLink = linkURL.split('createObject?type_name')[0]
        
        var redirLink = baseLink + 'redirectCreateRequest?url=' + escape(linkURL)
        
       newSRClink = redirLink + '&obj_type=1&'
       
       
    }else{
        newSRClink = linkURL + searchArgSep
    }

    if (editPaneObj) {
        editPaneObj.reUseWin(linkTitle,commonPanelsButtons,newSRClink + 'nowrap=true')
        if ((! noDisplay) && (newSRClink.indexOf('deletePane?rowId=') == -1)){
            editPaneObj.placePanel(true)
        }else{
            togglePanelEditing(1)
        }
    }else{
        editPaneObj = new ResizablePseudoWindow(200,200, 'psedit_', linkTitle
            , commonPanelsButtons, newSRClink + 'nowrap=true');
        
        isEditingPSWin = true;
    }
}


function openContentsForPanel(linkURL) {
    openEditForPanel(linkURL)
    isContentsPanelsPage = true;

}



function closeFrame(){
    
    document.location.reload(0);
}


function saveFrame(){
    editPaneSubmit.click()
}


function refreshFromMethodCall(){

    closeFrameRemote();

}

function cancelFrame(){

    editPaneCancel.click()
    var contentBody = filterForClass( 'documentContent', document.getElementsByTagName('*'), 1)
    contentBody.innerHTML = stashedHTML;
    editTab.className = 'plain';
    prevHilited.className = 'selected';
}




function closeFrameRemote(){

    if (isEditingPanelsPage){
    
    
    
  ////  alert('isEditingPanelsPage')
    
    
        var parentPath = panelsBaseURL + '/panesfolder_edit_form'; ////// NB thisdepends on js executing as the panelpage loads!  **** document.location.href
/*        
        var parPathStatusCheck = parentPath.split('portal_status_message')
        if (parPathStatusCheck.length > 1){ // strip out the status message  
        }
*/     
        
        var searchArgSep = (parentPath.indexOf('?') > -1) ? '&' : '?'
        var refreshURL = parentPath + searchArgSep + 'nowrap=true';
        refreshURL = refreshURL.split('/'+searchArgSep).join(searchArgSep)
        
        ///////document.getElementById('editPanelEditor').src = refreshURL
        editPaneObj.refreshIFrame(refreshURL)
        isWaitingForParentFreshContent = true;
        
    }else if (isEditingPSWin){
    
    
/////    alert('isEditingPSWin')
    
    
        document.location.reload(0);
    }
}

function saveFrameRemote(){
    editPaneSubmit.click()
}

function cancelFrameRemote(){

   if (! isContentsPanelsPage ){
       hasJustCancelled = true;
       if ( editPaneCancel ) editPaneCancel.click();
   }
        dismissIFrame()
}


function filterForType(aType, aNodeList, firstEl){
	var aType = new String(aType);
	aType=aType.toLowerCase();
	var filteredNodeList = new Array();
	if(!(aNodeList.length > 0)){return filteredNodeList}
	for(var i=0; i<aNodeList.length; i++){
		var nodeString = new String(aNodeList[i].nodeName);
		nodeString = nodeString.toLowerCase();
		if(nodeString == aType){
			filteredNodeList[filteredNodeList.length] = aNodeList[i];
//			filteredNodeList.push(aNodeList[i]);
		}
	}
	if (firstEl){
		if(filteredNodeList.length > 0) return filteredNodeList[0]
		else return null;
	}
	return filteredNodeList;
}

function filterForClass(aClass, aNodeList, firstEl){
	var aClass = new String(aClass);
	aClass=aClass.toLowerCase();
	var filteredNodeList = new Array();
	if(!(aNodeList.length > 0)){return filteredNodeList}
	for(var i=0; i<aNodeList.length; i++){
		var nodeString = new String(aNodeList[i].className);
		nodeString = nodeString.toLowerCase();
		if(nodeString == aClass){
			filteredNodeList[filteredNodeList.length] = aNodeList[i];
//			filteredNodeList.push(aNodeList[i]);
		}
	}
	if (firstEl){
		if(filteredNodeList.length > 0) return filteredNodeList[0]
		else return null;
	}
	return filteredNodeList;
}



/*** customising the scan for links from plone_javascript.js *****/

/**** MIM apr 13 04 --- this looks inert to me!! ****/

function scanforlinks(){
    // securing against really old DOMs 
    
    if (! document.getElementsByTagName){return false};
    if (! document.getElementById){return false};
    // Quick utility function by Geir B�kholt
    // Scan all links in the document and set classes on them dependant on 
    // whether they point to the current site or are external links
    
    contentarea = document.getElementById('content')
    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.indexOf(window.location.protocol+'//'+window.location.host)==0){
                // we are here because the link is an absolute pointer 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 ot other snacks
                // add tests for all relevant protocols as you like.
                
                protocols = ['mailto', 'ftp', 'news', 'irc', 'h323', 'sip', 'callto', 'https']
                // h323, sip and callto are internet telephony VoIP protocols
                
                for (p=0; p < protocols.length; p++){  
                     if (linkval.indexOf(protocols[p]+':') == 0){
                    // this link matches the protocol . add a classname protocol+link
                    //links[i].className = 'link-'+protocols[p]
                    wrapNode(links[i], 'span', 'link-'+protocols[p])
                    }
                }
            }else{
                // we are in here if the link points to somewhere else than our site.
                if ( links[i].getElementsByTagName('img').length == 0 ){
                    //links[i].className = 'link-external'
                    wrapNode(links[i], 'span', 'link-external')
                    links[i].setAttribute('target','_blank')
                    }
                
                
                
                
            }
        }
    }
}


/******

Mike Malloch, KnowNet, May 26 2003 - adapted for plone use oct 1 2003, adapted for indexFolders may 2004

******/

var hashIn = document.location.hash, useHash = false;

if(hashIn && (hashIn != '')) useHash = hashIn.indexOf('#') > -1 ? hashIn.split('#')[1] : hashIn;

//  experiments for automatic generation of TOC nopavigation from dom-traversal of <hn> nodes


var is_First_TOC_head_element = true;

function getTextForElement(obj) {

if (is_First_TOC_head_element){
    is_First_TOC_head_element = false;
    return 'Table of Contents (click the box to the left to show/hide; click titles to go to sections)';
}

if (obj.innerText){
	return obj.innerText;
}


 var str=""
 for (var i=0;i < obj.childNodes.length;i++) {
  if (obj.childNodes[i].nodeType==1)
   str+=getTextForElement(obj.childNodes[i])
  else if (obj.childNodes[i].nodeType==3)
   str = obj.childNodes[i].data
 }
 return str
}

var g_defaultItemDisplay = 'none'; // 'block' //// 	CHANGE THIS TO SHOW OR HIDE OUTLINE NAV AT DOCUMENT LOAD

var g_firstToggleDisplay = g_defaultItemDisplay == 'none' ?  'block' :  'none';

var g_doNotShowTOCIfFewerThan = 4; // ONLY SHOW TOC IF THERE ARE AT LEAST THIS MANY HEADS

var hackIEid = 0, headIDnum = 0;

function addOneToggler(obj){
	var childObj = document.createElement("a");
	if (document.all){///// && childObj.attachEvent){
		var id = 'hackID_' + hackIEid++;
		childObj.setAttribute("id", id)
		childObj.setAttribute("href","javascript:void(ieHackToggleNav('" + id + "'))");
	
	}else{
		childObj.setAttribute("href","click_to_show_or_hide_subsection_navigation");
		childObj.setAttribute("onclick","toggleNav(this); return false")
	}
	
	childObj.setAttribute("title","show or hide subsection navigation");
	childObj.className = "toggle";
	
	var childIMGObj = document.createElement("img");
	childIMGObj.setAttribute("src","/doc_ui_imgs/ol_" + g_defaultItemDisplay + ".gif");
	childIMGObj.setAttribute("alt","show or hide subsection navigation");
	
	childIMGObj.setAttribute("border",0);
	
	childObj.appendChild(childIMGObj)
	
	obj.insertBefore(childObj, obj.childNodes[0])
	
	obj.className = "toggler";

}


function ieHackToggleNav(id){
	
//	var event = window.Event;
	var el = document.getElementById(id)
//	alert(el)
	toggleNav(el)
}

function toggleNav(obj){

	var op = obj.parentNode, ulobj = filterForType('UL', op.childNodes, 1)
	
	var newDisplay = (ulobj.style.display == g_firstToggleDisplay ) ? g_defaultItemDisplay : g_firstToggleDisplay;

	ulobj.style.display = newDisplay;

	obj.childNodes[0].src = '/doc_ui_imgs/ol_' + newDisplay + '.gif';

}


function Heading(level){

	this.level = level;
	this.ul = document.createElement("UL");
	
	this.ul.style.display = g_defaultItemDisplay;
}

/////var HACK_SHOW_DEBUG = (document.location.href.indexOf('http://81.4.66.124:8080/ngrf/Members/admin/about-us') > -1)

function getHeaders() {

//	var mainContent = document.getElementById('mainContent')
	
	var mainContent = filterForClass('documentContent', document.getElementsByTagName('div'), 1)


//	var obj = document.getElementsByTagName("*")
	var obj = mainContent.getElementsByTagName("*")

	if (obj.length == 0){	//	navigator.userAgent.indexOf('Safari') >= 0) { // ie/win5.5 also no '*' tags
        if (document.all) obj = mainContent.all
	}

	var nHeads = 0;
	for (var i=1,c=0;i<7;i++){
	    nHeads += mainContent.getElementsByTagName("H" + i).length	    
	}
	
	
	if (nHeads < g_doNotShowTOCIfFewerThan) return false;
	
	
	nHeads = 0;
 
	var el = document.createElement("UL"), topEl = el, prevEl = null, prevHead = null;
//	var tagList = "H2;H3;H4;H5;H6;";
	var tagList = "H1;H2;H3;H4;H5;H6;";
	var prevLevel=0, level, eLI, popEl = [el], popLevel = [0]; // new Array(), popLevel = [0];
	var prevHeadsNextLink = null;

	for (var i=0;i < obj.length;i++){
	
		var oneHead = obj[i];
		
		level = tagList.indexOf(oneHead.tagName+";")
		
		if (level >= 0) {
		
		nHeads++;

		if(prevHead == oneHead) continue;	//// moz and ie/win seem to list everything twice???
		
			var hid = oneHead.tagName + '_' + headIDnum++
			if (level > prevLevel) {
			
				popEl.push(el);
				popLevel.push(level);	//	prevLevel)
				var ul1 = document.createElement("UL")
				
				ul1.style.display = g_defaultItemDisplay;
				
				if (prevEl){
					addOneToggler(prevEl)
					prevEl.appendChild(ul1)
				}
			

	//			el.appendChild(ul1)
	
				el = ul1;
			}
			
			
			if (level < prevLevel) {
				while (level < popLevel[popLevel.length-1]) {
					popLevel.pop()
					el = popEl.pop();
				}
			}
		  
		
			prevLevel = level;
			
			var eLIText = document.createTextNode(getTextForElement(oneHead))
			
			if (oneHead.id){
				hid = oneHead.id
			}else{
				oneHead.id = hid
			}
			
			
			
			var aEL = document.createElement("a");
			aEL.setAttribute("href", '#' + hid);
			aEL.setAttribute("title", 'Click to scroll to this section');
			aEL.className = 'olNavLink'
			
			eLI = document.createElement("LI")
			eLI.className="noToggle"
			
			
			var childIMGObj = document.createElement("img");
			childIMGObj.setAttribute("src","/doc_ui_imgs/darkBUFF_SQUARE.gif");
			childIMGObj.setAttribute("alt","marker icon");
			childIMGObj.setAttribute("border",0);
			childIMGObj.className="noToggleIMG"
			
			eLI.appendChild(childIMGObj)
	
			aEL.appendChild(eLIText)
			

// add prev/next/up nav links in the headers

			if (prevHead){	// add nav links, etc - not for top-level, so will always be both prev/next
				oneHead.prev = prevHead.id;
				prevHead.next = oneHead.id;
				
				if (prevHeadsNextLink) prevHeadsNextLink.setAttribute("href", '#' + hid);
				
				prevHeadsNextLink = document.createElement("a");
				prevHeadsNextLink.setAttribute("href", '#' + hid);
				prevHeadsNextLink.setAttribute("title", 'Click to scroll to the next section');
				prevHeadsNextLink.className = 'innerNavNext';
				
		
				oneHead.parentNode.insertBefore(prevHeadsNextLink, oneHead.nextSibling)
					
				
				linkEl = document.createElement("a");
				linkEl.setAttribute("href", '#' + prevHead.id);
				linkEl.setAttribute("title", 'Click to scroll to the previous section');
				linkEl.className = 'innerNavPrev';
				
				oneHead.parentNode.insertBefore(linkEl, oneHead.nextSibling)
		
		
				
				linkEl = document.createElement("a");
				linkEl.setAttribute("href", '#' + obj[0].id);
				linkEl.setAttribute("title", 'Click to scroll to top of document');
				linkEl.setAttribute("onclick", 'scrollTo(0,0);return false;');
				linkEl.className = 'innerNavTop';
				
				
				oneHead.insertBefore(linkEl, oneHead.firstChild)
				
	//			oneHead.parentNode.insertBefore(linkEl, oneHead.nextSibling)
				
			}
			
			eLI.appendChild(aEL)
			
			el.appendChild(eLI)
			prevHead = oneHead;
			prevEl = eLI;
		}
	}
	
if( nHeads < 2 ) return false;


 return topEl
}

function ie_getElementsByTagName(str) {
 if (str=="*")
  return document.all
 else
  return document.all.tags(str)
}

if (document.all)
 document.getElementsByTagName = ie_getElementsByTagName

function add_js_InnerNav() {

	var mainContent = filterForClass('documentContent', document.getElementsByTagName('div'), 1)
    var nHead_2 = mainContent.getElementsByTagName("H2").length	
    
    if (nHead_2 < 3) return 0;

 var el = getHeaders()
 
 if (el){
 
	 var startEl = document.getElementById("nav_test")
	 if (startEl) {
        // startEl.insertBefore(el,startEl.childNodes[0])
        startEl.appendChild(el)
        
        if (useHash && (navigator.userAgent.indexOf('Safari') >= 0)){
            var hashEl = document.getElementById(useHash)
            var newY = getPageOffsetTop(hashEl)
            scrollTo(0, newY)
            return false; // hash traversal repeats endlessly - does not support scrollIntoView
        }
    }
    if (useHash) siv(useHash, 1);    //  document.location.hash = useHash;

    }
    
}

function siv(nm,top){
  if(document.getElementById){
    var element=document.getElementById(nm);
    if(element && element.scrollIntoView){
      element.scrollIntoView(top);
    }
  }
}