function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}

function refoot() {
	var extra = 25;
	var footer = document.getElementById("footer");
	var main = document.getElementById("main");
	var bottom = document.getElementById("bottom");
	var mainTop = findPos(main)[1];
	var bottomTop = findPos(bottom)[1];
	var mainHeight = bottomTop - mainTop;
	var footerHeight = footer.offsetHeight;
	var pad = mainTop + footerHeight + footerHeight - extra;
	var viewHeight=getSize()[1]-pad;
	if (mainHeight < viewHeight) {
		main.style.height = viewHeight + 'px';
	}
	if (viewHeight < mainHeight) {
		main.style.height = mainHeight + 'px';
	}
}

window.onload=refoot;
//window.onresize=refoot;
