﻿function floatButton ()
{
    if (window.length > 0) return; // don't show button if iframe on page
	if (document.all)
	{
		document.all.topButton.style.pixelTop = f_scrollBottom()- 30;
		//alert(document.all.topButton.style.pixelTop);
		//alert(document.body.clientHeight + ';' + document.body.scrollHeight + ';' + document.body.offsetWidth + ';' + document.body.offsetHeight);
		//alert(document.documentElement.scrollTop + ';' + document.documentElement.scrollLeft);
	}
	else if (document.layers)
	{
		document.topButton.top = window.pageYOffset;
	}
	else if (document.getElementById)
	{
	    if(document.getElementById('topButton'))
	    {
		    document.getElementById('topButton').style.top = window.pageYOffset + 'px';
		}
  	 }
    if (document.getElementById) // all modern browsers support getElementById now
	{
	    if(document.getElementById('topButton'))
	    {
	        if (document.body.clientHeight > document.body.scrollHeight)
	        {
		        document.getElementById('topButton').style.visibility = 'hidden';
	        }
	        else
	        {
		        document.getElementById('topButton').style.visibility = 'visible';
	        }
	    }
	}
}

if (document.all)
{
	window.onscroll = floatButton;
	window.onresize = floatButton;
}
else
{
	setInterval ('floatButton()', 100);
}

function initButton ()
{
	if (document.all)
	{
		document.all.topButton.style.pixelLeft = document.body.clientWidth - document.all.topButton.offsetWidth;
		document.all.topButton.style.pixelTop = document.body.clientHeight - 15;
		//document.all.topButton.style.visibility = 'visible';
	}
	else if (document.layers)
	{
		document.topButton.left = window.innerWidth - document.topButton.clip.width - 15;
		//document.topButton.visibility = 'show';
	}
	else if (document.getElementById)
	{
		document.getElementById('topButton').style.left = (window.innerWidth - 35) + 'px';
		//document.getElementById('topButton').style.visibility = 'visible';
	 }
}

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_scrollBottom() 
{
	return f_filterResults (
		window.pageYOffset ? window.innerHeight + window.pageYOffset: 0,
		document.documentElement ? document.documentElement.clientHeight + 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;
}