var pnltoid;
var currDIV;
var currImg;
var currLeft;
var currTop;

var error = new String('failed to load, try again!');
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function collapexpand(node)
{
  var firstDIV = node.nextSibling;
  while (firstDIV!=null && firstDIV.nodeName!="SPAN")
  {
    firstDIV = firstDIV.nextSibling;
  }
  var td = node.parentNode;
  while (td.nodeName!='TD')
     td = td.nextSibling;
  td = td.nextSibling;
  while (td.nodeName!='TD')
     td = td.nextSibling;
  nextDIV = td.firstChild;
  while(nextDIV.nodeName != "DIV")
  {
     nextDIV = nextDIV.nextSibling;
  }
  if (nextDIV.style.display == 'none')
  {
    if (node.childNodes.length > 0)
    {
        for (var i=0;i<node.childNodes.length;i++)
        {
            if (node.childNodes.item(i).nodeName == "IMG")
            {
               currImg=node.childNodes.item(i);
               if (currImg.src.indexOf("empty.gif")!=-1)
                    return;
               if (nextDIV.firstChild!=null || nextDIV.innerHTML=='')
                   currImg.src = imgDir(node.childNodes.item(i).src) + "minus1.gif";
               else
                   currImg.src = imgDir(node.childNodes.item(i).src) + "empty.gif";
               currImg.align="top";
               break;
            }
       }
    }
    nextDIV.style.display = 'block';
    if (firstDIV!=null)
    {
      firstDIV.style.display = '';
      firstDIV.style.width='1px';
      firstDIV.style.height=node.parentNode.style.height;
      firstDIV.style.borderLeft='#333333 1px solid';
    }
    node.parentNode.bgColor = '#eeeeee';
    if (nextDIV.innerHTML.trim()=='' || nextDIV.innerHTML==error)
    {
       nextDIV.innerHTML ='loading ...';
       nextDIV.style.color = "#aaaaaa";
       currDIV = nextDIV;
       pnltoid=window.setTimeout("display_wait()", 300);
       currDIV = nextDIV;
       var id = nextDIV.id;
       var url = approot+'/cache/GroupsLoader.aspx?nid='+id;
       if (typeof target != 'undefined' && target!=null)
         url += '&target='+target;
       window.frames["dataloader"].window.location=url;
    }
  }
  else
  {
    if (node.childNodes.length > 0)
    {
        for (var i=0;i<node.childNodes.length;i++)
        {
           if (node.childNodes.item(i).nodeName == "IMG")
          {
             currImg=node.childNodes.item(i);
             if (nextDIV.firstChild!=null)
                 node.childNodes.item(i).src = imgDir(node.childNodes.item(i).src) + "plus1.gif";
             currImg.align="middle";
             break;
          }
       }
    }
    nextDIV.style.display = 'none';
    //nextDIV.innerHTML='';
    if (firstDIV!=null)
    {
      firstDIV.style.display = 'none';
    }
  }
}

function setHtml(div,html)
{
   if (html!='')
      div.innerHTML=html;
   else
   {
      currImg.src=imgDir(currImg.src) + "empty.gif";
      div.style.display='none';
   }
}

function groupAction(o,verb,id)
{
   if (typeof currContextId=='undefined' || currContextId=='')
      return;
   // action code here
   if (o.childNodes!=null)
   {
      var span = o.childNodes.item(0);
      while (span!=null && span.nodeName!="SPAN")
        span = span.nextSibling;
      currDIV = span;
   }
   else
   {
      currDIV = document.getElementById('pan'+id);
      if (currDIV==null)
        currDIV = document.getElementById('panelProg');
   }
   if (currDIV!=null)
   {
       if (id==currContextId)
          return;
       var url = approot+'/cache/GroupActions.aspx?nid='+id+'&act='+verb;
       if (typeof target != 'undefined' && target!=null)
         url += '&target='+target;
       window.frames["dataloader"].window.location=url;
       pnltoid=window.setTimeout("display_wait()", 300);
   }

}

function showmessage(o,msg)
{
   getpos(o);
   div = document.getElementById('msg');
   div.style.backgroundColor='transparent'; //null;//'tomato';
   div.style.color="white";
   div.innerHTML=' '+msg+' ';
   if (typeof div.filters != 'undefined')
        div.filters.alpha.opacity=60;
   div.style.left =currLeft-5;
   if (typeof o.getBoundingClientRect!='undefined')
   {
       var rect = o.getBoundingClientRect();
       div.style.top  =currTop-rect.bottom+rect.top-5;
   }
   else
       div.style.top  =currTop-10-5;
   div.style.display='';

}
function showmessage2(o,msg,details,bgcolor)
{
   getpos(o);
   div = document.getElementById('msg');
   div.style.backgroundColor=bgcolor;
   if (typeof div.filters != 'undefined')
       div.filters.alpha.opacity=80;
   div.style.color="white";
   div.innerHTML=' '+msg+' ';
   div.style.left =currLeft+50;
   div.style.whiteSpace = 'nowrap';
   if (typeof o.getBoundingClientRect!='undefined')
   {
         var rect = o.getBoundingClientRect();
         div.style.top  =currTop-rect.bottom+rect.top-20;
   }
   else
   {
        div.style.width=200;
        div.style.top  =currTop-10-20;
   }
   div.style.display='';
   div = document.getElementById('detailmsg');
   o   = document.getElementById('panelProg');
   getpos(o);
   if (typeof div.filters != 'undefined')
       div.filters.alpha.opacity=70;
   else
       div.style.width=165;
   div.style.color="white";
   div.style.backgroundColor="818181";
   div.style.display='';
   div.style.zIndex=1;
   div.style.left =currLeft+3;
   div.style.top  =currTop+10;
   div.style.whiteSpace = 'normal';
   div.innerHTML='<p>'+details+'</p>';

}
function hidemessage()
{
   div = document.getElementById('msg')
   div.style.display='none';
   div = document.getElementById('detailmsg');
   div.innerHTML='';
   div.style.display='none';
   div.style.zIndex=-1;
}

function getpos(o)
{
    currLeft=0;
    currTop=0;
    if (typeof o.offsetLeft != 'undefined')
    {
       do
       {
         currLeft += o.offsetLeft;
         currTop  += o.offsetTop;
         o = o.offsetParent;
       } while (o)
    }
}

function imgDir(source)
{
  return source.substring(0, source.lastIndexOf('/') + 1);
}

var cnt=0;
function display_wait()
{
  cnt++;
  if (cnt<80)
  {
      if (currDIV.innerHTML.length<25)
          currDIV.innerHTML += '.';
      else
          currDIV.innerHTML = '.';
      pnltoid=window.setTimeout("display_wait()", 300);
  }
  else
  {
      currDIV.innerHTML = error;
      cnt=0;
  }
}

function stopWait()
{
  cnt=0;
  window.clearTimeout(pnltoid);
}



