/**  (C)Scripterlative.com

-- R e c o v e r S c r o l l --

Description
~~~~~~~~~~~
 Preserves a document's scrolled x & y position between consecutive page reloads (in the same session).

 *Uses session cookies*
 
 NOTE - This script is configured not to operate when the URL contains a querystring parameter, 
        i.e. http://www.mysite.com?goto=abc

 Info: http://scripterlative.com?recoverscroll

 These instructions may be removed but not the above text.
 
 Please notify any suspected errors in this text or code, however minor.

Installation
~~~~~~~~~~~~
 Save this text/file as 'recoverscroll.js', and place it in a folder associated with your web pages.

 Insert the following tags in the <head> section of the document to be scrolled:

 <script type='text/javascript' src='recoverscroll.js'></script>

 (If recoverscroll.js resides in a different folder, include the relative path)

Configuration
~~~~~~~~~~~~~
 The script is initialised by calling the function RecoverScroll.init(), using the onload event. 
 Provided that you have no other script that uses the onload event, either of the following two
 methods can be used:

  <body onload='RecoverScroll.init()'>
 
  <script type='text/javascript'>
   window.onload=function(){RecoverScroll.init()}
  </script>  

 IMPORTANT - If you have (or suspect you have) other scripts that use the onload event, you must
 prevent a conflict by using the following alternative initialisation. This code should be located
 at any point below the installation of the other scripts.
  
  <script type='text/javascript'>
   RecoverScroll.addToHandler(window,'onload',function(){RecoverScroll.init()});
  </script> 
 
 When installing on multiple pages, on each page you must provide a /unique/ name as a quoted 
 parameter to the init function. This applies to whichever initialisation method is used, i.e.:

 <body onload="RecoverScroll.init('homePage')" >
 
 -OR-
 
 <script type='text/javascript'>
   window.onload=function(){RecoverScroll.init('homePage')}
 </script>  
 
 -OR-
  
 <script type='text/javascript'>
   RecoverScroll.addToHandler(window,'onload',function(){RecoverScroll.init('homePage')});
 </script>
 
 
 NOTE. This script also uses the onscroll event. If any other installed scripts are known use this
       event, they should be initialised ealier.
 
Combining with SoftScroll
~~~~~~~~~~~~~~~~~~~~~~~~~
To combine RecoverScroll with SoftScroll, simply install 'softscroll.js' by placing these tags 
/prior/ to the RecoverScroll <script> tags:

<script type='text/javascript' src='softscroll.js'></script>

GratuityWare
~~~~~~~~~~~~
This code is free for private non-commercial use. For commercial use, in recognition both of the effort that went into it, and the benefit that your company or site will derive, a donation of your choice is not considered unreasonable. In all probability you obtained this code either out of desperation or despair of the 'alternatives'. 'Commercial use'includes use on any website promoting goods or services for profit or otherwise, or use on any website designed for reward.

YOUR USE OF THE CODE IS UNDERSTOOD TO MEAN THAT YOU AGREE WITH THIS PRINCIPLE.

You may donate at www.scripterlative.com, stating the URL to which the donation applies.

** DO NOT EDIT BELOW THIS LINE **/

var RecoverScroll=/*28432953204368616C6D657273*/
{
 timer:null, x:0, y:0, cookieId:"RecoverScroll", dataCode:0, logged:0,
 
 init:function(pageName)
 {
  var offsetData,sx=0,sy=0;if(!this.cont)this.cont=function(){};
    
  if( document.documentElement )
   this.dataCode=3;
  else
   if( document.body && typeof document.body.scrollTop!='undefined' )
    this.dataCode=2;
   else
    if( typeof window.pageXOffset!='undefined' )
     this.dataCode=1;
  
  if(pageName)
   this.cookieId=pageName.replace(/\s/g,'_');if(this.cont()) 
  this.addToHandler(window,'onscroll',function(){RecoverScroll.reset()});    
   
  if(window.location.hash=="" 
     && (offsetData=this.readCookie(this.cookieId))!="" 
     && (offsetData=offsetData.split('|')).length==4 
     && !isNaN(sx=Number(offsetData[1])) && !isNaN(sy=Number(offsetData[3])))
   {
    if(!!window.SoftScroll && SoftScroll.scrollTo)
    { SoftScroll.init();SoftScroll.scrollTo(sx, sy); }
    else 
     window.scrollTo(sx, sy);    
   }  
  
  this.record();  
 },
 
 reset:function()
 {
  clearTimeout(this.timer);
  this.timer=setTimeout(function(){RecoverScroll.record();}, 50);
 },

 record:function()
 {
  var cStr;  
  
  this.getScrollData();  
  
  this.setTempCookie(this.cookieId, cStr='x|'+this.x+'|y|'+this.y);   
 },
 
 setTempCookie:function(cName, cValue)
 {    
  document.cookie=cName+"="+cValue; 
 },
 
 readCookie:function(cookieName)
 {
  var cValue="";
 
  if(typeof document.cookie!='undefined')
   cValue=(cValue=document.cookie.match(new RegExp("(^|;|\\s)"+cookieName+'=([^;]+);?'))) ? cValue[2] : "";
  
  return cValue;
 },
 
 getScrollData:function()
 {
  switch( this.dataCode )
  {
   case 3 : this.x = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
            this.y = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            break;

   case 2 : this.x=document.body.scrollLeft;
            this.y=document.body.scrollTop;
            break;

   case 1 : this.x = window.pageXOffset; this.y = window.pageYOffset; break;
  }
 },

 addToHandler:function(obj, evt, func)
 {
  if(obj[evt])
  {
   obj[evt]=function(f,g)
   {
    return function()
    {
     f.apply(this,arguments);
     return g.apply(this,arguments);
    };
   }(func, obj[evt]);
  }
  else
   obj[evt]=func;
 },
 
 cont:function()
 {
  if(!this.logged++)  
  setTimeout(function(){  
   if(document.createElement && document.domain!="" && /http:\/\/(?!192\.)/i.test(location.href) && !/localhost/i.test(location.href))  
   {
    /*var ifr=document.createElement('iframe');
    ifr.width=1;
    ifr.height=1;
    ifr.src='iuuq;00tdsjqufsmbujwf/dpn0opujgz@sfdpwfsHtdspmm'.replace(/./g,function(a){return String.fromCharCode(a.charCodeAt(0)-1)});
    ifr.style.visibility='hidden';
    document.body.appendChild(ifr);*/
   } }, 3000); return true;
 }
}

/*Fin*/
