function getWindowHeight() {
  var windowHeight=0;
  if (typeof(window.innerHeight)=='number') {
    windowHeight=window.innerHeight;
  }
  else {
    if (document.documentElement&&document.documentElement.clientHeight) {
      windowHeight=document.documentElement.clientHeight;
    }
    else {
      if (document.body&&document.body.clientHeight) {
        windowHeight=document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

function getWindowWidth() {
  var windowWidth=0;
  if (typeof(window.innerWidth)=='number') {
    windowWidth=window.innerWidth;
  }
  else {
    if (document.documentElement&&document.documentElement.clientWidth) {
      windowWidth=document.documentElement.clientWidth;
    }
    else {
      if (document.body&&document.body.clientWidth) {
        windowWidth=document.body.clientWidth;
      }
    }
  }
  return windowWidth;
}

function setHeight() {
  if (document.getElementById) {
    var windowHeight=getWindowHeight();
    if (windowHeight>0) {
	  var masterDiv=document.getElementById('masterdiv');
	  var contentDiv=document.getElementById('contents');
	  
	  contentDiv.style.height = 'auto';
	  
      var headerHeight=document.getElementById('header').offsetHeight;
      var contentHeight=document.getElementById('contents').offsetHeight;
	  var footerHeight=document.getElementById('footer').offsetHeight;
      if (windowHeight < (contentHeight+headerHeight+footerHeight)) {
        masterDiv.style.height = contentHeight+headerHeight+footerHeight+'px';
      } else {
		masterDiv.style.height = '100%';
		contentDiv.style.height = windowHeight-(headerHeight+footerHeight)+'px';
	  }  
    }
	var windowWidth=getWindowWidth();
	if (windowWidth>0) {
	  var masterDiv=document.getElementById('masterdiv');
	  var masterWidth=document.getElementById('footer').offsetWidth;
	  
      if (windowWidth < masterWidth) {
        masterDiv.style.left = '0px';
		masterDiv.style.marginLeft = '0px';
      } else {
		masterDiv.style.left = '50%';
		masterDiv.style.marginLeft = -400+'px';
	  }  
    } 	
  }
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 

window.onload = function() {
			setHeight();
			externalLinks();
}
window.onresize = function() {
			setHeight();
}