function viewportheight() {

	 var viewportwidth;
	 var viewportheight;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }

	 // older versions of IE

	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	//document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
	//alert ("vph:"+viewportheight);
	return viewportheight;
}

function getTop(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	//alert ("ct:"+curtop);
	return curtop;
}


function StretchToBottom(ID,margin){
		    var headerHeight=	getTop(document.getElementById(ID));        		    
		    var h=(viewportheight()-headerHeight-margin)+"px";
		    document.getElementById(ID).style.height=h;
}

function PlaceFooter(){
  var headlines=document.getElementById('headlines');
  var headlinesbottom=headlines.offsetTop+headlines.offsetHeight;
  var footer=document.getElementById('footer');
  var footerheight=footer.offsetHeight;
  var curfootertop=footer.offsetTop;
  var newfootertop=headlinesbottom-footerheight;
  var delta=newfootertop-curfootertop;
  if (delta>0) {
    footer.style.paddingTop=delta+"px";
  } else {
    //footer.style.paddingTop=(footer.style.paddingTop+15)+"px";
    //SizeHeadlines();            
  };    
}

function SizeHeadlines(){
  var headlines=document.getElementById('headlines');
  var footer=document.getElementById('footer');
  var footerbottom=footer.offsetTop+footer.offsetHeight;
  var paddingHeadlines=15; //paddingHeadlines=headlines.style.padding-top not working!! 
  var currHeadlinesHeight=headlines.offsetHeight;
  var newHeadlinesHeight=footerbottom-headlines.offsetTop-2*paddingHeadlines;
  if (newHeadlinesHeight>currHeadlinesHeight) {
    headlines.style.height=newHeadlinesHeight+"px";
  }  
    
}
   
