function pageHeight() {
		return window.innerHeight != null? window.innerHeight:
				document.documentElement && document.documentElement.clientHeight ? 
				document.documentElement.clientHeight:document.body != null? 
				document.body.clientHeight:null;}
				
function pageWidth() {
		return window.innerWidth != null? window.innerWidth:
				document.documentElement && document.documentElement.clientWidth ? 
				document.documentElement.clientWidth:document.body != null? 
				document.body.clientWidth:null;}
				
function pageTop() {		
		return window.pageYOffset != null? window.pageYOffset :
			document.documentElement.scrollTop != null ? document.documentElement.scrollTop :
			document.body.scrollTop != null? document.body.scrollTop : 0;
}

function changeAllDropDownsVisibility(parentNode,visible) {
	if (parentNode == null) parentNode = document;
	dropdowns=parentNode.getElementsByTagName("SELECT");	
	if (visible) { visibilitytext = 'visible'; } else {visibilitytext = 'hidden';}
	for (var i=0;i<dropdowns.length;i++) {
		var dropdown = dropdowns[i];
		dropdown.style.visibility=visibilitytext;
	}	
}

function setPageTop(pageTopValue) {		
	if (document.documentElement.scrollTop != null) {
		document.documentElement.scrollTop = pageTopValue;
		return;
	} else if (window.pageYOffset != null) {
		window.pageYOffset = pageTopValue;
		return;
	} else if (document.body.scrollTop != null) {
		document.body.scrollTop = pageTopValue;
		return;
	} 
}


function setupAutoVerticalPositioning() {
  if (window.addEventListener != null) {
	// chain an event handler to the onunload event which 
	// will store current top value in a cookie		
	window.addEventListener('unload', StoreVerticalPosition, true);
	// chain an event handler to the onload event which 
	// will look for the cookie, and set the top value 
	window.addEventListener('load', SetVerticalPosition, true);
 } else {
	window.attachEvent('onunload', StoreVerticalPosition);
	window.attachEvent('onload', SetVerticalPosition);
 }  
}

function StoreVerticalPosition() {	
	createCookie('FMPageTop', pageTop());	
	createCookie('FMPageTopURL', document.location);
}

function SetVerticalPosition() {	
	var pagetop = readCookie('FMPageTop');
	var pagetopURL = readCookie('FMPageTopURL');	
	if (pagetopURL == document.location) {
		if (pagetop != null) {
			setPageTop(pagetop);
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


setupAutoVerticalPositioning();