pbs_OtherOnLoad = (window.onload) ? window.onload :  new Function;
window.onload = function(){setTimeout("pbs_StartIt()",10)};
var pbs_OtherUnOnLoad = null;

function pbs_StartIt()
{        

    if(getCookie(GetScriptName()) != null)
    {    
        var iScrollTop = getCookie(GetScriptName());
        window.scroll(0,iScrollTop);
        delCookie (GetScriptName());
    }

    pbs_OtherUnOnLoad = (window.onunload) ? window.onunload :  new Function;    
    window.onunload = StoreScrollPosition;        
    
    pbs_OtherOnLoad();
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function GetScriptName()
{
    var sScriptName = document.location.href;
    if(sScriptName.indexOf("?") > -1)
        sScriptName = sScriptName.substring(0, sScriptName.lastIndexOf("?"));
            
    return sScriptName;
}

function StoreScrollPosition()
{
    var iScrollTop = f_scrollTop()
    setCookie(GetScriptName(), iScrollTop);

    if(pbs_OtherUnOnLoad != null)
        pbs_OtherUnOnLoad();
}

function getCookie(NameOfCookie)
{ 
	if (document.cookie.length > 0) 
	{ 
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		if (begin != -1) 
		{ 
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) 
				end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		} 
	}
	
	return null; 
}

function setCookie(NameOfCookie, value, expireseconds) 
{ 
	var ExpireDate = new Date ();	
	ExpireDate.setTime(ExpireDate.getTime() + ( expireseconds * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expireseconds == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



function delCookie (NameOfCookie) 
{ 
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}