]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/generic.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1060 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / generic.js
index 25e8a488179c23b7eab9f26cddd91b1743169ee4..89cce21d5d12a715159f04f15c3096c9f9eb87e9 100644 (file)
@@ -35,8 +35,7 @@ var activeAjaxRequests = 0;
 var allDocumentElements = null;
 
 /* a W3C compliant document.all */
-function getAllScopeElements(scope)
-{
+function getAllScopeElements(scope) {
   var elements = new Array();
 
   for (var i = 0; i < scope.childNodes.length; i++)
@@ -53,8 +52,7 @@ function getAllScopeElements(scope)
   return elements;
 }
 
-function getAllElements(scope)
-{
+function getAllElements(scope) {
   var elements;
 
   if (scope == null)
@@ -112,6 +110,24 @@ function ml_stripActionInURL(url) {
   return 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];
+   
+   if (url[url.length-1] == '/')
+      url = url.substr(0, url.length-1);
+
+   return url;
+}
+
 function extractEmailAddress(mailTo) {
   var email = "";
 
@@ -128,11 +144,13 @@ function extractEmailAddress(mailTo) {
 function extractEmailName(mailTo) {
   var emailName = "";
 
-  var emailNamere = /(\w[\w\ _-]+)\ (&lt;|<)/;
+  var emailNamere = /(.+)\ </;
   if (emailNamere.test(mailTo)) {
     emailNamere.exec(mailTo);
     emailName = RegExp.$1;
   }
+
+  return emailName;
 }
 
 function sanitizeMailTo(dirtyMailTo) {
@@ -148,6 +166,19 @@ function sanitizeMailTo(dirtyMailTo) {
   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,
                       "width=680,height=520,resizable=1,scrollbars=1,toolbar=0,"
@@ -380,7 +411,7 @@ function onRowClick(event) {
     var parentNode = node.parentNode;
     if (parentNode instanceof HTMLTableSectionElement)
       parentNode = parentNode.parentNode;
-    var onSelectionChangeEvent = document.createEvent("Event");
+    var onSelectionChangeEvent = document.createEvent("UIEvents");
     onSelectionChangeEvent.initEvent("selectionchange", true, true);
     parentNode.dispatchEvent(onSelectionChangeEvent);
   }
@@ -391,8 +422,7 @@ function onRowClick(event) {
 var bodyOnClick = "";
 // var acceptClick = false;
 
-function onMenuClick(event, menuId)
-{
+function onMenuClick(event, menuId) {
   var node = event.target;
 
   if (document.currentPopupMenu)
@@ -427,8 +457,7 @@ function onMenuClick(event, menuId)
   return false;
 }
 
-function setupMenuTarget(menu, target)
-{
+function setupMenuTarget(menu, target) {
   menu.menuTarget = target;
   var menus = document.getElementsByClassName("menu", menu);
   for (var i = 0; i < menus.length; i++) {
@@ -436,8 +465,7 @@ function setupMenuTarget(menu, target)
   }
 }
 
-function getParentMenu(node)
-{
+function getParentMenu(node) {
   var currentNode, menuNode;
 
   menuNode = null;
@@ -454,8 +482,7 @@ function getParentMenu(node)
   return menuNode;
 }
 
-function onBodyClick(event)
-{
+function onBodyClick(event) {
   document.currentPopupMenu.menuTarget = null;
   hideMenu(event, document.currentPopupMenu);
   document.body.setAttribute("onclick", bodyOnClick);
@@ -463,35 +490,31 @@ function onBodyClick(event)
   return false;
 }
 
-function hideMenu(event, menuNode)
-{
+function hideMenu(event, menuNode) {
   var onHide;
 
 //   log('hiding menu "' + menuNode.getAttribute('id') + '"');
-  if (menuNode.submenu)
-    {
-      hideMenu(event, menuNode.submenu);
-      menuNode.submenu = null;
-    }
+  if (menuNode.submenu) {
+    hideMenu(event, menuNode.submenu);
+    menuNode.submenu = null;
+  }
 
   menuNode.style.visibility = "hidden";
-  if (menuNode.parentMenuItem)
-    {
-      menuNode.parentMenuItem.setAttribute('class', 'submenu');
-      menuNode.parentMenuItem = null;
-      menuNode.parentMenu.setAttribute('onmousemove', null);
-      menuNode.parentMenu.submenuItem = null;
-      menuNode.parentMenu.submenu = null;
-      menuNode.parentMenu = null;
-    }
+  if (menuNode.parentMenuItem) {
+    menuNode.parentMenuItem.setAttribute('class', 'submenu');
+    menuNode.parentMenuItem = null;
+    menuNode.parentMenu.setAttribute('onmousemove', null);
+    menuNode.parentMenu.submenuItem = null;
+    menuNode.parentMenu.submenu = null;
+    menuNode.parentMenu = null;
+  }
 
-  var onhideEvent = document.createEvent("Event");
+  var onhideEvent = document.createEvent("UIEvents");
   onhideEvent.initEvent("hideMenu", false, true);
   menuNode.dispatchEvent(onhideEvent);
 }
 
-function onMenuEntryClick(event, menuId)
-{
+function onMenuEntryClick(event, menuId) {
   var node = event.target;
 
   id = getParentMenu(node).menuTarget;
@@ -525,8 +548,7 @@ function initLogConsole() {
   }
 }
 
-function onBodyKeyDown(event)
-{
+function onBodyKeyDown(event) {
   if (event.keyCode == 27) {
     toggleLogConsole();
     event.cancelBubble = true;
@@ -534,8 +556,7 @@ function onBodyKeyDown(event)
   }
 }
 
-function onLogDblClick(event)
-{
+function onLogDblClick(event) {
   var logConsole = $("logConsole");
   logConsole.innerHTML = "";
 }
@@ -559,75 +580,94 @@ function log(message) {
     while (logWindow.opener)
       logWindow = logWindow.opener;
   }
-  var logConsole = logWindow.document.getElementById('logConsole');
+  var logConsole = logWindow.document.getElementById("logConsole");
   if (logConsole)
-    logConsole.innerHTML += message + '<br />' + "\n";
+    logConsole.innerHTML += message.replace("<", "&lt;") + '<br />' + "\n";
 }
 
-function dropDownSubmenu(event)
-{
+function backtrace() {
+   var func = backtrace.caller;
+   var str = "backtrace:<br/>";
+
+   while (func)
+   {
+      if (func.name)
+      {
+         str += "  " + func.name;
+         if (this)
+            str += " (" + this + ")";
+      }
+      else
+         str += "[anonymous]\n";
+
+      str += "<br/>";
+      func = func.caller;
+   }
+   str += "--\n";
+
+   return str;
+}
+
+function dropDownSubmenu(event) {
   var node = event.target;
   var submenu = node.getAttribute("submenu");
-  if (submenu && submenu != "")
-    {
-      var submenuNode = document.getElementById(submenu);
-      var parentNode = getParentMenu(node);
-      if (parentNode.submenu)
-       hideMenu(event, 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()))
+  if (submenu && submenu != "") {
+    var submenuNode = document.getElementById(submenu);
+    var parentNode = getParentMenu(node);
+    if (parentNode.submenu)
+      hideMenu(event, 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.style.top = menuTop + "px;";
-      submenuNode.style.left = menuLeft + "px;";
-      submenuNode.style.visibility = "visible;";
-    }
+    
+    parentNode.setAttribute('onmousemove', 'checkDropDown(event);');
+    node.setAttribute('class', 'submenu-selected');
+    submenuNode.style.top = menuTop + "px;";
+    submenuNode.style.left = menuLeft + "px;";
+    submenuNode.style.visibility = "visible;";
+  }
 }
 
-function checkDropDown(event)
-{
+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(event, parentMenu.submenu);
-         parentMenu.submenu = null;
-         parentMenu.submenuItem = null;
-         parentMenu.setAttribute('onmousemove', null);
-       }
+  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(event, parentMenu.submenu);
+      parentMenu.submenu = null;
+      parentMenu.submenuItem = null;
+      parentMenu.setAttribute('onmousemove', null);
     }
+  }
 }
 
 /* search field */
-function popupSearchMenu(event, menuId)
-{
+function popupSearchMenu(event) {
   var node = event.target;
+
+  var menuId = this.getAttribute("menuid");
   relX = event.pageX - node.cascadeLeftOffset();
   relY = event.pageY - node.cascadeTopOffset();
 
@@ -650,148 +690,192 @@ function popupSearchMenu(event, menuId)
   }
 }
 
-function setSearchCriteria(event)
-{
-  searchValue = document.getElementById('searchValue');
-  searchCriteria = document.getElementById('searchCriteria');
+function setSearchCriteria(event) {
+  searchValue = $("searchValue");
+  searchCriteria = $("searchCriteria");
   
   var node = event.target;
   searchValue.setAttribute("ghost-phrase", node.innerHTML);
   searchCriteria = node.getAttribute('id');
 }
 
-function checkSearchValue(event)
-{
+function checkSearchValue(event) {
   var form = event.target;
-  var searchValue = document.getElementById('searchValue');
+  var searchValue = $("searchValue");
   var ghostPhrase = searchValue.getAttribute('ghost-phrase');
 
   if (searchValue.value == ghostPhrase)
     searchValue.value = "";
 }
 
-function onSearchChange()
-{
+function onSearchChange() {
   log ("onSearchChange()...");
 }
 
-function onSearchMouseDown(event, searchValue)
-{
-  superNode = searchValue.parentNode.parentNode.parentNode;
-  relX = (event.pageX - superNode.offsetLeft - searchValue.offsetLeft);
-  relY = (event.pageY - superNode.offsetTop - searchValue.offsetTop);
+function onSearchMouseDown(event) {
+   var superNode = this.parentNode.parentNode.parentNode;
+   relX = (event.pageX - superNode.offsetLeft - this.offsetLeft);
+   relY = (event.pageY - superNode.offsetTop - this.offsetTop);
 
-  if (relY < 24) {
-    event.cancelBubble = true;
-    event.returnValue = false;
-  }
+   if (relY < 24) {
+      event.cancelBubble = true;
+      event.returnValue = false;
+   }
 }
 
-function onSearchFocus(searchValue)
-{
-  ghostPhrase = searchValue.getAttribute("ghost-phrase");
-  if (searchValue.value == ghostPhrase) {
-    searchValue.value = "";
-    searchValue.setAttribute("modified", "");
+function onSearchFocus() {
+  ghostPhrase = this.getAttribute("ghost-phrase");
+  if (this.value == ghostPhrase) {
+    this.value = "";
+    this.setAttribute("modified", "");
   } else {
-    searchValue.select();
+    this.select();
   }
 
-  searchValue.style.color = "#000";
+  this.style.color = "#000";
 }
 
-function onSearchBlur(searchValue)
-{
-  var ghostPhrase = searchValue.getAttribute("ghost-phrase");
-//   log ("search blur: '" + searchValue.value + "'");
-  if (!searchValue.value) {
-    searchValue.setAttribute("modified", "");
-    searchValue.style.color = "#aaa";
-    searchValue.value = ghostPhrase;
-  } else if (searchValue.value == ghostPhrase) {
-    searchValue.setAttribute("modified", "");
-    searchValue.style.color = "#aaa";
+function onSearchBlur(event) {
+  var ghostPhrase = this.getAttribute("ghost-phrase");
+//   log ("search blur: '" + this.value + "'");
+  if (!this.value) {
+    this.setAttribute("modified", "");
+    this.style.color = "#aaa";
+    this.value = ghostPhrase;
+  } else if (this.value == ghostPhrase) {
+    this.setAttribute("modified", "");
+    this.style.color = "#aaa";
   } else {
-    searchValue.setAttribute("modified", "yes");
-    searchValue.style.color = "#000";
+    this.setAttribute("modified", "yes");
+    this.style.color = "#000";
   }
 }
 
-function onSearchKeyDown(searchValue)
-{
-  if (searchValue.timer)
-    clearTimeout(searchValue.timer);
+function onSearchKeyDown(event) {
+  if (this.timer)
+    clearTimeout(this.timer);
 
-  searchValue.timer = setTimeout("onSearchFormSubmit()", 1000);
+  this.timer = setTimeout("onSearchFormSubmit()", 1000);
 }
 
-function initCriteria()
-{
-  var searchCriteria = document.getElementById('searchCriteria');
-  var searchValue = document.getElementById('searchValue');
+function initCriteria() {
+  var searchCriteria = $("searchCriteria");
+  var searchValue = $("searchValue");
   var firstOption;
  
-  firstOption = document.getElementById('searchOptions').childNodes[1];
-  searchCriteria.value = firstOption.getAttribute('id');
-  searchValue.setAttribute('ghost-phrase', firstOption.innerHTML);
-  if (searchValue.value == '') {
-    searchValue.value = firstOption.innerHTML;
-    searchValue.setAttribute("modified", "");
-    searchValue.style.color = "#aaa";
+  var searchOptions = $("searchOptions");
+  if (searchOptions) {
+    firstOption = searchOptions.childNodes[1];
+    searchCriteria.value = firstOption.getAttribute('id');
+    searchValue.setAttribute('ghost-phrase', firstOption.innerHTML);
+    if (searchValue.value == '') {
+      searchValue.value = firstOption.innerHTML;
+      searchValue.setAttribute("modified", "");
+      searchValue.style.color = "#aaa";
+    }
   }
 }
-/* contact selector */
 
-function onContactAdd(node)
-{
-  var selector = null;
-  var selectorURL = '?popup=YES';
-  if (node) {
-    selector = node.parentNode.parentNode;
-    selectorURL += ("&selectorId=" + selector.getAttribute("id"));
-  }
-
-  urlstr = ApplicationBaseURL;
-  if (urlstr[urlstr.length-1] != '/')
-    urlstr += '/';
-  urlstr += ("../../" + UserLogin + "/Contacts/"
-             + contactSelectorAction + selectorURL);
-//   log (urlstr);
-  var w = window.open(urlstr, "Addressbook",
-                      "width=640,height=400,resizable=1,scrollbars=0");
-  w.selector = selector;
-  w.opener = this;
-  w.focus();
+/* toolbar buttons */
+function popupToolbarMenu(event, menuId) {
+   var toolbar = $("toolbar");
+   var node = event.target;
+   if (node.tagName != 'A')
+      node = node.getParentWithTagName("a");
+   node = node.childNodesWithTag("span")[0];
 
-  return false;
+   if (event.button == 0) {
+      event.cancelBubble = true;
+      event.returnValue = false;
+      
+      if (document.currentPopupMenu)
+        hideMenu(event, document.currentPopupMenu);
+      
+      var popup = document.getElementById(menuId);
+      var top = node.offsetTop + node.offsetHeight - 2;
+      popup.style.top = top + "px";
+      popup.style.left = node.cascadeLeftOffset() + "px";
+      popup.style.visibility = "visible";
+      
+      bodyOnClick = "" + document.body.getAttribute("onclick");
+      document.body.setAttribute("onclick", "onBodyClick('" + menuId + "');");
+      document.currentPopupMenu = popup;
+   }
 }
 
-function onContactRemove(node) {
-  var selector = node.parentNode.parentNode;
-  var selectorId = selector.getAttribute("id");
-  var hasChanged = false;
-
-  var names = $('uixselector-' + selectorId + '-display');
-  var nodes = names.getSelectedNodes();
-  hasChanged = (nodes.length > 0);
-  for (var i = 0; i < nodes.length; i++) {
-    var currentNode = nodes[i];
-    currentNode.parentNode.removeChild(currentNode);
-  }
-
-  var uids = $('uixselector-' + selectorId + '-uidList');
-  nodes = node.parentNode.childNodes;
-  var ids = new Array();
-  for (var i = 0; i < nodes.length; i++)
-    if (nodes[i] instanceof HTMLLIElement)
-      ids.push(nodes[i].getAttribute("uid"));
-  uids.value = ids.join(",");
-
-  if (selector.changeNotification && hasChanged)
-    selector.changeNotification("removal");
+/* contact selector */
 
-  return false;
+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");
+}
+
+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());
+}
+
+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;
+   }
+}
+
+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());
+   }
 }
 
 function listRowMouseDownHandler(event) {
@@ -799,8 +883,7 @@ function listRowMouseDownHandler(event) {
 }
 
 /* tabs */
-function initTabs()
-{
+function initTabs() {
   var containers = document.getElementsByClassName("tabsContainer");
   for (var x = 0; x < containers.length; x++) {
     var container = containers[x];
@@ -810,18 +893,18 @@ function initTabs()
     for (var i = 0; i < nodes.length; i++) {
       if (nodes[i] instanceof HTMLLIElement) {
         if (!firstTab) {
-          firstTab = nodes[i];
+          firstTab = i;
         }
         nodes[i].addEventListener("mousedown", onTabMouseDown, true);
         nodes[i].addEventListener("click", onTabClick, true);
       }
     }
 
-    firstTab.addClassName("first");
-    firstTab.addClassName("active");
-    container.activeTab = firstTab;
+    nodes[firstTab].addClassName("first");
+    nodes[firstTab].addClassName("active");
+    container.activeTab = nodes[firstTab];
 
-    var target = $(firstTab.getAttribute("target"));
+    var target = $(nodes[firstTab].getAttribute("target"));
     target.addClassName("active");
   }
 }
@@ -854,17 +937,39 @@ function openExternalLink(anchor) {
   return false;
 }
 
-function openAclWindow(url, objectTitle) {
+function openAclWindow(url) {
   var w = window.open(url, "aclWindow",
                       "width=300,height=300,resizable=1,scrollbars=1,toolbar=0,"
                       + "location=0,directories=0,status=0,menubar=0"
                       + ",copyhistory=0");
+  w.opener = window;
   w.focus();
-  w.title = "Poil: " + objectTitle;
 
   return w;
 }
 
+function getUsersRightsWindowHeight() {
+   return usersRightsWindowHeight;
+}
+
+function getUsersRightsWindowWidth() {
+   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;
+   }
+
+   return topWindow;
+}
+
 function onTabClick(event) {
   var node = event.target;
 
@@ -922,11 +1027,13 @@ function disableAnchor(anchor) {
 
 function d2h(d) {
   var hD = "0123456789abcdef";
-  var h = hD.substr(d&15,1);
-  while (d>15) {
-    d>>=4;
-    h=hD.substr(d&15,1)+h;
+  var h = hD.substr(d & 15, 1);
+
+  while (d > 15) {
+    d >>= 4;
+    h = hD.substr(d & 15, 1) + h;
   }
+
   return h;
 }
 
@@ -940,15 +1047,14 @@ function indexColor(number) {
     
     var currentValue = number;
     var index = 0;
-    while (currentValue)
-      {
-        if (currentValue & 1)
+    while (currentValue) {
+       if (currentValue & 1)
           colorTable[index]++;
-      if (index == 3)
-        index = 0;
-      currentValue >>= 1;
-      index++;
-      }
+       if (index == 3)
+         index = 0;
+       currentValue >>= 1;
+       index++;
+    }
     
     color = ("#"
              + d2h((256 / colorTable[2]) - 1)
@@ -959,22 +1065,20 @@ function indexColor(number) {
   return color;
 }
 
-var onLoadHandler = {
-  handleEvent: function (event) {
-    queryParameters = parseQueryParameters('' + window.location);
-    if (!document.body.hasClassName("popup")) {
-      initLogConsole();
-      initializeMenus();
-      initCriteria();
-    }
-    initTabs();
-    configureDragHandles();
-    configureSortableTableHeaders();
-    configureLinkBanner();
-    var progressImage = $("progressIndicator");
-    if (progressImage)
-      progressImage.parentNode.removeChild(progressImage);
+var onLoadHandler = function (event) {
+  queryParameters = parseQueryParameters('' + window.location);
+  if (!document.body.hasClassName("popup")) {
+    initLogConsole();
+    initializeMenus();
+    initCriteria();
   }
+  initTabs();
+  configureDragHandles();
+  configureSortableTableHeaders();
+  configureLinkBanner();
+  var progressImage = $("progressIndicator");
+  if (progressImage)
+    progressImage.parentNode.removeChild(progressImage);
 }
 
 function configureSortableTableHeaders() {
@@ -998,17 +1102,21 @@ function configureLinkBanner() {
   var linkBanner = $("linkBanner");
   if (linkBanner) {
     var anchors = linkBanner.childNodesWithTag("a");
-    for (var i = 0; i < 4; i++) {
+    for (var i = 0; i < 2; i++) {
       anchors[i].addEventListener("mousedown", listRowMouseDownHandler,
                                   false);
       anchors[i].addEventListener("click", onLinkBannerClick, false);
     }
-    if (anchors.length > 5)
-      anchors[5].addEventListener("click", toggleLogConsole, true);
+    if (anchors.length > 3)
+      anchors[3].addEventListener("click", toggleLogConsole, true);
   }
 }
 
-window.addEventListener("load", onLoadHandler, false);
+if (window.addEventListener) {
+  window.addEventListener('load', onLoadHandler, false);
+} else if (document.addEventListener) {
+  document.addEventListener('load', onLoadHandler, false);
+}
 
 /* stubs */
 function configureDragHandles() {
@@ -1020,3 +1128,7 @@ function initializeMenus() {
 function onHeaderClick(event) {
   window.alert("generic headerClick");
 }
+
+function parent$(element) {
+   return window.opener.document.getElementById(element);
+}