  var win = null;
  
  function onBeforeUnload()
  {
    saveToCache();
  }  

  function closePopup()
  {
    if (win != null) win.close(); 
      win = null;           
  }
                                        
  function openWindow(wnd, _width, _height)
  {
    closePopup();
    posx = (screen.width) ?   (screen.width-_width)/2 : 0;
    posy = (screen.height) ? (screen.height-_height)/2 : 0;
    settings = 'height='+_height+',width='+_width+',top='+posy+',left='+posx+',scrollbars=yes,resizable=yes,alwaysRaised=yes'
    win = window.open(wnd,'popwindow',settings)
    if(win.window.focus){win.window.focus();}
  }
  function onScroll()
  {
    userInteraction=true;
  }
  function onClick()
  {
    userInteraction=true;
  }

  function onKeyDown()
  {
    userInteraction=true;
  }

  var userInteraction=false;
  var rtbIds;

  function saveToCache()
  {
    if (rtbIds)
    {
      for (var i = 0; i < rtbIds.length; i++)    
      {
        var c; 
        if (document.all[rtbIds[i]])
        {
          c = eval(rtbIds[i]); 
          if (c && c.document && document.getElementById != null) 
          {
            document.getElementById("RTBCache_" + rtbIds[i]).value=c.document.body.innerHTML;
          }
        }
      }
    }
  }
  function loadFromCache()
  {
    if (rtbIds)
    {
      for (var i = 0; i < rtbIds.length; i++)    
      {
        var v = document.getElementById("RTBCache_" + rtbIds[i]).value;
        if (v != "")
        {
          var d; 
          d = eval(rtbIds[i] + ".document");
          d.body.innerHTML=v;
        }
      }
    }
  }
  function onLoadEventHandler()
  {
    
    loadFromCache();
    if (!userInteraction && typeof setInitialFocus != 'undefined') setInitialFocus();
  }  


  function isIE()
  {
    var naVer=navigator.appVersion;
    var naAgn=navigator.userAgent;
    var nIE=document.all ? 1 : 0;
    var nVer=parseFloat(naAgn.substring(naAgn.indexOf("MSIE ")+5,naAgn.length));
    var nOP=naAgn.indexOf("Opera")>=0;

    if(nIE && nVer>=5 && !nOP)
      return true;

    return false;

  }



