/*****************************************************************************
 Window scroll saver.
 Munsifali Rashid.  mUnit Limited (www.munit.co.uk).  April 2005.
 
 Simply include this file into any page and it will retain the page scroll
 position across postbacks.
 
 If you are using the window.onload or window.unload events for anything,
 you will have to tweak the code a little.  saveScroll() must be called when
 the page unloads, and restoreScroll() must be called when the page loads.
*****************************************************************************/

var COOKIE_NAME = "MyCookieName";

function cookiemanager(allcookies)
{
	this.name		= COOKIE_NAME;
	this.items		= new Array();
	this.add		=	function(key, val)
						{
							this.items[key] = val;
						}
	this.makeCookie	=	function()
						{
							var a = "";
							for (key in this.items) a += key + ":" + escape(this.items[key]) + "&";
							a = a.substring(0, a.length-1);
							a = this.name + "=" + a;
							return a;
						}
	this.saveCookie	=	function()
						{
							document.cookie = this.makeCookie();
						}
	if (allcookies.indexOf(this.name) == -1) return;
	var start = allcookies.indexOf(this.name) + this.name.length + 1;
	var end = allcookies.indexOf(";", start);
	if (end == -1) end = allcookies.length;
	var cookie = allcookies.substring(start, end);
	var a = cookie.split("&");
	for (var i=0; i < a.length; i++)
	{
		var b = a[i].split(":");
		this.items[b[0]] = unescape(b[1]);
	}
}
var cm = new cookiemanager(document.cookie);

function saveScroll()
{
	var scrolltop = document.documentElement.scrollTop;
	cm.add("scrolltop", scrolltop);
	cm.saveCookie();
}
function restoreScroll()
{
	if (document.getElementById) if (cm.items["scrolltop"]) document.documentElement.scrollTop = cm.items["scrolltop"];
}
if ((document.getElementById) && (!window.onunload))	window.onunload	= saveScroll;
if ((document.getElementById) && (!window.onload))		window.onload	= restoreScroll;

