]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/generic.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1267 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / generic.js
index d469df7d067e62efdb4e79452a810e7d25e1dc70..ce7a12ed45171a4c42d9c14348d16ee1f19d6cc7 100644 (file)
@@ -27,11 +27,12 @@ var logWindow = null;
 
 var queryParameters;
 
-var activeAjaxRequests = 0;
 var menus = new Array();
 var search = {};
 var sorting = {};
 
+var lastClickedRow = -1;
+
 var weekStartIsMonday = true;
 
 // logArea = null;
@@ -40,6 +41,10 @@ var allDocumentElements = null;
 var userDefaults = null;
 var userSettings = null;
 
+// Ajax requests counts
+var activeAjaxRequests = 0;
+var removeFolderRequestCount = 0;
+
 /* a W3C compliant document.all */
 function getAllScopeElements(scope) {
   var elements = new Array();
@@ -106,26 +111,26 @@ function getElementsByClassName2(_tag, _class, _scope) {
 
 function createElement(tagName, id, classes, attributes, htmlAttributes,
                       parentNode) {
-   var newElement = $(document.createElement(tagName));
-   if (id)
-      newElement.setAttribute("id", id);
-   if (classes) {
-      if (typeof(classes) == "string")
-        newElement.addClassName(classes);
-      else
-        for (var i = 0; i < classes.length; i++)
-           newElement.addClassName(classes[i]);
-   }
-   if (attributes)
-      for (var i in attributes)
-        newElement[i] = attributes[i];
-   if (htmlAttributes)
-      for (var i in htmlAttributes)
-        newElement.setAttribute(i, attributes[i]);
-   if (parentNode)
-      parentNode.appendChild(newElement);
+  var newElement = $(document.createElement(tagName));
+  if (id)
+    newElement.setAttribute("id", id);
+  if (classes) {
+    if (typeof(classes) == "string")
+      newElement.addClassName(classes);
+    else
+      for (var i = 0; i < classes.length; i++)
+       newElement.addClassName(classes[i]);
+  }
+  if (attributes)
+    for (var i in attributes)
+      newElement[i] = attributes[i];
+  if (htmlAttributes)
+    for (var i in htmlAttributes)
+      newElement.setAttribute(i, htmlAttributes[i]);
+  if (parentNode)
+    parentNode.appendChild(newElement);
 
-   return $(newElement);
+  return $(newElement);
 }
 
 function ml_stripActionInURL(url) {
@@ -141,21 +146,22 @@ function ml_stripActionInURL(url) {
 }
 
 function URLForFolderID(folderID) {
-   var folderInfos = folderID.split(":");
-   var url;
-   if (folderInfos.length > 1) {
-      url = UserFolderURL + "../" + folderInfos[0];
-      if (folderInfos[1][0] != '/')
-        url += '/';
-      url += folderInfos[1];
-   }
-   else
-      url = ApplicationBaseURL + folderInfos[0];
+  var folderInfos = folderID.split(":");
+  var url;
+  if (folderInfos.length > 1) {
+    url = UserFolderURL + "../" + folderInfos[0];
+    if (!(folderInfos[0].endsWith('/')
+         || folderInfos[1].startsWith('/')))
+      url += '/';
+    url += folderInfos[1];
+  }
+  else
+    url = ApplicationBaseURL + folderInfos[0];
    
-   if (url[url.length-1] == '/')
-      url = url.substr(0, url.length-1);
+  if (url[url.length-1] == '/')
+    url = url.substr(0, url.length-1);
 
-   return url;
+  return url;
 }
 
 function extractEmailAddress(mailTo) {
@@ -174,59 +180,87 @@ function extractEmailAddress(mailTo) {
 function extractEmailName(mailTo) {
   var emailName = "";
 
-   var tmpMailTo = mailTo.replace("&lt;", "<");
-   tmpMailTo = tmpMailTo.replace("&gt;", ">");
+  var tmpMailTo = mailTo.replace("&lt;", "<");
+  tmpMailTo = tmpMailTo.replace("&gt;", ">");
 
-   var emailNamere = /([       ]+)?(.+)\ </;
-   if (emailNamere.test(tmpMailTo)) {
-      emailNamere.exec(tmpMailTo);
-      emailName = RegExp.$2;
-   }
+  var emailNamere = /([        ]+)?(.+)\ </;
+  if (emailNamere.test(tmpMailTo)) {
+    emailNamere.exec(tmpMailTo);
+    emailName = RegExp.$2;
+  }
    
-   return emailName;
+  return emailName;
 }
 
 function sanitizeMailTo(dirtyMailTo) {
-   var emailName = extractEmailName(dirtyMailTo);
-   var email = "" + extractEmailAddress(dirtyMailTo);
+  var emailName = extractEmailName(dirtyMailTo);
+  var email = "" + extractEmailAddress(dirtyMailTo);
    
-   var mailto = "";
-   if (emailName && emailName.length > 0)
-      mailto = emailName + ' <' + email + '>';
-   else
-      mailto = email;
+  var mailto = "";
+  if (emailName && emailName.length > 0)
+    mailto = emailName + ' <' + email + '>';
+  else
+    mailto = email;
 
-   return mailto;
+  return mailto;
 }
 
 function openUserFolderSelector(callback, type) {
-   var urlstr = ApplicationBaseURL;
-   if (urlstr[urlstr.length-1] != '/')
-      urlstr += '/';
-   urlstr += ("../../" + UserLogin + "/Contacts/userFolders");
-   var w = window.open(urlstr, "User Selector",
-                      "width=322,height=250,resizable=1,scrollbars=0");
-   w.opener = window;
-   w.userFolderCallback = callback;
-   w.userFolderType = type;
-   w.focus();
-}
-
-function openMailComposeWindow(url) {
-  var w = window.open(url, null,
+  var urlstr = ApplicationBaseURL;
+  if (! urlstr.endsWith('/'))
+    urlstr += '/';
+  urlstr += ("../../" + UserLogin + "/Contacts/userFolders");
+  var w = window.open(urlstr, "_blank",
+                     "width=322,height=250,resizable=1,scrollbars=0,location=0");
+  w.opener = window;
+  window.userFolderCallback = callback;
+  window.userFolderType = type;
+  w.focus();
+}
+
+function openContactWindow(url, wId) {
+  if (typeof wId == "undefined")
+    wId = "_blank";
+  else {
+    var r = new RegExp("[\.\/-]", "g");
+    wId = wId.replace(r, "_");
+  }
+
+  var w = window.open(url, wId,
+                     "width=450,height=600,resizable=0,location=0");
+  w.focus();
+
+  return w;
+}
+
+function openMailComposeWindow(url, wId) {
+  var parentWindow = this;
+
+  if (typeof wId == "undefined")
+    wId = "_blank";
+  else {
+    var r = new RegExp("[\.\/-]", "g");
+    wId = wId.replace(r, "_");
+    if (document.body.hasClassName("popup"))
+      parentWindow = window.opener;
+  }
+
+  var w = parentWindow.open(url, wId,
                       "width=680,height=520,resizable=1,scrollbars=1,toolbar=0,"
                       + "location=0,directories=0,status=0,menubar=0"
                       + ",copyhistory=0");
+
   w.focus();
 
   return w;
 }
 
 function openMailTo(senderMailTo) {
-   var mailto = sanitizeMailTo(senderMailTo);
-   if (mailto.length > 0)
-      openMailComposeWindow(ApplicationBaseURL
-                           + "/../Mail/compose?mailto=" + mailto);
+  var mailto = sanitizeMailTo(senderMailTo);
+
+  if (mailto.length > 0)
+    openMailComposeWindow(ApplicationBaseURL
+                         + "../Mail/compose?mailto=" + mailto);
 
   return false; /* stop following the link */
 }
@@ -260,7 +294,7 @@ function triggerAjaxRequest(url, callback, userdata) {
   var http = createHTTPClient();
 
   activeAjaxRequests += 1;
-  document.animTimer = setTimeout("checkAjaxRequestsState();", 200);
+  document.animTimer = setTimeout("checkAjaxRequestsState();", 50);
   //url = appendDifferentiator(url);
 
   if (http) {
@@ -268,26 +302,27 @@ function triggerAjaxRequest(url, callback, userdata) {
     http.url = url;
     http.onreadystatechange
       = function() {
-        //log ("state changed (" + http.readyState + "): " + url);
-        try {
-          if (http.readyState == 4
-              && activeAjaxRequests > 0) {
-                if (!http.aborted) {
-                  http.callbackData = userdata;
-                  callback(http);
-                }
-                activeAjaxRequests -= 1;
-                checkAjaxRequestsState();
-              }
-        }
-        catch( e ) {
-          activeAjaxRequests -= 1;
-          checkAjaxRequestsState();
-          log("AJAX Request, Caught Exception: " + e.name);
-          log(e.message);
-         log(backtrace());
-        }
-      };
+//       log ("state changed (" + http.readyState + "): " + url);
+      try {
+       if (http.readyState == 4
+           && activeAjaxRequests > 0) {
+         if (!http.aborted) {
+           if (userdata)
+             http.callbackData = userdata;
+           callback(http);
+         }
+         activeAjaxRequests -= 1;
+         checkAjaxRequestsState();
+       }
+      }
+      catch( e ) {
+       activeAjaxRequests -= 1;
+       checkAjaxRequestsState();
+       log("AJAX Request, Caught Exception: " + e.name);
+       log(e.message);
+       log(backtrace());
+      }
+    };
     http.send(null);
   }
   else {
@@ -297,19 +332,30 @@ function triggerAjaxRequest(url, callback, userdata) {
   return http;
 }
 
+function startAnimation(parent, nextNode) {
+  var anim = $("progressIndicator");
+  if (anim) return anim;
+  
+  anim = document.createElement("img");
+  anim = $(anim);
+  anim.id = "progressIndicator";
+  anim.src = ResourcesURL + "/busy.gif";
+  anim.setStyle({ visibility: "hidden" });
+  if (nextNode)
+    parent.insertBefore(anim, nextNode);
+  else
+    parent.appendChild(anim);
+  anim.setStyle({ visibility: "visible" });
+
+  return anim;
+}
+
 function checkAjaxRequestsState() {
   var toolbar = document.getElementById("toolbar");
   if (toolbar) {
     if (activeAjaxRequests > 0
         && !document.busyAnim) {
-      var anim = document.createElement("img");
-      anim = $(anim);
-      document.busyAnim = anim;
-      anim.id = "progressIndicator";
-      anim.src = ResourcesURL + "/busy.gif";
-      anim.setStyle({ visibility: "hidden" });
-      toolbar.appendChild(anim);
-      anim.setStyle({ visibility: "visible" });
+      document.busyAnim = startAnimation(toolbar);
     }
     else if (activeAjaxRequests == 0
             && document.busyAnim
@@ -320,6 +366,10 @@ function checkAjaxRequestsState() {
   }
 }
 
+function isSafari3() {
+  return (navigator.appVersion.indexOf("Version") > -1);
+}
+
 function isSafari() {
   //var agt = navigator.userAgent.toLowerCase();
   //var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
@@ -344,8 +394,8 @@ function getTarget(event) {
 function preventDefault(event) {
   if (event.preventDefault)
     event.preventDefault(); // W3C DOM
-
-  event.returnValue = false; // IE
+  else
+    event.returnValue = false; // IE
 }
 
 function resetSelection(win) {
@@ -367,7 +417,7 @@ function refreshOpener() {
 
 function parseQueryString() {
   var queryArray, queryDict
-  var key, value, s, idx;
+    var key, value, s, idx;
   queryDict.length = 0;
   
   queryDict  = new Array();
@@ -405,44 +455,6 @@ function generateQueryString(queryDict) {
   return s;
 }
 
-function getQueryParaArray(s) {
-  if (s.charAt(0) == "?") s = s.substr(1, s.length - 1);
-  return s.split("&");
-}
-
-function getQueryParaValue(s, name) {
-  var t;
-  
-  t = getQueryParaArray(s);
-  for (var i = 0; i < t.length; i++) {
-    var s = t[i];
-    
-    if (s.indexOf(name) != 0)
-      continue;
-    
-    s = s.substr(name.length, s.length - name.length);
-    return decodeURIComponent(s);
-  }
-  return null;
-}
-
-/* opener callback */
-
-function triggerOpenerCallback() {
-  /* this code has some issue if the folder has no proper trailing slash! */
-  if (window.opener && !window.opener.closed) {
-    var t, cburl;
-    
-    t = getQueryParaValue(window.location.search, "openerurl=");
-    cburl = window.opener.location.href;
-    if (cburl[cburl.length - 1] != "/") {
-      cburl = cburl.substr(0, cburl.lastIndexOf("/") + 1);
-    }
-    cburl = cburl + t;
-    window.opener.location.href = cburl;
-  }
-}
-
 /* selection mechanism */
 
 function deselectAll(parent) {
@@ -458,58 +470,67 @@ function isNodeSelected(node) {
 }
 
 function acceptMultiSelect(node) {
-   var response = false;
-   var attribute = node.getAttribute('multiselect');
-   if (attribute) {
-      log("node '" + node.getAttribute("id")
-         + "' is still using old-stylemultiselect!");
-      response = (attribute.toLowerCase() == 'yes');
-   }
-   else
-      response = node.multiselect;
+  var response = false;
+  var attribute = node.getAttribute('multiselect');
+  if (attribute && attribute.length > 0) {
+    log("node '" + node.getAttribute("id")
+       + "' is still using old-stylemultiselect!");
+    response = (attribute.toLowerCase() == 'yes');
+  }
+  else
+    response = node.multiselect;
 
-   return response;
+  return response;
 }
 
 function onRowClick(event) {
   var node = getTarget(event);
+  var rowIndex = null;
 
-  if (node.tagName == 'TD')
-    node = node.parentNode;
-  var startSelection = $(node.parentNode).getSelectedNodes();
-  if (event.shiftKey == 1
+  if (node.tagName == 'TD') {
+    node = node.parentNode; // select TR
+    rowIndex = node.rowIndex - $(node).up('table').down('thead').getElementsByTagName('tr').length;  
+  }
+  else if (node.tagName == 'LI') {
+    // Find index of clicked row
+    var list = node.parentNode;
+    var items = list.childNodesWithTag("li");
+    for (var i = 0; i < items.length; i++) {
+      if (items[i] == node) {
+       rowIndex = i;
+       break;
+      }
+    }
+  }
+
+  var initialSelection = $(node.parentNode).getSelectedNodes();
+  if ((event.shiftKey == 1 || event.ctrlKey == 1)
+      && (lastClickedRow >= 0)
       && (acceptMultiSelect(node.parentNode)
          || acceptMultiSelect(node.parentNode.parentNode))) {
-    if (isNodeSelected(node) == true) {
+    if (event.shiftKey)
+      $(node.parentNode).selectRange(lastClickedRow, rowIndex);
+    else if (isNodeSelected(node) == true) {
       $(node).deselect();
     } else {
       $(node).select();
     }
+    // At this point, should empty content of 3-pane view
   } else {
+    // Single line selection
     $(node.parentNode).deselectAll();
     $(node).select();
-  }
-
-  if (startSelection != $(node.parentNode).getSelectedNodes()) {
-    var parentNode = node.parentNode;
-    if (parentNode.tagName == 'TBODY')
-      parentNode = parentNode.parentNode;
-    //log("onRowClick: parentNode = " + parentNode.tagName);
-    // parentNode is UL or TABLE
-    if (document.createEvent) {
-      var onSelectionChangeEvent;
-      if (isSafari())
-       onSelectionChangeEvent = document.createEvent("UIEvents");
-      else
-       onSelectionChangeEvent = document.createEvent("Events");
-      onSelectionChangeEvent.initEvent("mousedown", true, true);
-      parentNode.dispatchEvent(onSelectionChangeEvent);
-    }
-    else if (document.createEventObject) {
-      parentNode.fireEvent("onmousedown");
+  
+    if (initialSelection != $(node.parentNode).getSelectedNodes()) {
+      // Selection has changed; fire mousedown event
+      var parentNode = node.parentNode;
+      if (parentNode.tagName == 'TBODY')
+       parentNode = parentNode.parentNode;
+      parentNode.fire("mousedown");
     }
   }
-
+  lastClickedRow = rowIndex;
+  
   return true;
 }
 
@@ -518,32 +539,48 @@ function onRowClick(event) {
 // var acceptClick = false;
 
 function popupMenu(event, menuId, target) {
-   document.menuTarget = target;
+  document.menuTarget = target;
 
-   if (document.currentPopupMenu)
-      hideMenu(document.currentPopupMenu);
+  if (document.currentPopupMenu)
+    hideMenu(document.currentPopupMenu);
+
+  var popup = $(menuId);
 
-   var popup = $(menuId);
-   var menuTop = event.pageY;
-   var menuLeft = event.pageX;
-   var heightDiff = (window.innerHeight
-                    - (menuTop + popup.offsetHeight));
-   if (heightDiff < 0)
-      menuTop += heightDiff;
+  var deltaX = 0;
+  var deltaY = 0;
+
+  var pageContent = $("pageContent");
+  if (popup.parentNode.tagName != "BODY") {
+    var offset = pageContent.cascadeLeftOffset();
+    deltaX = -($(popup.parentNode).cascadeLeftOffset() - offset);
+    offset = pageContent.cascadeTopOffset();
+    deltaY = -($(popup.parentNode).cascadeTopOffset() - offset);
+  }
+
+  var menuTop = Event.pointerY(event) + deltaY;
+  var menuLeft = Event.pointerX(event) + deltaX;
+  var heightDiff = (window.height()
+                   - (menuTop + popup.offsetHeight));
+  if (heightDiff < 0)
+    menuTop += heightDiff;
   
-   var leftDiff = (window.innerWidth
-                  - (menuLeft + popup.offsetWidth));
-   if (leftDiff < 0)
-      menuLeft -= popup.offsetWidth;
+  var leftDiff = (window.width()
+                 - (menuLeft + popup.offsetWidth));
+  if (leftDiff < 0)
+    menuLeft -= popup.offsetWidth;
 
-   popup.setStyle({ top: menuTop + "px",
-                   left: menuLeft + "px",
-                   visibility: "visible" });
+  if (popup.prepareVisibility)
+    popup.prepareVisibility();
+  
+  popup.setStyle({ top: menuTop + "px",
+                  left: menuLeft + "px",
+                  visibility: "visible" });
+
+  document.currentPopupMenu = popup;
 
-   document.currentPopupMenu = popup;
-   Event.observe(document.body, "click", onBodyClickMenuHandler);
+  $(document.body).observe("click", onBodyClickMenuHandler);
 
-   preventDefault(event);
+  preventDefault(event);
 }
 
 function getParentMenu(node) {
@@ -564,11 +601,11 @@ function getParentMenu(node) {
 }
 
 function onBodyClickMenuHandler(event) {
-   document.body.menuTarget = null;
-   hideMenu(document.currentPopupMenu);
-   Event.stopObserving(document.body, "click", onBodyClickMenuHandler);
+  hideMenu(document.currentPopupMenu);
+  document.body.stopObserving("click", onBodyClickMenuHandler);
 
-   preventDefault(event);
+  if (event)
+    preventDefault(event);
 }
 
 function hideMenu(menuNode) {
@@ -580,31 +617,27 @@ function hideMenu(menuNode) {
   }
 
   menuNode.setStyle({ visibility: "hidden" });
-  //   menuNode.hide();
   if (menuNode.parentMenuItem) {
-    menuNode.parentMenuItem.setAttribute('class', 'submenu');
+    menuNode.parentMenuItem.stopObserving("mouseover",onMouseEnteredSubmenu);
+    menuNode.stopObserving("mouseover", onMouseEnteredSubmenu);
+    menuNode.parentMenuItem.stopObserving("mouseout", onMouseLeftSubmenu);
+    menuNode.stopObserving("mouseout", onMouseLeftSubmenu);
+    menuNode.parentMenu.stopObserving("mouseover", onMouseEnteredParentMenu);
+    $(menuNode.parentMenuItem).removeClassName("submenu-selected");
+    menuNode.parentMenuItem.mouseInside = false;
     menuNode.parentMenuItem = null;
-    menuNode.parentMenu.setAttribute('onmousemove', null);
     menuNode.parentMenu.submenuItem = null;
     menuNode.parentMenu.submenu = null;
     menuNode.parentMenu = null;
   }
 
-  if (document.initEvent) {
-    var onhideEvent = document.createEvent("UIEvents");
-    onhideEvent.initEvent("hideMenu", false, true);
-    menuNode.dispatchEvent(onhideEvent);
-  }
-  else if (document.createEventObject) {
-    // TODO: add support for IE
-  }
+  $(menuNode).fire("mousedown");
 }
 
 function onMenuEntryClick(event) {
   var node = event.target;
 
   id = getParentMenu(node).menuTarget;
-//   log("clicked " + id + "/" + id.tagName);
 
   return false;
 }
@@ -625,20 +658,20 @@ function parseQueryParameters(url) {
 }
 
 function initLogConsole() {
-    var logConsole = $("logConsole");
-    if (logConsole) {
-       logConsole.highlighted = false;
-       Event.observe(logConsole, "dblclick", onLogDblClick, false);
-       logConsole.innerHTML = "";
-       Event.observe(window, "keydown", onBodyKeyDown);
-    }
+  var logConsole = $("logConsole");
+  if (logConsole) {
+    logConsole.highlighted = false;
+    logConsole.observe("dblclick", onLogDblClick, false);
+    logConsole.update();
+    Event.observe(window, "keydown", onBodyKeyDown);
+  }
 }
 
 function onBodyKeyDown(event) {
-    if (event.keyCode == 27) {
-       toggleLogConsole();
-       preventDefault(event);
-    }
+  if (event.keyCode == 27) {
+    toggleLogConsole();
+    preventDefault(event);
+  }
 }
 
 function onLogDblClick(event) {
@@ -655,7 +688,7 @@ function toggleLogConsole(event) {
     logConsole.setStyle({ display: '' });
   }
   if (event)
-      preventDefault(event);
+    preventDefault(event);
 }
 
 function log(message) {
@@ -666,101 +699,104 @@ function log(message) {
   }
   var logConsole = logWindow.document.getElementById("logConsole");
   if (logConsole) {
-      logConsole.highlighted = !logConsole.highlighted;
-      var logMessage = message.replace("<", "&lt;", "g");
-      logMessage = logMessage.replace(" ", "&nbsp;", "g");
-      logMessage = logMessage.replace("\r\n", "<br />\n", "g");
-      logMessage = logMessage.replace("\n", "<br />\n", "g");
-      logMessage += '<br />' + "\n";
-      if (logConsole.highlighted)
-         logMessage = '<div class="highlighted">' + logMessage + '</div>';
-      logConsole.innerHTML += logMessage;
+    logConsole.highlighted = !logConsole.highlighted;
+    if (message == '\c') {
+      logConsole.innerHTML = "";
+      return;
+    }
+    var logMessage = message.replace("<", "&lt;", "g");
+    logMessage = logMessage.replace(" ", "&nbsp;", "g");
+    logMessage = logMessage.replace("\r\n", "<br />\n", "g");
+    logMessage = logMessage.replace("\n", "<br />\n", "g");
+    logMessage += '<br />' + "\n";
+    if (logConsole.highlighted)
+      logMessage = '<div class="highlighted">' + logMessage + '</div>';
+    logConsole.innerHTML += logMessage;
   }
 }
 
 function backtrace() {
-   var func = backtrace.caller;
-   var str = "backtrace:\n";
+  var func = backtrace.caller;
+  var str = "backtrace:\n";
 
-   while (func)
-   {
+  while (func)
+    {
       if (func.name)
-      {
-         str += "  " + func.name;
-         if (this)
+       {
+         str += "  " + func.name;
+         if (this)
             str += " (" + this + ")";
-      }
+       }
       else
-         str += "[anonymous]\n";
+       str += "[anonymous]\n";
 
       str += "\n";
       func = func.caller;
-   }
-   str += "--\n";
-
-   return str;
-}
-
-function dropDownSubmenu(event) {
-   var node = this;
-   if (this.submenu && this.submenu != "") {
-      log ("submenu: " + this.submenu);
-      var submenuNode = $(this.submenu);
-      var parentNode = getParentMenu(node);
-      if (parentNode.submenu)
-        hideMenu(parentNode.submenu);
-      submenuNode.parentMenuItem = node;
-      submenuNode.parentMenu = parentNode;
-      parentNode.submenuItem = node;
-      parentNode.submenu = submenuNode;
-      
-      var menuTop = (node.offsetTop - 2);
-      
-      var heightDiff = (window.innerHeight
-                       - (menuTop + submenuNode.offsetHeight));
-      if (heightDiff < 0)
-        menuTop += heightDiff;
-      
-      var menuLeft = parentNode.offsetWidth - 3;
-      if (window.innerWidth
-         < (menuLeft + submenuNode.offsetWidth
-            + parentNode.cascadeLeftOffset()))
-        menuLeft = - submenuNode.offsetWidth + 3;
-      
-      parentNode.setAttribute('onmousemove', 'checkDropDown(event);');
-      node.setAttribute('class', 'submenu-selected');
-      submenuNode.setStyle({ top: menuTop + "px",
-                                    left: menuLeft + "px",
-                                    visibility: "visible" });
-   }
-}
-
-function checkDropDown(event) {
-  var parentMenu = getParentMenu(event.target);
-  var submenuItem = parentMenu.submenuItem;
-  if (submenuItem) {
-    var menuX = event.clientX - parentMenu.cascadeLeftOffset();
-    var menuY = event.clientY - parentMenu.cascadeTopOffset();
-    var itemX = submenuItem.offsetLeft;
-    var itemY = submenuItem.offsetTop - 75;
-
-    if (menuX >= itemX
-        && menuX < itemX + submenuItem.offsetWidth
-        && (menuY < itemY
-            || menuY > (itemY + submenuItem.offsetHeight))) {
-      hideMenu(parentMenu.submenu);
-      parentMenu.submenu = null;
-      parentMenu.submenuItem = null;
-      parentMenu.setAttribute('onmousemove', null);
     }
+  str += "--\n";
+
+  return str;
+}
+
+function popupSubmenu(event) {
+  if (this.submenu && this.submenu != "") {
+    var submenuNode = $(this.submenu);
+    var parentNode = getParentMenu(this);
+    if (parentNode.submenu)
+      hideMenu(parentNode.submenu);
+    submenuNode.parentMenuItem = this;
+    submenuNode.parentMenu = parentNode;
+    parentNode.submenuItem = this;
+    parentNode.submenu = submenuNode;
+
+    if (submenuNode.prepareVisibility)
+      submenuNode.prepareVisibility();
+
+    var menuTop = (parentNode.offsetTop - 1
+                  + this.offsetTop);
+    if (window.height()
+       < (menuTop + submenuNode.offsetHeight)
+       && submenuNode.offsetHeight < window.height())
+      menuTop -= submenuNode.offsetHeight - this.offsetHeight - 4;
+    var menuLeft = (parentNode.offsetLeft + parentNode.offsetWidth - 3);
+    if (window.width()
+       < (menuLeft + submenuNode.offsetWidth))
+      menuLeft = parentNode.offsetLeft - submenuNode.offsetWidth + 3;
+
+    this.mouseInside = true;
+    this.observe("mouseover", onMouseEnteredSubmenu);
+    submenuNode.observe("mouseover", onMouseEnteredSubmenu);
+    this.observe("mouseout", onMouseLeftSubmenu);
+    submenuNode.observe("mouseout", onMouseLeftSubmenu);
+    parentNode.observe("mouseover", onMouseEnteredParentMenu);
+    $(this).addClassName("submenu-selected");
+    submenuNode.setStyle({ top: menuTop + "px",
+                          left: menuLeft + "px",
+                          visibility: "visible" });
+    preventDefault(event);
   }
 }
 
+function onMouseEnteredParentMenu(event) {
+  if (this.submenuItem && !this.submenuItem.mouseInside)
+    hideMenu(this.submenu);
+}
+
+function onMouseEnteredSubmenu(event) {
+  $(this).mouseInside = true;
+}
+
+function onMouseLeftSubmenu(event) {
+  $(this).mouseInside = false;
+}
+
 /* search field */
 function popupSearchMenu(event) {
   var menuId = this.getAttribute("menuid");
-  relX = event.pageX - $(this).cascadeLeftOffset();
-  relY = event.pageY - $(this).cascadeTopOffset();
+  var offset = Position.cumulativeOffset(this);
+
+  relX = Event.pointerX(event) - offset[0];
+  relY = Event.pointerY(event) - offset[1];
 
   if (event.button == 0
       && relX < 24) {
@@ -771,21 +807,27 @@ function popupSearchMenu(event) {
       hideMenu(document.currentPopupMenu);
 
     var popup = $(menuId);
+    offset = Position.positionedOffset(this);
     popup.setStyle({ top: this.offsetHeight + "px",
-                    left: (this.offsetLeft + 3) + "px",
-                           visibility: "visible" });
+         left: (offset[0] + 3) + "px",
+         visibility: "visible" });
   
     document.currentPopupMenu = popup;
-    Event.observe(document.body, "click", onBodyClickMenuHandler);
+    $(document.body).observe("click", onBodyClickMenuHandler);
   }
 }
 
 function setSearchCriteria(event) {
-  searchValue = $("searchValue");
-  searchCriteria = $("searchCriteria");
+  var searchValue = $("searchValue");
+  var searchCriteria = $("searchCriteria");
 
   searchValue.setAttribute("ghost-phrase", this.innerHTML);
   searchCriteria.value = this.getAttribute('id');
+  
+  if (this.parentNode.chosenNode)
+    this.parentNode.chosenNode.removeClassName("_chosen");
+  this.addClassName("_chosen");
+  this.parentNode.chosenNode = this;
 }
 
 function checkSearchValue(event) {
@@ -802,29 +844,34 @@ function onSearchChange() {
 }
 
 function configureSearchField() {
-   var searchValue = $("searchValue");
+  var searchValue = $("searchValue");
+  var searchOptions = $("searchOptions");
 
-   Event.observe(searchValue, "mousedown",
-                onSearchMouseDown.bindAsEventListener(searchValue));
-   Event.observe(searchValue, "click",
-                popupSearchMenu.bindAsEventListener(searchValue));
-   Event.observe(searchValue, "blur",
-                onSearchBlur.bindAsEventListener(searchValue));
-   Event.observe(searchValue, "focus",
-                onSearchFocus.bindAsEventListener(searchValue));
-   Event.observe(searchValue, "keydown",
-                onSearchKeyDown.bindAsEventListener(searchValue));
+  if (!searchValue) return;
+
+  searchValue.observe("click", popupSearchMenu);
+  searchValue.observe("blur", onSearchBlur);
+  searchValue.observe("focus", onSearchFocus);
+  searchValue.observe("keydown", onSearchKeyDown);
+  searchValue.observe("mousedown", onSearchMouseDown);
+  
+  if (!searchOptions) return;
+   
+  // Set the checkmark to the first option
+  var firstOption = searchOptions.down('li');
+  firstOption.addClassName("_chosen");
+  searchOptions.chosenNode = firstOption;
 }
 
 function onSearchMouseDown(event) {
-   var superNode = this.parentNode.parentNode.parentNode;
-   relX = (event.pageX - superNode.offsetLeft - this.offsetLeft);
-   relY = (event.pageY - superNode.offsetTop - this.offsetTop);
+  var superNode = this.parentNode.parentNode.parentNode;
+  relX = (Event.pointerX(event) - superNode.offsetLeft - this.offsetLeft);
+  relY = (Event.pointerY(event) - superNode.offsetTop - this.offsetTop);
 
-   if (relY < 24) {
-      event.cancelBubble = true;
-      event.returnValue = false;
-   }
+  if (relY < 24) {
+    event.cancelBubble = true;
+    event.returnValue = false;
+  }
 }
 
 function onSearchFocus() {
@@ -841,11 +888,12 @@ function onSearchFocus() {
 
 function onSearchBlur(event) {
   var ghostPhrase = this.getAttribute("ghost-phrase");
-//   log ("search blur: '" + this.value + "'");
+
   if (!this.value) {
     this.setAttribute("modified", "");
     this.setStyle({ color: "#aaa" });
     this.value = ghostPhrase;
+    refreshCurrentFolder();
   } else if (this.value == ghostPhrase) {
     this.setAttribute("modified", "");
     this.setStyle({ color: "#aaa" });
@@ -863,19 +911,24 @@ function onSearchKeyDown(event) {
 }
 
 function onSearchFormSubmit(event) {
-   var searchValue = $("searchValue");
-   var searchCriteria = $("searchCriteria");
+  var searchValue = $("searchValue");
+  var searchCriteria = $("searchCriteria");
+  var ghostPhrase = searchValue.getAttribute('ghost-phrase');
+   
+  if (searchValue.value == ghostPhrase) return;
 
-   search["criteria"] = searchCriteria.value;
-   search["value"] = searchValue.value;
+  search["criteria"] = searchCriteria.value;
+  search["value"] = searchValue.value;
 
-   refreshCurrentFolder();
+  refreshCurrentFolder();
 }
 
 function initCriteria() {
   var searchCriteria = $("searchCriteria");
   var searchValue = $("searchValue");
  
+  if (!searchValue) return;
+
   var searchOptions = $("searchOptions").childNodesWithTag("li");
   if (searchOptions.length > 0) {
     var firstChild = searchOptions[0];
@@ -891,96 +944,118 @@ function initCriteria() {
 
 /* toolbar buttons */
 function popupToolbarMenu(node, menuId) {
-   if (document.currentPopupMenu)
-      hideMenu(document.currentPopupMenu);
+  if (document.currentPopupMenu)
+    hideMenu(document.currentPopupMenu);
 
-   var popup = $(menuId);
-   var top = node.top + node.offsetHeight - 2;
-   popup.setStyle({ top: top + "px",
-                   left: node.cascadeLeftOffset() + "px",
-                   visibility: "visible" });
+  var popup = $(menuId);
+  var top = ($(node).getStyle('top') || 0) + node.offsetHeight - 2;
+  popup.setStyle({ top: top + "px",
+       left: $(node).cascadeLeftOffset() + "px",
+       visibility: "visible" });
 
-   document.currentPopupMenu = popup;
-   Event.observe(document.body, "click", onBodyClickMenuHandler);
+  document.currentPopupMenu = popup;
+  $(document.body).observe("click", onBodyClickMenuHandler);
 }
 
 /* contact selector */
 
 function folderSubscriptionCallback(http) {
-   if (http.readyState == 4) {
-      if (http.status == 204) {
-        if (http.callbackData)
-           http.callbackData["method"](http.callbackData["data"]);
-      }
-      else
-        window.alert(labels["Unable to subscribe to that folder!"].decodeEntities());
-      document.subscriptionAjaxRequest = null;
-   }
-   else
-      log ("ajax fuckage");
+  if (http.readyState == 4) {
+    if (isHttpStatus204(http.status)) {
+      if (http.callbackData)
+       http.callbackData["method"](http.callbackData["data"]);
+    }
+    else
+      window.alert(clabels["Unable to subscribe to that folder!"]);
+    document.subscriptionAjaxRequest = null;
+  }
+  else
+    log ("folderSubscriptionCallback Ajax error");
 }
 
 function subscribeToFolder(refreshCallback, refreshCallbackData) {
-   var folderData = refreshCallbackData["folder"].split(":");
-   var username = folderData[0];
-   var folderPath = folderData[1];
-   if (username != UserLogin) {
-      var url = (UserFolderURL + "../" + username
-                 + folderPath + "/subscribe");
-      if (document.subscriptionAjaxRequest) {
-        document.subscriptionAjaxRequest.aborted = true;
-        document.subscriptionAjaxRequest.abort();
-      }
-      var rfCbData = { method: refreshCallback, data: refreshCallbackData };
-      document.subscriptionAjaxRequest = triggerAjaxRequest(url,
-                                                           folderSubscriptionCallback,
-                                                           rfCbData);
-   }
-   else
-      window.alert(labels["You cannot subscribe to a folder that you own!"]
-                  .decodeEntities());
+  var folderData = refreshCallbackData["folder"].split(":");
+  var username = folderData[0];
+  var folderPath = folderData[1];
+  if (username != UserLogin) {
+    var url = (UserFolderURL + "../" + username
+              + folderPath + "/subscribe");
+    if (document.subscriptionAjaxRequest) {
+      document.subscriptionAjaxRequest.aborted = true;
+      document.subscriptionAjaxRequest.abort();
+    }
+
+    var rfCbData = { method: refreshCallback, data: refreshCallbackData };
+    document.subscriptionAjaxRequest = triggerAjaxRequest(url,
+                                                         folderSubscriptionCallback,
+                                                         rfCbData);
+  }
+  else
+    refreshCallbackData["window"].alert(clabels["You cannot subscribe to a folder that you own!"]);
 }
 
 function folderUnsubscriptionCallback(http) {
-   if (http.readyState == 4) {
-      if (http.status == 204) {
-        if (http.callbackData)
-           http.callbackData["method"](http.callbackData["data"]);
-      }
-      else
-        window.alert(labels["Unable to unsubscribe from that folder!"].decodeEntities());
-      document.unsubscriptionAjaxRequest = null;
-   }
+  if (http.readyState == 4) {
+    removeFolderRequestCount--;
+    if (isHttpStatus204(http.status)) {
+      if (http.callbackData)
+       http.callbackData["method"](http.callbackData["data"]);
+    }
+    else
+      window.alert(clabels["Unable to unsubscribe from that folder!"]);
+  }
 }
 
 function unsubscribeFromFolder(folder, refreshCallback, refreshCallbackData) {
-   if (document.body.hasClassName("popup")) {
-      window.opener.unsubscribeFromFolder(folder, refreshCallback,
-                                         refreshCallbackData);
-   }
-   else {
-      var folderData = folder.split(":");
-      var username = folderData[0];
-      var folderPath = folderData[1];
-      if (username != UserLogin) {
-        var url = (UserFolderURL + "../" + username
-                   + "/" + folderPath + "/unsubscribe");
-        if (document.unsubscriptionAjaxRequest) {
-           document.unsubscriptionAjaxRequest.aborted = true;
-           document.unsubscriptionAjaxRequest.abort();
-        }
-        var rfCbData = { method: refreshCallback, data: refreshCallbackData };
-        document.unsubscriptionAjaxRequest
-           = triggerAjaxRequest(url, folderUnsubscriptionCallback,
-                                rfCbData);
-      }
-      else
-        window.alert(labels["You cannot unsubscribe from a folder that you own!"].decodeEntities());
-   }
+  if (document.body.hasClassName("popup")) {
+    window.opener.unsubscribeFromFolder(folder, refreshCallback,
+                                       refreshCallbackData);
+  }
+  else {
+    var folderData = folder.split("_");
+    var username = folderData[0];
+    var folderPath = folderData[1];
+    if (username.startsWith('/'))
+      username = username.substring(1);
+    if (username != UserLogin) {
+      var url = (ApplicationBaseURL + folder + "/unsubscribe");
+      removeFolderRequestCount++;
+      var rfCbData = { method: refreshCallback, data: refreshCallbackData };
+      triggerAjaxRequest(url, folderUnsubscriptionCallback, rfCbData);
+    }
+    else
+      window.alert(clabels["You cannot unsubscribe from a folder that you own!"]);
+  }
+}
+
+function accessToSubscribedFolder(serverFolder) {
+  var folder;
+
+  var parts = serverFolder.split(":");
+  if (parts.length > 1) {
+    var paths = parts[1].split("/");
+    folder = "/" + parts[0] + "_" + paths[2];
+  }
+  else
+    folder = serverFolder;
+  
+  return folder;
+}
+
+function getSubscribedFolderOwner(serverFolder) {
+  var owner;
+  
+  var parts = serverFolder.split(":");
+  if (parts.length > 1) {
+    owner = parts[0];
+  }
+  
+  return owner;
 }
 
 function listRowMouseDownHandler(event) {
-   preventDefault(event);
+  preventDefault(event);
+  //Event.stop(event); 
 }
 
 /* tabs */
@@ -999,16 +1074,14 @@ function initTabs() {
     
     firstTab = null;
     for (var i = 0; i < nodes.length; i++) {
-       var currentNode = nodes[i];
-       if (currentNode.tagName == 'LI') {
-           if (!firstTab)
-               firstTab = i;
-           Event.observe(currentNode, "mousedown",
-                         onTabMouseDown.bindAsEventListener(currentNode));
-           Event.observe(currentNode, "click",
-                         onTabClick.bindAsEventListener(currentNode));
-           //$(currentNode.getAttribute("target")).hide();
-       }
+      var currentNode = nodes[i];
+      if (currentNode.tagName == 'LI') {
+       if (!firstTab)
+         firstTab = i;
+       $(currentNode).observe("mousedown", onTabMouseDown);
+       $(currentNode).observe("click", onTabClick);
+       //$(currentNode.getAttribute("target")).hide();
+      }
     }
 
     nodes[firstTab].addClassName("first");
@@ -1022,39 +1095,40 @@ function initTabs() {
 }
 
 function initMenus() {
-   var menus = getMenus();
-   if (menus) {
-      for (var menuID in menus) {
-        var menuDIV = $(menuID);
-        if (menuDIV)
-           initMenu(menuDIV, menus[menuID]);
-      }
-   }
+  var menus = getMenus();
+  if (menus) {
+    for (var menuID in menus) {
+      var menuDIV = $(menuID);
+      if (menuDIV)
+       initMenu(menuDIV, menus[menuID]);
+    }
+  }
 }
 
 function initMenu(menuDIV, callbacks) {
-   var lis = $(menuDIV.childNodesWithTag("ul")[0]).childNodesWithTag("li");
-   for (var j = 0; j < lis.length; j++) {
-      var node = lis[j];
-      Event.observe(node, "mousedown", listRowMouseDownHandler, false);
-      var callback = callbacks[j];
-      if (callback) {
-        if (typeof(callback) == "string") {
-           if (callback == "-")
-              node.addClassName("separator");
-           else {
-              node.submenu = callback;
-              node.addClassName("submenu");
-              Event.observe(node, "mouseover", dropDownSubmenu);
-           }
-        }
-        else
-           Event.observe(node, "mouseup",
-                         $(callback).bindAsEventListener(node));
+  var lis = $(menuDIV.childNodesWithTag("ul")[0]).childNodesWithTag("li");
+  for (var j = 0; j < lis.length; j++) {
+    var node = $(lis[j]);
+    node.observe("mousedown", listRowMouseDownHandler, false);
+    var callback = callbacks[j];
+    if (callback) {
+      if (typeof(callback) == "string") {
+       if (callback == "-")
+         node.addClassName("separator");
+       else {
+         node.submenu = callback;
+         node.addClassName("submenu");
+         node.observe("mouseover", popupSubmenu);
+       }
       }
-      else
-        node.addClassName("disabled");
-   }
+      else {
+       node.observe("mouseup", onBodyClickMenuHandler);
+       node.observe("click", callback);
+      }
+    }
+    else
+      node.addClassName("disabled");
+  }
 }
 
 function onTabMouseDown(event) {
@@ -1078,25 +1152,25 @@ function openAclWindow(url) {
 }
 
 function getUsersRightsWindowHeight() {
-   return usersRightsWindowHeight;
+  return usersRightsWindowHeight;
 }
 
 function getUsersRightsWindowWidth() {
-   return usersRightsWindowWidth;
+  return usersRightsWindowWidth;
 }
 
 function getTopWindow() {
-   var topWindow = null;
-   var currentWindow = window;
-   while (!topWindow) {
-      if (currentWindow.document.body.hasClassName("popup")
-         && currentWindow.opener)
-        currentWindow = currentWindow.opener;
-      else
-        topWindow = currentWindow;
-   }
+  var topWindow = null;
+  var currentWindow = window;
+  while (!topWindow) {
+    if (currentWindow.document.body.hasClassName("popup")
+       && currentWindow.opener)
+      currentWindow = currentWindow.opener;
+    else
+      topWindow = currentWindow;
+  }
 
-   return topWindow;
+  return topWindow;
 }
 
 function onTabClick(event) {
@@ -1191,12 +1265,12 @@ function indexColor(number) {
     var currentValue = number;
     var index = 0;
     while (currentValue) {
-       if (currentValue & 1)
-          colorTable[index]++;
-       if (index == 3)
-         index = 0;
-       currentValue >>= 1;
-       index++;
+      if (currentValue & 1)
+       colorTable[index]++;
+      if (index == 3)
+       index = 0;
+      currentValue >>= 1;
+      index++;
     }
     
     color = ("#"
@@ -1209,52 +1283,57 @@ function indexColor(number) {
 }
 
 function loadPreferences() {
-   var url = UserFolderURL + "jsonDefaults";
-   var http = createHTTPClient();
-   http.open("GET", url, false);
-   http.send("");
-   if (http.status == 200)
+  var url = UserFolderURL + "jsonDefaults";
+  var http = createHTTPClient();
+  http.open("GET", url, false);
+  http.send("");
+  if (http.status == 200) {
+    if (http.responseText.length > 0)
       userDefaults = http.responseText.evalJSON(true);
+    else
+      userDefaults = {};
+  }
 
-   url = UserFolderURL + "jsonSettings";
-   http.open("GET", url, false);
-   http.send("");
-   if (http.status == 200)
+  url = UserFolderURL + "jsonSettings";
+  http.open("GET", url, false);
+  http.send("");
+  if (http.status == 200) {
+    if (http.responseText.length > 0)
       userSettings = http.responseText.evalJSON(true);
+    else
+      userSettings = {};
+  }
 }
 
 function onLoadHandler(event) {
-   loadPreferences();
-   queryParameters = parseQueryParameters('' + window.location);
-   if (!$(document.body).hasClassName("popup")) {
-      initLogConsole();
-      initCriteria();
-      configureSearchField();
-   }
-   initMenus();
-   initTabs();
-   configureDragHandles();
-   configureSortableTableHeaders();
-   configureLinkBanner();
-   var progressImage = $("progressIndicator");
-   if (progressImage)
-      progressImage.parentNode.removeChild(progressImage);
-   Event.observe(document.body, "contextmenu", onBodyClickContextMenu);
+  if (typeof UserLogin != "undefined")
+    loadPreferences();
+  queryParameters = parseQueryParameters('' + window.location);
+  if (!$(document.body).hasClassName("popup")) {
+    initLogConsole();
+  }
+  initCriteria();
+  configureSearchField();
+  initMenus();
+  initTabs();
+  configureDragHandles();
+  configureLinkBanner();
+  var progressImage = $("progressIndicator");
+  if (progressImage)
+    progressImage.parentNode.removeChild(progressImage);
+  $(document.body).observe("contextmenu", onBodyClickContextMenu);
 }
 
 function onBodyClickContextMenu(event) {
-   preventDefault(event);
+  preventDefault(event);
 }
 
-function configureSortableTableHeaders() {
-   var headers = document.getElementsByClassName("sortableTableHeader");
-   for (var i = 0; i < headers.length; i++) {
-      var header = headers[i];
-      var anchor = $(header).childNodesWithTag("a")[0];
-      if (anchor)
-        Event.observe(anchor, "click",
-                      onHeaderClick.bindAsEventListener(anchor));
-   }
+function configureSortableTableHeaders(table) {
+  var headers = $(table).getElementsByClassName("sortableTableHeader");
+  for (var i = 0; i < headers.length; i++) {
+    var header = headers[i];
+    $(header).observe("click", onHeaderClick);
+  }
 }
 
 function onLinkBannerClick() {
@@ -1263,34 +1342,72 @@ function onLinkBannerClick() {
 }
 
 function onPreferencesClick(event) {
-   var urlstr = UserFolderURL + "preferences";
-   var w = window.open(urlstr, "User Preferences",
-                      "width=430,height=250,resizable=0,scrollbars=0");
-   w.opener = window;
-   w.focus();
+  var urlstr = UserFolderURL + "preferences";
+  var w = window.open(urlstr, "_blank",
+                     "width=430,height=250,resizable=0,scrollbars=0,location=0");
+  w.opener = window;
+  w.focus();
 
-   preventDefault(event);
+  preventDefault(event);
 }
 
 function configureLinkBanner() {
   var linkBanner = $("linkBanner");
   if (linkBanner) {
     var anchors = linkBanner.childNodesWithTag("a");
-    for (var i = 0; i < 2; i++) {
-       Event.observe(anchors[i], "mousedown", listRowMouseDownHandler);
-       Event.observe(anchors[i], "click", onLinkBannerClick);
+    for (var i = 1; i < 3; i++) {
+      $(anchors[i]).observe("mousedown", listRowMouseDownHandler);
+      $(anchors[i]).observe("click", onLinkBannerClick);
+    }
+    $(anchors[4]).observe("mousedown", listRowMouseDownHandler);
+    $(anchors[4]).observe("click", onPreferencesClick);
+    if (anchors.length > 5)
+      $(anchors[5]).observe("click", toggleLogConsole);
+  }
+}
+
+/* folder creation */
+function createFolder(name, okCB, notOkCB) {
+  if (name) {
+    if (document.newFolderAjaxRequest) {
+      document.newFolderAjaxRequest.aborted = true;
+      document.newFolderAjaxRequest.abort();
+    }
+    var url = ApplicationBaseURL + "/createFolder?name=" + name;
+    document.newFolderAjaxRequest
+      = triggerAjaxRequest(url, createFolderCallback,
+                          {name: name,
+                           okCB: okCB,
+                           notOkCB: notOkCB});
+  }
+}
+
+function createFolderCallback(http) {
+  if (http.readyState == 4) {
+    var data = http.callbackData;
+    if (http.status == 201) {
+      if (data.okCB)
+       data.okCB(data.name, "/" + http.responseText, UserLogin);
+    }
+    else {
+      if (data.notOkCB)
+       data.notOkCB(name);
+      else
+       log("ajax problem:" + http.status);
     }
-    Event.observe(anchors[3], "mousedown", listRowMouseDownHandler);
-    Event.observe(anchors[3], "click", onPreferencesClick);
-    if (anchors.length > 4)
-       Event.observe(anchors[4], "click", toggleLogConsole);
   }
 }
 
-addEvent(window, 'load', onLoadHandler);
+function onFinalLoadHandler(event) {
+  var safetyNet = $("javascriptSafetyNet");
+  if (safetyNet)
+    safetyNet.parentNode.removeChild(safetyNet);
+}
+
+FastInit.addOnLoad(onLoadHandler);
 
 function parent$(element) {
-   return this.opener.document.getElementById(element);
+  return this.opener.document.getElementById(element);
 }
 
 /* stubs */
@@ -1304,5 +1421,5 @@ function getMenus() {
 }
 
 function onHeaderClick(event) {
-   window.alert("generic headerClick");
+  window.alert("generic headerClick");
 }