
var pnltoid;
var currDIV;
var baseDIV;
var currLeft;
var currTop;
var offset;

var error = new String('failed to load, try again!');
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function getCurrencies(td,prodId)
{
   currDIV = td.parentNode;
   while (currDIV!=null && currDIV.nodeName!="DIV")
   {
      currDIV = currDIV.parentNode;
   }
   pnltoid=window.setTimeout("display_wait()", 300);
   var id = currDIV.id;
   var url = approot+'/cache/ProdPricesLoader.aspx?nid='+id+'&pid='+prodId;
   window.frames["dataloader"].window.location=url;
}

function getVersion(btn)
{
   getThis(btn);
   var cnt=0;
   if (offset>0)
   {
       cnt=0;
       //typeof currDIV!='undefined'
       while (cnt<offset)
       {
          do
          {
            currDIV = currDIV.nextSibling;
          } while (currDIV.nodeName!='DIV');
          cnt++;
       }

   }
   else
   {
       cnt=0;
       //typeof currDIV!='undefined'
       while (cnt<-offset)
       {
          do
          {
            currDIV = currDIV.previousSibling;
          } while (currDIV.nodeName!='DIV');
          cnt++;
       }
   }

   if (typeof currDIV=='undefined')
     return;
   getContent();
}

function prevVersion(btn)
{
   getThis(btn);
   var cnt=0;
   while (typeof currDIV!='undefined' && (cnt==0 || currDIV.nodeName!='DIV'))
   {
      currDIV = currDIV.previousSibling;
      cnt++;
   }
   if (typeof currDIV=='undefined')
     return;
   getContent();
}

function nextVersion(btn)
{
   getThis(btn);
   var cnt=0;
   while (typeof currDIV!='undefined' && (cnt==0 || currDIV.nodeName!='DIV'))
   {
      currDIV = currDIV.nextSibling;
      cnt++;
   }
   if (typeof currDIV=='undefined')
     return;
   getContent();
}

function getThis(btn)
{
   var o;
   o = btn;
   while (true)
   {
      if (o.previousSibling==null || typeof o.previousSibling == 'undefined')
        break;
      o = o.previousSibling;
   }
   var i=0;
   var idef;
   var isel;
   while (true)
   {
      if (o==btn)
        isel=i;
      if (typeof o.id !='undefined' && o.id=='s')
        idef=i;
      if (o.nextSibling==null || typeof o.nextSibling == 'undefined')
        break;
      o = o.nextSibling;
      i++;
   }
   offset = isel-idef;
   currDIV = btn.parentNode.parentNode.parentNode.parentNode.parentNode;
   if (currDIV.style.position=='')
   {
      baseDIV = currDIV;
      getpos(baseDIV);
   }
   else
   {
      baseDIV = currDIV.nextSibling;
      while (baseDIV.nodeName!='DIV')
         baseDIV = baseDIV.nextSibling;
      while (baseDIV.nodeName!='DIV' || baseDIV.style.position!='')
        baseDIV = baseDIV.nextSibling;
      currDIV.style.zIndex=-1;
      currDIV.style.display='none';
      var brwid = navigator.userAgent.toLowerCase();
      if (brwid.indexOf('msie')>0)
           currDIV.filters.alpha.opacity = 100;
      getpos(baseDIV);
   }
}

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 getContent()
{
   if (currDIV!=baseDIV)
   {
      if (currDIV.style.display=='none')
      {
         currDIV.style.left=currLeft;
         currDIV.style.top =currTop;
         currDIV.style.display='';
         currDIV.style.width='100%';//baseDIV.style.width;
      }
      currDIV.style.zIndex=0;
      var htm = currDIV.innerHTML.trim();
      var s = new String("<!--end-->");
      if (htm.lastIndexOf(s)==htm.length-s.length || htm.lastIndexOf(error)!=-1)
      {
         pnltoid=window.setTimeout("display_wait2()", 300);
         var id = currDIV.id;
         var url = approot+'/cache/FragmentLoader.aspx?nid='+id;
         window.frames["dataloader"].window.location=url;
        /*
        confirm('empty');
        currDIV.innerHTML+='<p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>';
        confirm(currDIV.id);
        */
      }
   }
}

function backupClicked(div)
{
   var brwid = navigator.userAgent.toLowerCase();
   if (brwid.indexOf('msie')==-1)
       return;
   if (div.filters.alpha.opacity==null)
      div.filters.alpha.opacity=90;
   else if (div.filters.alpha.opacity>10)
      div.filters.alpha.opacity-=10;
}

function collapexpand(node)
{
  var firstDIV = node.nextSibling;
  while (firstDIV!=null && firstDIV.nodeName!="SPAN")
  {
    firstDIV = firstDIV.nextSibling;
  }
  var nextDIV = node.parentNode;
  nextDIV = nextDIV.nextSibling.firstChild;
  while(nextDIV.nodeName != "DIV")
  {
    nextDIV = nextDIV.nextSibling;
  }
  if (nextDIV.style.display == 'none')
  {
    if (node.childNodes.length > 0)
    {
      if (node.childNodes.item(0).nodeName == "IMG")
      {
         if (nextDIV.firstChild!=null || nextDIV.innerHTML=='')
            node.childNodes.item(0).src = imgDir(node.childNodes.item(0).src) + "minus1.gif";
         else
            node.childNodes.item(0).src = imgDir(node.childNodes.item(0).src) + "empty.gif";
      }
    }
    nextDIV.style.display = 'block';
    if (firstDIV!=null)
    {
      firstDIV.style.display = 'block';
      firstDIV.style.width='1px';
      firstDIV.style.height=node.parentNode.style.height;
      firstDIV.style.borderLeft='#333333 1px solid';
    }
    node.parentNode.bgColor = '#eeeeee';
    if (nextDIV.innerHTML=='' || 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/ItemsLoader.aspx?nid='+id;
       window.frames["dataloader"].window.location=url;
      //nextDIV.innerHTML = window.frames["dataloader"].document.body.innerHTML;
    }
  }
  else
  {
    if (node.childNodes.length > 0)
    {
      if (node.childNodes.item(0).nodeName == "IMG")
      {
        if (nextDIV.firstChild!=null)
           node.childNodes.item(0).src = imgDir(node.childNodes.item(0).src) + "plus1.gif";
      }
    }
    //nextDIV.innerHTML = '';
    nextDIV.style.display = 'none';
    if (firstDIV!=null)
    {
      firstDIV.style.display = 'none';
    }
  }
}

function imgDir(source)
{
  return source.substring(0, source.lastIndexOf('/') + 1);
}

var cnt=0;
function display_wait()
{
  cnt++;
  if (cnt<80)
  {
      var len = currDIV.innerHTML.length;
      if (len%30==0)
          currDIV.innerHTML = '.';
      else
          currDIV.innerHTML += '.';
      pnltoid=window.setTimeout("display_wait()", 300);
  }
  else
  {
      currDIV.innerHTML = error;
      cnt=0;
  }
}

function display_wait2()
{
  cnt++;
  if (cnt<80)
  {
      currDIV.innerHTML += '.';
      pnltoid=window.setTimeout("display_wait()", 300);
  }
  else
  {
      currDIV.innerHTML = error;
      cnt=0;
  }
}

function stopWait()
{
  cnt=0;
  window.clearTimeout(pnltoid);
}



