var popupWindow;
var windowFeatures = "";

function setUpWindowFeatures() {
   //var w = (screen.width  >= 800) ? 700 : 600;
   var w = screen.width - 100;
   w = (w > 800 ) ? 800 : w ;
   var h = screen.height - 150;
   //if (h > 450)  h = 450;
   var t = 50;
   var l = screen.width - w - 40;
   var otherDefs = ',resizable=yes,scrollbars=yes';
   return 'width=' + w + ',height=' + h + ',left=' + l + ',top=' + t +otherDefs ;
}

function isPopupWindowAvailable () {
   if ( ( typeof(popupWindow)=='undefined' ) || popupWindow.closed) {
      return false;
   } else {
      return true;
   }
}

function openPopup(href) {
   if ( isPopupWindowAvailable () ) {
      if (href != "") popupWindow.location.href = href;
      popupWindow.focus();
      return true; 
   } else {
      if (windowFeatures=="") windowFeatures = setUpWindowFeatures() ;
      popupWindow=window.open(href,'popup',windowFeatures);
      popupWindow.focus();
      return true;
   }
}

