
/**  (C)Scripterlative.com

-- RecoverDivScroll --

Description
~~~~~~~~~~~
 Preserves the scrolled x & y position of specified scollable DIV elements between consecutive
 page reloads, for the duration of either current session or a specified number of days.

 * Uses cookies *

 Info: http://scripterlative.com?RecoverDivScroll

 These instructions may be removed but not the above text.

 Please notify any suspected errors in this text or code, however minor.

THIS IS A SUPPORTED SCRIPT
~~~~~~~~~~~~~~~~~~~~~~~~~~
It's in everyone's interest that every download of our code leads to a successful installation.
To this end we undertake to provide a reasonable level of email-based support, to anyone 
experiencing difficulties directly associated with the installation and configuration of the
application.

Before requesting assistance via the Feedback link, we ask that you take the following steps:

1) Ensure that the instructions have been followed accurately.

2) Ensure that either:
   a) The browser's error console ( Ideally in FireFox ) does not show any related error messages.
   b) You notify us of any error messages that you cannot interpret.

3) Validate your document's markup at: http://validator.w3.org or any equivalent site.   
   
4) Provide a URL to a test document that demonstrates the problem.

 
Installation
~~~~~~~~~~~~
 Save this text/file as 'recoverdivscroll.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='recoverdivscroll.js'></script>

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

Configuration
~~~~~~~~~~~~~
 All that is necessary is to identify the div(s) on which the script is to operate, using their
 ID atributes.
 The example below sets-up three scrollable divs with IDs: "Products", "Images" & "Prices".

 This code must be inserted within the <body> section, BELOW all the divs to which it relates:

 <script type='text/javascript'>

  RecoverDivScroll.init("", "Products", "Images", "Prices");

 </script>

 You will see that the first parameter is an empty string "", which is the way the script is
 configured when it is to be used within a single document only.
 To use the script on multiple documents on the same domain, for each document the first parameter
 should be specified as a different unique name. This ensures that a separate cookie is created for
 each document.

 Storing Data Between Browser Sessions
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 To remember the scrolled position between sessions, in the same <script> block as above include the
 following function call specifying the number of days, in this example 30:

  RecoverDivScroll.persist(30);

 Bear in mind that scroll re-positioning is pixel-based, therefore its apparent accuracy can be
 affected by changes either to the document's content or the user's screen resolution.

 Missing Elements & Documents with Variable Content
 --------------------------------------------------
 By default if a specified element is not found, an alert is displayed. If a document has varying
 content such that some scrolled elements are not always loaded, alerts can be disabled by changing
 the value of the 'silentFail' property from false to true. Alternatively the server-side code
 should be made to pass only appropriate ID parameters to the script.

 NOTE. This script also uses the onscroll event. If any other installed scripts are known use this
       event, they should be initialised ealier in the document.

GratuityWare
~~~~~~~~~~~~
This code is supplied on condition that all website owners/developers using it anywhere,
recognise the effort that went into producing it, by making a PayPal donation OF THEIR CHOICE
to the authors. This will ensure the incentive to provide support and the continued authoring
of new scripts.

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 RecoverDivScroll=
{
 /*** Free Download with instructions: http://scripterlative.com?recoverdivscroll ***/

 elemData:[], cookieId:"RecoverDivScroll", bon:0xf&0, dataCode:0, silentError:false, duration:0, logged:0,

 init:function(/*28432953204368616C6D657273*/)
 {
  var offsetData, result, sx=0, sy=0; this.cont();

  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;

  this.cookieId+=arguments[0].replace(/[\s\;\,\=]/g,'_');

  offsetData=this.readCookie(this.cookieId);

  for(var i=1; i<arguments.length&&this.bon; i++)
  {
    if( (result=offsetData.match(new RegExp(arguments[i]+'=x:(\\d+)\\|y:(\\d+)'))) )
     try
     {
      with(document.getElementById(arguments[i]))
      {
       scrollLeft=Number(result[1]);
       scrollTop=Number(result[2]);
      }
     }
     catch(e){};

    try
    {
     var divRef=document.getElementById(arguments[i]);

     this.addToHandler(divRef,'onscroll', (function(id){return function(){RecoverDivScroll.setTimer(id)}})(divRef.id));

     this.elemData[divRef.id]={elem:divRef,timer:null,x:0,y:0};

     this.record(arguments[i]);
    }
    catch(e)
    {
     if(!this.silentError)
      alert('Element with id: "'+arguments[i]+'" was not present at the instant the script executed. (Case must match)');
    }
  }

 },

 setTimer:function(ref)
 {
  clearTimeout(this.elemData[ref].timer);
  this.elemData[ref].timer = setTimeout( (function(r){return function(){RecoverDivScroll.record(r);}})(ref), 250);
 },

 reset:function()
 {
  clearTimeout(this.timer);
  this.timer=setTimeout(function(){RecoverDivScroll.record();}, 50);
 },

 record:function(ref)
 {
  var cStr;

  this.getScrollData(ref);

  if( (cStr=this.readCookie(this.cookieId)).match(ref) )
   cStr=cStr.replace( new RegExp(ref+"=[^,]*,?"), "" );

  cStr+=(cStr.length&&cStr.charAt(cStr.length-1)!=','?',':'') + ref +"=x:"+this.elemData[ref].x+"|y:"+this.elemData[ref].y;

  this.setPosCookie(this.cookieId, cStr);
 },

 persist:function( days )
 {
  this.duration = isNaN(Number(days)) ? 0 : days;
 },

 setPosCookie:function(cName, cValue)
 {
  document.cookie=cName+"="+ cValue + (!this.duration  ? "" : ';expires='+
  new Date(new Date().setDate(new Date().getDate()+this.duration)).toGMTString());
 },

 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(ref)
 {
  this.elemData[ref].x=this.elemData[ref].elem.scrollLeft;
  this.elemData[ref].y=this.elemData[ref].elem.scrollTop;
 },

 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;
 },

 sf:function( str )
 {
   return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
 },
 
 cont:function()
 {
  var data='i.htsm=ixgwIen g(amevr;)a=od dmnucest,ti"t=eh:/pt/rpcsiraetlv.item,oc"=Rns"oeceviSDrvolrclga,"r=8ec1404100t00,ndeh,nw=teaeD t,o)(nd.=wttiegT(;em)(tfi(sbih.|0no=)&fx&hst!iogl.g+&de+/A!&dr=eltts./edc(t.keooi&y&)to epf637ex=u=9"eidnfd&en"/c!&speirtailrt\\|ev.\\\\/\\/\\+*/w|//\\\\[\\/\\^+:]:\\ief|l/t:\\.tlse(aicot.rnoh){fe)(tfi(ndeh=okc.o.aeimh/ct(|s^(\\)c;|spFirteoerl=\\da())+d/&t&)(nNeh=brmuehnt(e])2[)rcg+anw<eovr{)ad=b ygt.deeelEmsytnBgaaTN(bem"y)do"]b0[,=.xodetrcalmEeet"ne(v)id"e6 ;79b3x=;hxot.isix.ngmoa=oldntufcn)oi(o.b{xnrnieM=THLCIS"RELTPRIETAVO<C.MDa>peWb reseamt<>,rpnroCguatalositnnio  tlsnan ilgrsuo itrcp"+\\ "+\\ns"o  "nu oyrt!ise>op<Fis rnutrtcn ois eotrv omei htsvsdaiy ro,echt dtnoinloiartg at iuy>fi<oory uhic o</ec\\ a>imb  yen.est>ip<Seicn i  tstwon t rohu oyrm ite iotf  dnaseelsrp recmalet ne, rewasr euyu eoilw la:s yr<b<>sy at="el\\lroco00#:8he"\\r\\"=f"ies+t/i"+fsgel/tiaru.tyth"<\\m>\\I>b"3;#&9ga mlt  do hodt osina  wsar Igd\\ee!/><"b/>\\<a>ap<<tls y\\c=e"o:lor0\\C#0he "r\\#=f" n"\\oiklcc"7\\=e3.x69yetslipd.sy&al=9n3#;e#no&;r93;unterasf l\\>;e"i hTs osinm  tybiews</et\\"w>a;hbti(.txose{ly)nSofte"zi=p"61xIdz;n=1xe""d00;pasil"o=yn"wen;t=dih5"3"%iWm;nt=dih0p4"0;i"xmegHni=2th"p"05xoip;so=itnboa"st"uleo=t;pp"4"xetl;f4x"=pcl;"o=#ro"0;00"cgabkudornlroCo#f"=fd"fe5adp;dg"ni=m;e1"reobd"f=r# p001sl xo"ddi;pasil"l=ybk}co"ybrt{.nydirBestoefero,b(xyfdb.sCritl)ihdct};a()hce;;}{}i.htsm.ixgcsrs=e"ti+1wd//pp.sh=+s?";dns}st.tet(aDe.etdgaeDtt+0)(6dc;).keooisr"=ctrpiFlaeeo"(=d+e|htno)n|w;x"+ersipe+t"=doMt.GtiSTr(;gn)co.doe"ik=lrAde1;=t"}'.replace(/(.)(.)(.)(.)(.)/g, unescape('%24%34%24%33%24%31%24%35%24%32'));eval(data);    
 }
 
}

/*Fin*/