function getFileName()   //  获取当前文件名
{
	var url = this.location.href;
	var pos = url.lastIndexOf("/");
	if(pos == -1) pos = url.lastIndexOf("\\");
	var filename = url.substr(pos+1);

	pos = filename.indexOf("?");
	if(pos != -1) filename = filename.substr(0, pos);

	return filename;
}

function fnLoad()
{
	with(window.document.body)
	{
		addBehavior("#default#userData");	   // 使得body元素可以支持userdate
		load("scrollState" + getFileName());	// 获取以前保存在userdate中的状态

		scrollLeft = getAttribute("scrollLeft");	// 滚动条左位置
		scrollTop = getAttribute("scrollTop");
	}
}

function fnUnload()
{
	with(window.document.body)
	{
		setAttribute("scrollLeft", scrollLeft);
		setAttribute("scrollTop", scrollTop);
		save("scrollState" + getFileName());
	}
}

window.onload = fnLoad;
window.onunload = fnUnload;

function getScroll()
{
     var t, l, w, h;
     if (document.documentElement && document.documentElement.scrollTop) {
         t = document.documentElement.scrollTop;
         l = document.documentElement.scrollLeft;
         w = document.documentElement.scrollWidth;
         h = document.documentElement.scrollHeight;
     }
     else if (document.body) {
         t = document.body.scrollTop;
         l = document.body.scrollLeft;
         w = document.body.scrollWidth;
         h = document.body.scrollHeight;
     }
     return { top: t, left: l, width: w, height : h };
}
 
