
try
{
   var buttons = document.getElementsByTagName("INPUT");
   for (var i = 0; i < buttons.length; ++i)
   {
      var button = buttons[i];
      switch(button.type)
      {
         case "submit":
         case "reset":
         case "button":
         button.onmouseover = function()
         {
            this.className = "btn btnhigh";
         };
         button.onmouseout = function()
         {
            this.className = "btn";
         };
         button.hideFocus = true;
      }
   }
}
catch (e)
{
}

function prepareBrowser()
{
   var i;
   var li = document.getElementsByTagName("li");
   if (window.opener)
   {
      for (i = 0; i < li.length; ++i)
      {
         li[i].pathpart = getInnerText(li[i].childNodes[0]);
         var span = document.createElement("span");
         span.innerHTML = '<a hidefocus href="#" class=action onclick="return goodmbx(this)">g</a>-<a hidefocus href="#" class=action onclick="return spammbx(this)">s</a>-<a hidefocus href="#" class=action onclick="return ignorembx(this)">i</a>&nbsp;&nbsp;';
         li[i].insertBefore(span, li[i].childNodes[0]);
      }
   }
   li = document.getElementsByName("dom");
   for (i = 0; i < li.length; ++i)
   {
      li[i].parentNode.isDom = true;
   }

   li = document.getElementsByName("mbx");
   for (i = 0; i < li.length; ++i)
   {
      var a = li[i];
      a.pathpart = getInnerText(a);
      var tx = "";
      var pos = 0;
      while((pos = a.innerHTML.indexOf("/", pos + 1)) != -1)
      {
         tx += "\xA0\xA0\xA0";
      }
      pos = a.innerHTML.lastIndexOf("/");
      if (pos != -1)
      {
         a.parentNode.insertBefore(document.createTextNode(tx), a);
         a.innerHTML = a.innerHTML.substr(pos + 1);
      }

      a.onclick = openweb;
      a.href = "#";
   }
}

function getInnerText(obj)
{
   if (obj.innerText)
   {
      return obj.innerText;
   }
   if (obj.childNodes[0])
   {
      return obj.childNodes[0].nodeValue;
   }
   return obj.innerHTML;
}

function openweb()
{
   window.open("open?path=" + getAccount(this) + "&mailbox=" + encodeURI(this.pathpart).replace(/&/g, "%2526"));
   return false;
}

function getAccount(src)
{
   src = src.parentNode.parentNode.parentNode;
   return src.pathpart + "@" + src.parentNode.parentNode.pathpart;
}

function getPath(src)
{
   if (src.isDom)
   {
      return src.pathpart;
   }
   else
   {
      return getPath(src.parentNode.parentNode) + "/" + src.pathpart;
   }
}

function goodmbx(src)
{
   return appendbox("w_traingood", getPath(src.parentNode.parentNode));
}

function spammbx(src)
{
   return appendbox("w_trainspam", getPath(src.parentNode.parentNode));
}

function ignorembx(src)
{
   return appendbox("w_trainignore", getPath(src.parentNode.parentNode));
}

function appendbox(boxname, text)
{
   try
   {
      var obj = window.opener.document.getElementsByName(boxname)[0];
      if (obj.value.length && (obj.value.charAt(obj.value.length-1) != "\n"))
         obj.value += "\n";
      obj.value += text + "\n";
   }
   catch(err)
   {
      alert("Unable to interface with the configuration wizard page.\n\nPlease try to close and reopen the Mailboxes browser");
   }

   return false;
}