// Global Plone variables that need to be accessible to the Javascripts

/* <!-- compression status: 1 --> (this is for http compression) */

portal_url = 'http://test.inpm.ro';

// 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 ie4=document.all
var ns6=document.getElementById&&!document.all
var ns4=document.layers

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;
    document.onkeydown = pageMousedown;
}else{
    document.addEventListener("mousedown", pageMousedown, true);
    document.addEventListener("keydown", 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 buttonShowMenu(event, menuId) {
    var button;
    
    // Find the target button element.
    
    if (browser.isIE){
        button = window.event.srcElement;
    }else{
        button = event.currentTarget;
    }
    clearHideMenu()
    
    // 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, button.menu);
        }
    }
    
    // Reset the currently active button, if any.
    if (activeButton != null && button != activeButton) 
        resetButton(activeButton);

    // Activate this button, unless it was the currently active one.
    if (button != activeButton) {
        depressButton(button);
        activeButton = button;
    }
    return false;
}

function contains_ns6(a, b) {
    //Determines if 1 element in contained in another- by Brainjar.com
    while (b.parentNode)
        if ((b = b.parentNode) == a)
            return true;
    return false;
}

function hideMenu(menuId){
    var menu = ns6 ? document.getElementById(menuId) : ie4 ? document.all[menuId] : ns4 ? document.layers[menuId] : ""
    
    if (menu)
        activeButton = null;
        menu.style.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamicHide(e, menuId){
    
    var menu = ns6 ? document.getElementById(menuId) : ie4 ? document.all[menuId] : ns4 ? document.layers[menuId] : ""
    if (ie4&&!menu.contains(e.toElement)) 
        delayHideMenu(menuId)
    else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) {
        delayHideMenu(menuId);
    }
}

function delayHideMenu(menuId){
    if (ie4||ns6||ns4) {
        delayhide=setTimeout("hideMenu('" + menuId + "')",500)
    }
}

function clearHideMenu(){
    if (window.delayhide)
        clearTimeout(delayhide)
}

function depressButton(button) {

    var x, y;
    
    // Update the button's style class to make it look like it's
    // depressed.
    
    button.className += " menuButtonActive";
    
    // Make the associated drop down menu visible
    
    vis = button.menu.style.visibility;
    button.menu.style.visibility = (vis == "hidden" || vis == '') ? "visible" : "hidden";
}

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";
    }
}

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(button, 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.
    
    maxWidth = 0;
    
    for (i = 0; i < itemList.length; i++) {
        var w = itemList[i].offsetWidth;
        if (w) {
            if(w>maxWidth) maxWidth = w;
        }
        
        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.
    if (maxWidth != 'undefined' && maxWidth>0) {
        menu.style ? menu.style.width = maxWidth+"px" : menu.width = maxWidth;
    }
                        
    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 element's className property.
    
    newList = new Array();
    curList = el.className.split(" ");
    for (i = 0; i < curList.length; i++){
        if (curList[i] != name){
            newList.push(curList[i]);
            el.className = newList.join(" ");
        }
    }
}


function registerPloneFunction(func){
    // registers a function to fire onload. 
	// Turned out we kept doing this all the time
	// Use this for initilaizing any javascript that should fire once the page has been loaded. 
	// 
    if (window.addEventListener) window.addEventListener("load",func,false);
    else if (window.attachEvent) window.attachEvent("onload",func);   
  }

function unRegisterPloneFunction(func){
    // uregisters a previous function to fire onload. 
    if (window.removeEventListener) window.removeEventListener("load",func,false);
    else if (window.detachEvent) window.detachEvent("onload",func);   
  }

function getContentArea(){
	// to end all doubt on where the content sits. It also felt a bit silly doing this over and over in every
	// function, even if it is a tiny operation. Just guarding against someone changing the names again, in the name
	// of semantics or something.... ;)
	node =  document.getElementById('region-content')
	if (! node){
		node = document.getElementById('content')
		}
	return node
	}
function getPortlets() {
    portlets = new Array();
    left = document.getElementById('portal-column-one');
    right = document.getElementById('portal-column-two');
    if(left) {
        portlets.push(left)
    }
	if(right) {
        portlets.push(right)
    }
	return portlets
}

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)
}
  
function injectNode(node, injectedtype, injectedclass) {
    var injectednode = document.createElement(injectedtype)
    var injectedtext = document.createTextNode(String.fromCharCode(160));
    injectednode.appendChild(injectedtext);
    injectednode.className = injectedclass;
    node.parentNode.insertBefore(injectednode, node);
}


// 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 
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++) {
                    if (inputnode.type!='hidden' && inputnode.type!='submit')
                    {
                        inputnode.focus();
                        return;   
                    }
                }
            }
        }
        // If no error, focus on input element with tabindex 1
        
        
        // uncomment to reactivate
        // this part works as intended, but there are too many places where this function causes pain, moving 
        // focus away from a field in whuch the user is already typing
        
        //for (var i = 0; (node = formnode.getElementsByTagName('input').item(i)); i++) {
         //   if (node.getAttribute('tabindex') == 1) {
         //       node.focus();
         //        return;   
         //   }
        //}
    }
}
registerPloneFunction(setFocus)





/********* Table sorter script *************/
// Table sorter script, thanks to Geir Bokholt 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 initalizeTableSort(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) {}
        }
    }
}   
// **** End table sort script ***
registerPloneFunction(initalizeTableSort)   

// 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 Bokholt
    // 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 = getContentArea();
    portlets = getPortlets();
    if (! contentarea && portlets.length<=0){return false}

    var links = contentarea.getElementsByTagName('a');

    for (i=0; i < links.length; i++){      
        modifyLinkTag(links[i]);
    }

    for(i=0;i<portlets.length;i++) {
        var plinks = portlets[i].getElementsByTagName('a');
        for (j=0; j < plinks.length; j++){      
            modifyLinkTag(plinks[j]);
        }
    }
}
function modifyLinkTag(node) {
    linkname = node.getAttribute('name');
    if(linkname) {
        if(linkname.indexOf('navigationlink')==0 ) {
            return;
        }
    }
    if (node.getAttribute('href') && node.className.indexOf('link-plain')==-1 ){
        var linkval = node.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) {
            // 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
                    linkclass = 'link-'+protocols[p]
                    injectNode(node, 'span', linkclass+'-js')
                    if(node.className==linkclass||node.className==linkclass+'-js') {
                        node.removeAttribute('class');
                    }
                    break;
                }
            }
        } else {
            // we are in here if the link points to somewhere else than our site.
            if ( node.getElementsByTagName('img').length == 0 ){
				// we do not want to mess with those links that already have images in them
				injectNode(node, 'span', 'link-external-js');
                if(node.className=='link-external') {
                    node.className='';
                }
            }
/*
            if (node.getAttribute('onclick') == false){
               if (node.addEventListener) node.addEventListener("onclick",window.open(node.href), true);
               else if (node.attachEvent) node.attachEvent("onclick",window.open(node.href));
            }
*/
        }
        pathelems = linkval.split('/');
        filename = pathelems[pathelems.length-1];
        fileelems = filename.split('.');

        if(filename.indexOf('?')<0 && fileelems.length>1 && node.getElementsByTagName('img').length == 0) {
            ending = fileelems[fileelems.length-1].toLowerCase();
            endings = ['pdf', 'doc', 'xls', 'ppt', 'zip'];
            for (e=0; e < endings.length; e++){ 
                if (ending == endings[e]) {
                    linkclass = 'link-'+ending+'-js';
                    injectNode(node, 'span', linkclass);
                    break;
                }
            }
        }
        
    }
}
registerPloneFunction(scanforlinks)   


function climb(node, word){
	 // traverse childnodes
    if (! node){return false}
    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 ;) 
		// currently not activated
        contentarea = getContentArea();
        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')
		//  }
        //}      
}
//registerPloneFunction(correctPREformatting);

function highlightSearchTerm() {
        // search-term-highlighter function --  Geir Bokholt
        query = window.location.search
        // _robert_ ie 5 does not have decodeURI 
        if (typeof decodeURI != 'undefined'){
            query = unescape(decodeURI(query)) // thanks, Casper 
        }
        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
                contentarea = getContentArea();
				for (q=0;q<queries.length;q++) {
                                       // don't highlight reserved catalog search terms
                                       if (queries[q].toLowerCase() != 'not'
                                               && queries[q].toLowerCase() != 'and'
                                               && queries[q].toLowerCase() != 'or') {
                       climb(contentarea,queries[q]);
                                       }
                }
            }
        }
}
registerPloneFunction(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+"="+escape(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 unescape(c.substring(nameEQ.length,c.length));
  }
  return null;
}
registerPloneFunction(setStyle);

// simple Window opener

function openWindow(url, width, height, params) {
    var width;
    var height;
    if(!width) width="320";
    if(!height) height="450";
    if(!params) params = "scrollbars, resizable";
    paramstring = "width="+width+",height="+height+","+params;
    
    newWin = window.open(url,"newWindow",paramstring);
    newWin.focus();
} 

function evalKey(e, funcname, params) {
    var key ='';
    if(window.event || !e.which) {
        key = e.keyCode; // IE
    } else if(e) {
        key = e.which; // Netscape
    }
    if(key!=9 || e == undefined) {
        fstr = funcname+'(';
        for( i = 0; i<params.length; i++) {
            fstr += 'params['+String(i)+']';
            if(i<(params.length-1))
                fstr += ', ';
        }
        fstr += ')';
        eval(fstr);
    }
}

function gotoURL (x) {
    if (x=='') {
        document.forms['networkchooser'].reset();
        return;
    } else {
        if(x.substr(5, 11)=='http://') {
            loc = x;
        } else {
            loc = 'http://'+x;
        }
        window.location.href = loc
    }
}

