function main_getWindowInfo() {
	var scrollTop, clientHeight, scrollLeft;
	scrollTop = clientHeight = scrollLeft = 0;
	// Get window details
	if (typeof(window.innerHeight) == 'number') {
		clientHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		clientHeight = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		clientHeight = document.body.clientHeight;
	}
	if (typeof(window.pageYOffset) == 'number') {
		scrollTop = window.pageYOffset;
		scrollLeft = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		scrollTop = document.body.scrollTop;
		scrollLeft = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		scrollTop = document.documentElement.scrollTop;
		scrollLeft = document.documentElement.scrollLeft;
	}
	var scrollHeight = document.body.scrollHeight;

	return {scrollTop: scrollTop, scrollLeft: scrollLeft, clientHeight: clientHeight, scrollHeight: scrollHeight};
}

var savepos = 0;

function main_memClickScrollPos() {
  var pos = main_getWindowInfo();
  document.cookie = "scrollPos=" + pos.scrollTop;
  savepos = 1;
}

function main_memScrollPos() {
  if (!savepos)
    document.cookie = "scrollPos=0";
}


var main_oldUnload = window.onunload;
window.onunload = function () { main_memScrollPos(); if (main_oldUnload) main_oldUnload(); };
var main_oldLoad = window.onload;
window.onload = function () { main_restoreScrollPos(); if (main_oldLoad) main_oldLoad(); };


function main_restoreScrollPos() {
	var scrollValue = document.cookie.match( /scrollPos=(\d+)/ );
	if ( scrollValue ) {
		var pos = parseInt( scrollValue[1] );
		if (pos != 0) {
      if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
  			document.body.scrollTop = pos;
	  	} else if (document.documentElement) {
		  	document.documentElement.scrollTop = pos;
		  }
    }
	}
}

