﻿var SessionKeeper=
{
	DEFAULT_TIMEOUT:4.5*60*1000
	,DEFAULT_FOLDER:"/shopper/"
	,_frame:null
	,_timeout:null
	,_folder:null
	,KeepSession:function()
	{
		var f,s;
		if(!(f=this._frame))
		{
			this._frame=f=document.createElement("iframe");
			f.style.display="none";
			document.body.appendChild(f);
		}
		f.src=((this._folder==null)?this.DEFAULT_FOLDER:this._folder)+"sessionkeeper.aspx?x="+Math.random()+"&y="+Math.random();
		this.StartTimer();
	}
	,StartTimer:function()
	{
		var T=this._timeout,L,rx,k,s;
		if(!T)
		{
			try
			{
				//when calling this script place the numnber of MINUTES that a session lasts
				L=document.getElementsByTagName("script");
				rx=/js\/sessionkeeper\.js(\?|$)/i;
				for(k=0;k<L.length;k++)
				{
					if(!(s=L[k].getAttribute("src")))continue;
					if(!s.match(rx))continue;
					k=s.toLowerCase().indexOf("js/sessionkeeper.js");
					if(k==0)
						this._folder="";
					else
						this._folder=s.substr(0,k);
					k=s.lastIndexOf("?");
					if((k>0)&&(k<s.length-1))
						if((s=s.substr(k+1).replace(/\D/g,"")).length)
						{
							if(isNaN(T=parseInt(s)))
								T=null;
							else if(T<=0)
								T=null;
							else
							{
								T*=(60*1000);
								if(T>=(60*1000))
									T-=(30*1000);
								else
									T=Math.ceil(.95*T);
							}
						}
					if(!T)
						T=this.DEFAULT_TIMEOUT;
					this._timeout=T;
					break;
				}
			}
			catch(e)
			{ }
			if(!T)T=this.DEFAULT_TIMEOUT;
		}
		setTimeout("SessionKeeper.KeepSession()",T);
	}
};
SessionKeeper.StartTimer();
